build.js 12 KB

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