build.js 12 KB

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