build.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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!==null&&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!==null&&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==="share") 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' value='' placeholder='username'>";
  127. modal += "<input id='password' type='password' 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(title, files) {
  136. var modal = "";
  137. modal += "<div class='upload_overlay fadeIn'>";
  138. modal += "<div class='upload_message center'>";
  139. modal += "<h1>" + title + "</h1>";
  140. modal += "<a class='close icon-remove-sign'></a>";
  141. modal += "<div class='rows'>";
  142. for (var i = 0; i < files.length; i++) {
  143. if (files[i].name.length>40) files[i].name = files[i].name.substr(0, 17) + "..." + files[i].name.substr(files[i].name.length-20, 20);
  144. modal += "<div class='row'>";
  145. modal += "<a class='name'>" + lychee.escapeHTML(files[i].name) + "</a>";
  146. if (files[i].supported===true) modal += "<a class='status'></a>";
  147. else modal += "<a class='status error'>Not supported</a>";
  148. modal += "<p class='notice'></p>";
  149. modal += "</div>";
  150. }
  151. modal += "</div>";
  152. modal += "</div>";
  153. modal += "</div>";
  154. return modal;
  155. },
  156. contextMenu: function(items) {
  157. var menu = "";
  158. menu += "<div class='contextmenu_bg'></div>";
  159. menu += "<div class='contextmenu'>";
  160. menu += "<table>";
  161. menu += "<tbody>";
  162. $.each(items, function(index) {
  163. if (items[index][0]==="separator"&&items[index][1]===-1) menu += "<tr class='separator'></tr>";
  164. else if (items[index][1]===-1) menu += "<tr class='no_hover'><td>" + items[index][0] + "</td></tr>";
  165. else if (items[index][2]!=undefined) menu += "<tr><td onclick='" + items[index][2] + "; window.contextMenu.close();'>" + items[index][0] + "</td></tr>";
  166. else menu += "<tr><td onclick='window.contextMenu.fns[" + items[index][1] + "](); window.contextMenu.close();'>" + items[index][0] + "</td></tr>";
  167. });
  168. menu += "</tbody>";
  169. menu += "</table>";
  170. menu += "</div>";
  171. return menu;
  172. },
  173. tags: function(tags, forView) {
  174. var html = "",
  175. editTagsHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_tags");
  176. if (tags!=="") {
  177. tags = tags.split(",");
  178. tags.forEach(function(tag, index, array) {
  179. html += "<a class='tag'>" + tag + "<span class='icon-remove' data-index='" + index + "'></span></a>";
  180. });
  181. html += editTagsHTML;
  182. } else {
  183. html = "<div class='empty'>No Tags" + editTagsHTML + "</div>";
  184. }
  185. return html;
  186. },
  187. infoboxPhoto: function(photoJSON, forView) {
  188. if (!photoJSON) return "";
  189. var infobox = "",
  190. public,
  191. editTitleHTML,
  192. editDescriptionHTML,
  193. infos,
  194. exifHash = "";
  195. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  196. infobox += "<div class='wrapper'>";
  197. switch (photoJSON.public) {
  198. case "0":
  199. public = "No";
  200. break;
  201. case "1":
  202. public = "Yes";
  203. break;
  204. case "2":
  205. public = "Yes (Album)";
  206. break;
  207. default:
  208. public = "-";
  209. break;
  210. }
  211. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title");
  212. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description");
  213. infos = [
  214. ["", "Basics"],
  215. ["Title", photoJSON.title + editTitleHTML],
  216. ["Uploaded", photoJSON.sysdate],
  217. ["Description", photoJSON.description + editDescriptionHTML],
  218. ["", "Image"],
  219. ["Size", photoJSON.size],
  220. ["Format", photoJSON.type],
  221. ["Resolution", photoJSON.width + " x " + photoJSON.height],
  222. ["Tags", build.tags(photoJSON.tags, forView)]
  223. ];
  224. exifHash = photoJSON.takestamp+photoJSON.make+photoJSON.model+photoJSON.shutter+photoJSON.aperture+photoJSON.focal+photoJSON.iso;
  225. if (exifHash!="0"&&exifHash!=="null") {
  226. infos = infos.concat([
  227. ["", "Camera"],
  228. ["Captured", photoJSON.takedate],
  229. ["Make", photoJSON.make],
  230. ["Type/Model", photoJSON.model],
  231. ["Shutter Speed", photoJSON.shutter],
  232. ["Aperture", photoJSON.aperture],
  233. ["Focal Length", photoJSON.focal],
  234. ["ISO", photoJSON.iso]
  235. ]);
  236. }
  237. infos = infos.concat([
  238. ["", "Share"],
  239. ["Public", public]
  240. ]);
  241. $.each(infos, function(index) {
  242. if (infos[index][1]===""||infos[index][1]===undefined||infos[index][1]===null) infos[index][1] = "-";
  243. switch (infos[index][0]) {
  244. case "": // Separator
  245. infobox += "</table>";
  246. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  247. infobox += "<table>";
  248. break;
  249. case "Tags": // Tags
  250. if (forView!==true&&!lychee.publicMode) {
  251. infobox += "</table>";
  252. infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>";
  253. infobox += "<div id='tags'>" + infos[index][1] + "</div>";
  254. }
  255. break;
  256. default: // Item
  257. infobox += "<tr>";
  258. infobox += "<td>" + infos[index][0] + "</td>";
  259. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  260. infobox += "</tr>";
  261. break;
  262. }
  263. });
  264. infobox += "</table>";
  265. infobox += "<div class='bumper'></div>";
  266. infobox += "</div>";
  267. return infobox;
  268. },
  269. infoboxAlbum: function(albumJSON, forView) {
  270. if (!albumJSON) return "";
  271. var infobox = "",
  272. public = "-",
  273. password = "-",
  274. downloadable = "-",
  275. editTitleHTML,
  276. editDescriptionHTML,
  277. infos;
  278. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  279. infobox += "<div class='wrapper'>";
  280. switch (albumJSON.public) {
  281. case "0":
  282. public = "No";
  283. break;
  284. case "1":
  285. public = "Yes";
  286. break;
  287. }
  288. switch (albumJSON.password) {
  289. case false:
  290. password = "No";
  291. break;
  292. case true:
  293. password = "Yes";
  294. break;
  295. }
  296. switch (albumJSON.downloadable) {
  297. case "0":
  298. downloadable = "No";
  299. break;
  300. case "1":
  301. downloadable = "Yes";
  302. break;
  303. }
  304. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title_album");
  305. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description_album");
  306. infos = [
  307. ["", "Basics"],
  308. ["Title", albumJSON.title + editTitleHTML],
  309. ["Description", albumJSON.description + editDescriptionHTML],
  310. ["", "Album"],
  311. ["Created", albumJSON.sysdate],
  312. ["Images", albumJSON.num],
  313. ["", "Share"],
  314. ["Public", public],
  315. ["Downloadable", downloadable],
  316. ["Password", password]
  317. ];
  318. $.each(infos, function(index) {
  319. if (infos[index][1]===""||infos[index][1]===undefined||infos[index][1]===null) infos[index][1] = "-";
  320. if (infos[index][0]==="") {
  321. infobox += "</table>";
  322. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  323. infobox += "<table id='infos'>";
  324. } else {
  325. infobox += "<tr>";
  326. infobox += "<td>" + infos[index][0] + "</td>";
  327. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  328. infobox += "</tr>";
  329. }
  330. });
  331. infobox += "</table>";
  332. infobox += "<div class='bumper'></div>";
  333. infobox += "</div>";
  334. return infobox;
  335. }
  336. };