build.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /**
  2. * @name Build Module
  3. * @description This module is used to generate HTML-Code.
  4. * @author Tobias Reich
  5. * @copyright 2014 by Tobias Reich
  6. */
  7. build = {
  8. divider: function(title) {
  9. return "<div class='divider fadeIn'><h1>" + title + "</h1></div>";
  10. },
  11. editIcon: function(id) {
  12. return "<div id='" + id + "' class='edit'><a class='icon-pencil'></a></div>";
  13. },
  14. album: function(albumJSON) {
  15. if (!albumJSON) return "";
  16. var album = "",
  17. longTitle = title = albumJSON.title;
  18. if (title.length>18) title = albumJSON.title.substr(0, 18) + "...";
  19. typeThumb0 = albumJSON.thumb0.split('.').pop();
  20. typeThumb1 = albumJSON.thumb1.split('.').pop();
  21. typeThumb2 = albumJSON.thumb2.split('.').pop();
  22. album += "<div class='album' data-id='" + albumJSON.id + "' data-password='" + albumJSON.password + "'>";
  23. album += "<img src='" + albumJSON.thumb2 + "' width='200' height='200' alt='thumb' data-type='" + typeThumb2 + "'>";
  24. album += "<img src='" + albumJSON.thumb1 + "' width='200' height='200' alt='thumb' data-type='" + typeThumb1 + "'>";
  25. album += "<img src='" + albumJSON.thumb0 + "' width='200' height='200' alt='thumb' data-type='" + typeThumb0 + "'>";
  26. album += "<div class='overlay' title='" + longTitle + "'>";
  27. if (albumJSON.password&&!lychee.publicMode) album += "<h1><span class='icon-lock'></span> " + title + "</h1>";
  28. else album += "<h1>" + title + "</h1>";
  29. album += "<a>" + albumJSON.sysdate + "</a>";
  30. album += "</div>";
  31. if(!lychee.publicMode&&albumJSON.star==1) album += "<a class='badge red icon-star'></a>";
  32. if(!lychee.publicMode&&albumJSON.public==1) album += "<a class='badge red icon-share'></a>";
  33. if(!lychee.publicMode&&albumJSON.unsorted==1) album += "<a class='badge red icon-reorder'></a>";
  34. album += "</div>";
  35. return album;
  36. },
  37. photo: function(photoJSON) {
  38. if (!photoJSON) return "";
  39. var photo = "",
  40. title = photoJSON.title;
  41. if (title.length>18) title = photoJSON.title.substr(0, 18) + "...";
  42. photo += "<div class='photo' data-album-id='" + photoJSON.album + "' data-id='" + photoJSON.id + "'>";
  43. photo += "<img src='" + photoJSON.thumbUrl + "' width='200' height='200' alt='thumb'>";
  44. photo += "<div class='overlay'>";
  45. photo += "<h1>" + title + "</h1>";
  46. photo += "<a>" + photoJSON.sysdate + "</a>";
  47. photo += "</div>";
  48. if (photoJSON.star==1) photo += "<a class='badge red icon-star'></a>";
  49. if (!lychee.publicMode&&photoJSON.public==1&&album.json.public!=1) photo += "<a class='badge red icon-share'></a>";
  50. photo += "</div>";
  51. return photo;
  52. },
  53. imageview: function(photoJSON, isSmall, visibleControls) {
  54. if (!photoJSON) return "";
  55. var view = "";
  56. view += "<div class='arrow_wrapper previous'><a id='previous' class='icon-caret-left'></a></div>";
  57. view += "<div class='arrow_wrapper next'><a id='next' class='icon-caret-right'></a></div>";
  58. if (isSmall) {
  59. if (visibleControls)
  60. view += "<div id='image' class='small' style='background-image: url(" + photoJSON.url + "); width: " + photoJSON.width + "px; height: " + photoJSON.height + "px; margin-top: -" + parseInt(photoJSON.height/2-20) + "px; margin-left: -" + photoJSON.width/2 + "px;'></div>";
  61. else
  62. view += "<div id='image' class='small' style='background-image: url(" + photoJSON.url + "); width: " + photoJSON.width + "px; height: " + photoJSON.height + "px; margin-top: -" + parseInt(photoJSON.height/2) + "px; margin-left: -" + photoJSON.width/2 + "px;'></div>";
  63. } else {
  64. if (visibleControls)
  65. view += "<div id='image' style='background-image: url(" + photoJSON.url + ")'></div>";
  66. else
  67. view += "<div id='image' style='background-image: url(" + photoJSON.url + "); top: 0px; right: 0px; bottom: 0px; left: 0px;'></div>";
  68. }
  69. return view;
  70. },
  71. no_content: function(typ) {
  72. var no_content = "";
  73. no_content += "<div class='no_content fadeIn'>";
  74. no_content += "<a class='icon icon-" + typ + "'></a>";
  75. if (typ==="search") no_content += "<p>No results</p>";
  76. else if (typ==="picture") no_content += "<p>No public albums</p>";
  77. else if (typ==="cog") no_content += "<p>No Configuration!</p>";
  78. no_content += "</div>";
  79. return no_content;
  80. },
  81. modal: function(title, text, button, marginTop, closeButton) {
  82. var modal = "",
  83. custom_style = "";
  84. if (marginTop) custom_style = "style='margin-top: " + marginTop + "px;'";
  85. modal += "<div class='message_overlay fadeIn'>";
  86. modal += "<div class='message center'" + custom_style + ">";
  87. modal += "<h1>" + title + "</h1>";
  88. if (closeButton!=false) {
  89. modal += "<a class='close icon-remove-sign'></a>";
  90. }
  91. modal += "<p>" + text + "</p>";
  92. $.each(button, function(index) {
  93. if (this[0]!="") {
  94. if (index===0) modal += "<a class='button active'>" + this[0] + "</a>";
  95. else modal += "<a class='button'>" + this[0] + "</a>";
  96. }
  97. });
  98. modal += "</div>";
  99. modal += "</div>";
  100. return modal;
  101. },
  102. signInModal: function() {
  103. var modal = "";
  104. modal += "<div class='message_overlay'>";
  105. modal += "<div class='message center'>";
  106. modal += "<h1><a class='icon-lock'></a> Sign In</h1>";
  107. modal += "<a class='close icon-remove-sign'></a>";
  108. modal += "<div class='sign_in'>";
  109. modal += "<input id='username' type='text' name='' value='' placeholder='username'>";
  110. modal += "<input id='password' type='password' name='' value='' placeholder='password'>";
  111. modal += "</div>";
  112. modal += "<div id='version'>Version " + lychee.version + "<span> &#8211; <a target='_blank' href='" + lychee.updateURL + "'>Update available!</a><span></div>";
  113. modal += "<a onclick='lychee.login()' class='button active'>Sign in</a>";
  114. modal += "</div>";
  115. modal += "</div>";
  116. return modal;
  117. },
  118. uploadModal: function(icon, text) {
  119. var modal = "";
  120. modal += "<div class='upload_overlay fadeIn'>";
  121. modal += "<div class='upload_message center'>";
  122. modal += "<a class='icon-" + icon + "'></a>";
  123. if (text!==undefined) modal += "<p>" + text + "</p>";
  124. else modal += "<div class='progressbar'><div></div></div>";
  125. modal += "</div>";
  126. modal += "</div>";
  127. return modal;
  128. },
  129. contextMenu: function(items) {
  130. var menu = "";
  131. menu += "<div class='contextmenu_bg'></div>";
  132. menu += "<div class='contextmenu'>";
  133. menu += "<table>";
  134. menu += "<tbody>";
  135. $.each(items, function(index) {
  136. if (items[index][0]==="separator"&&items[index][1]===-1) menu += "<tr class='separator'></tr>";
  137. else if (items[index][1]===-1) menu += "<tr class='no_hover'><td>" + items[index][0] + "</td></tr>";
  138. else if (items[index][2]!=undefined) menu += "<tr><td onclick='" + items[index][2] + "; window.contextMenu.close();'>" + items[index][0] + "</td></tr>";
  139. else menu += "<tr><td onclick='window.contextMenu.fns[" + items[index][1] + "](); window.contextMenu.close();'>" + items[index][0] + "</td></tr>";
  140. });
  141. menu += "</tbody>";
  142. menu += "</table>";
  143. menu += "</div>";
  144. return menu;
  145. },
  146. infoboxPhoto: function(photoJSON, forView) {
  147. if (!photoJSON) return "";
  148. var infobox = "",
  149. public,
  150. editTitleHTML,
  151. editDescriptionHTML,
  152. infos;
  153. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  154. infobox += "<div class='wrapper'>";
  155. switch (photoJSON.public) {
  156. case "0":
  157. public = "Private";
  158. break;
  159. case "1":
  160. public = "Public";
  161. break;
  162. case "2":
  163. public = "Public (Album)";
  164. break;
  165. default:
  166. public = "-";
  167. break;
  168. }
  169. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title");
  170. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description");
  171. //["Tags", "<a class='tag'>Abstract<span class='icon-remove'></span></a><a class='tag'>Colors<span class='icon-remove'></span></a><a class='tag'>Photoshop<span class='icon-remove'></span></a><a class='tag'>Something<span class='icon-remove'></span></a><a class='tag'>Lychee<span class='icon-remove'></span></a><a class='tag'>Tags<span class='icon-remove'></span></a><a class='tag icon-plus'></a>"]
  172. infos = [
  173. ["", "Basics"],
  174. ["Name", photoJSON.title + editTitleHTML],
  175. ["Uploaded", photoJSON.sysdate],
  176. ["Description", photoJSON.description + editDescriptionHTML],
  177. ["", "Image"],
  178. ["Size", photoJSON.size],
  179. ["Format", photoJSON.type],
  180. ["Resolution", photoJSON.width + " x " + photoJSON.height]
  181. ];
  182. if ((photoJSON.takedate+photoJSON.make+photoJSON.model+photoJSON.shutter+photoJSON.aperture+photoJSON.focal+photoJSON.iso)!="") {
  183. infos = infos.concat([
  184. ["", "Camera"],
  185. ["Captured", photoJSON.takedate],
  186. ["Make", photoJSON.make],
  187. ["Type/Model", photoJSON.model],
  188. ["Shutter Speed", photoJSON.shutter],
  189. ["Aperture", photoJSON.aperture],
  190. ["Focal Length", photoJSON.focal],
  191. ["ISO", photoJSON.iso]
  192. ]);
  193. }
  194. infos = infos.concat([
  195. ["", "Share"],
  196. ["Visibility", public]
  197. ]);
  198. $.each(infos, function(index) {
  199. if (infos[index][1]===""||infos[index][1]==undefined||infos[index][1]==null) infos[index][1] = "-";
  200. switch (infos[index][0]) {
  201. case "": // Separator
  202. infobox += "</table>";
  203. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  204. infobox += "<table>";
  205. break;
  206. case "Tags": // Tags
  207. infobox += "</table>";
  208. infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>";
  209. infobox += "<tr>";
  210. infobox += "<div id='tags'>" + infos[index][1] + "</div>";
  211. infobox += "</tr>";
  212. break;
  213. default: // Item
  214. infobox += "<tr>";
  215. infobox += "<td>" + infos[index][0] + "</td>";
  216. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  217. infobox += "</tr>";
  218. break;
  219. }
  220. });
  221. infobox += "</table>";
  222. infobox += "<div class='bumper'></div>";
  223. infobox += "</div>";
  224. return infobox;
  225. },
  226. infoboxAlbum: function(albumJSON, forView) {
  227. if (!albumJSON) return "";
  228. var infobox = "",
  229. public,
  230. password,
  231. editTitleHTML,
  232. editDescriptionHTML,
  233. infos;
  234. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  235. infobox += "<div class='wrapper'>";
  236. switch (albumJSON.public) {
  237. case "0":
  238. public = "Private";
  239. break;
  240. case "1":
  241. public = "Public";
  242. break;
  243. default:
  244. public = "-";
  245. break;
  246. }
  247. switch (albumJSON.password) {
  248. case false:
  249. password = "No";
  250. break;
  251. case true:
  252. password = "Yes";
  253. break;
  254. default:
  255. password = "-";
  256. break;
  257. }
  258. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title_album");
  259. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description_album");
  260. infos = [
  261. ["", "Basics"],
  262. ["Name", albumJSON.title + editTitleHTML],
  263. ["Description", albumJSON.description + editDescriptionHTML],
  264. ["", "Album"],
  265. ["Created", albumJSON.sysdate],
  266. ["Images", albumJSON.num],
  267. ["", "Share"],
  268. ["Visibility", public],
  269. ["Password", password]
  270. ];
  271. $.each(infos, function(index) {
  272. if (infos[index][1]===""||infos[index][1]==undefined||infos[index][1]==null) infos[index][1] = "-";
  273. if (infos[index][0]==="") {
  274. infobox += "</table>";
  275. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  276. infobox += "<table id='infos'>";
  277. } else {
  278. infobox += "<tr>";
  279. infobox += "<td>" + infos[index][0] + "</td>";
  280. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  281. infobox += "</tr>";
  282. }
  283. });
  284. infobox += "</table>";
  285. infobox += "<div class='bumper'></div>";
  286. infobox += "</div>";
  287. return infobox;
  288. }
  289. }