build.js 12 KB

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