build.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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. build.divider = function(title) {
  9. return "<div class='divider fadeIn'><h1>" + title + "</h1></div>";
  10. },
  11. build.editIcon = function(id) {
  12. return "<div id='" + id + "' class='edit'><a class='icon-pencil'></a></div>";
  13. },
  14. build.multiselect = function(top, left) {
  15. return "<div id='multiselect' style='top: " + top + "px; left: " + left + "px;'></div>";
  16. },
  17. build.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. build.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. build.imageview = function(photoJSON, size, 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 (size==="big") {
  76. if (visibleControls)
  77. view += "<div id='image' style='background-image: url(" + photoJSON.url + ")'></div>";
  78. else
  79. view += "<div id='image' style='background-image: url(" + photoJSON.url + ");' class='full'></div>";
  80. } else if (size==="medium") {
  81. if (visibleControls)
  82. view += "<div id='image' style='background-image: url(" + photoJSON.medium + ")'></div>";
  83. else
  84. view += "<div id='image' style='background-image: url(" + photoJSON.medium + ");' class='full'></div>";
  85. } else if (size==='small') {
  86. if (visibleControls)
  87. 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>";
  88. else
  89. 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>";
  90. }
  91. return view;
  92. },
  93. build.no_content = function(typ) {
  94. var no_content = "";
  95. no_content += "<div class='no_content fadeIn'>";
  96. no_content += "<a class='icon icon-" + typ + "'></a>";
  97. if (typ==="search") no_content += "<p>No results</p>";
  98. else if (typ==="share") no_content += "<p>No public albums</p>";
  99. else if (typ==="cog") no_content += "<p>No configuration</p>";
  100. no_content += "</div>";
  101. return no_content;
  102. },
  103. build.modal = function(title, text, button, marginTop, closeButton) {
  104. var modal = "",
  105. custom_style = "";
  106. if (marginTop) custom_style = "style='margin-top: " + marginTop + "px;'";
  107. modal += "<div class='message_overlay fadeIn'>";
  108. modal += "<div class='message center'" + custom_style + ">";
  109. modal += "<h1>" + title + "</h1>";
  110. if (closeButton!==false) {
  111. modal += "<a class='close icon-remove-sign'></a>";
  112. }
  113. modal += "<p>" + text + "</p>";
  114. $.each(button, function(index) {
  115. if (this[0]!=="") {
  116. if (index===0) modal += "<a class='button active'>" + this[0] + "</a>";
  117. else modal += "<a class='button'>" + this[0] + "</a>";
  118. }
  119. });
  120. modal += "</div>";
  121. modal += "</div>";
  122. return modal;
  123. },
  124. build.signInModal = function() {
  125. var modal = "";
  126. modal += "<div class='message_overlay'>";
  127. modal += "<div class='message center'>";
  128. modal += "<h1><a class='icon-lock'></a> Sign In</h1>";
  129. modal += "<a class='close icon-remove-sign'></a>";
  130. modal += "<div class='sign_in'>";
  131. modal += "<input id='username' type='text' value='' placeholder='username' autocapitalize='off' autocorrect='off'>";
  132. modal += "<input id='password' type='password' value='' placeholder='password'>";
  133. modal += "</div>";
  134. modal += "<div id='version'>Version " + lychee.version + "<span> &#8211; <a target='_blank' href='" + lychee.updateURL + "'>Update available!</a><span></div>";
  135. modal += "<a onclick='lychee.login()' class='button active'>Sign in</a>";
  136. modal += "</div>";
  137. modal += "</div>";
  138. return modal;
  139. },
  140. build.uploadModal = function(title, files) {
  141. var modal = "";
  142. modal += "<div class='upload_overlay fadeIn'>";
  143. modal += "<div class='upload_message center'>";
  144. modal += "<h1>" + title + "</h1>";
  145. modal += "<a class='close icon-remove-sign'></a>";
  146. modal += "<div class='rows'>";
  147. for (var i = 0; i < files.length; i++) {
  148. 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);
  149. modal += "<div class='row'>";
  150. modal += "<a class='name'>" + lychee.escapeHTML(files[i].name) + "</a>";
  151. if (files[i].supported===true) modal += "<a class='status'></a>";
  152. else modal += "<a class='status error'>Not supported</a>";
  153. modal += "<p class='notice'></p>";
  154. modal += "</div>";
  155. }
  156. modal += "</div>";
  157. modal += "</div>";
  158. modal += "</div>";
  159. return modal;
  160. },
  161. build.contextMenu = function(items) {
  162. var menu = "";
  163. menu += "<div class='contextmenu_bg'></div>";
  164. menu += "<div class='contextmenu'>";
  165. menu += "<table>";
  166. menu += "<tbody>";
  167. $.each(items, function(index) {
  168. if (items[index][0]==="separator"&&items[index][1]===-1) menu += "<tr class='separator'></tr>";
  169. else if (items[index][1]===-1) menu += "<tr class='no_hover'><td>" + items[index][0] + "</td></tr>";
  170. else if (items[index][2]!=undefined) menu += "<tr><td onclick='" + items[index][2] + "; window.contextMenu.close();'>" + items[index][0] + "</td></tr>";
  171. else menu += "<tr><td onclick='window.contextMenu.fns[" + items[index][1] + "](); window.contextMenu.close();'>" + items[index][0] + "</td></tr>";
  172. });
  173. menu += "</tbody>";
  174. menu += "</table>";
  175. menu += "</div>";
  176. return menu;
  177. },
  178. build.tags = function(tags, forView) {
  179. var html = "",
  180. editTagsHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_tags");
  181. if (tags!=="") {
  182. tags = tags.split(",");
  183. tags.forEach(function(tag, index, array) {
  184. html += "<a class='tag'>" + tag + "<span class='icon-remove' data-index='" + index + "'></span></a>";
  185. });
  186. html += editTagsHTML;
  187. } else {
  188. html = "<div class='empty'>No Tags" + editTagsHTML + "</div>";
  189. }
  190. return html;
  191. },
  192. build.infoboxPhoto = function(photoJSON, forView) {
  193. if (!photoJSON) return "";
  194. var infobox = "",
  195. public,
  196. editTitleHTML,
  197. editDescriptionHTML,
  198. infos,
  199. exifHash = "";
  200. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  201. infobox += "<div class='wrapper'>";
  202. switch (photoJSON.public) {
  203. case "0":
  204. public = "No";
  205. break;
  206. case "1":
  207. public = "Yes";
  208. break;
  209. case "2":
  210. public = "Yes (Album)";
  211. break;
  212. default:
  213. public = "-";
  214. break;
  215. }
  216. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title");
  217. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description");
  218. infos = [
  219. ["", "Basics"],
  220. ["Title", photoJSON.title + editTitleHTML],
  221. ["Uploaded", photoJSON.sysdate],
  222. ["Description", photoJSON.description + editDescriptionHTML],
  223. ["", "Image"],
  224. ["Size", photoJSON.size],
  225. ["Format", photoJSON.type],
  226. ["Resolution", photoJSON.width + " x " + photoJSON.height],
  227. ["Tags", build.tags(photoJSON.tags, forView)]
  228. ];
  229. exifHash = photoJSON.takestamp+photoJSON.make+photoJSON.model+photoJSON.shutter+photoJSON.aperture+photoJSON.focal+photoJSON.iso;
  230. if (exifHash!="0"&&exifHash!=="null") {
  231. infos = infos.concat([
  232. ["", "Camera"],
  233. ["Captured", photoJSON.takedate],
  234. ["Make", photoJSON.make],
  235. ["Type/Model", photoJSON.model],
  236. ["Shutter Speed", photoJSON.shutter],
  237. ["Aperture", photoJSON.aperture],
  238. ["Focal Length", photoJSON.focal],
  239. ["ISO", photoJSON.iso]
  240. ]);
  241. }
  242. infos = infos.concat([
  243. ["", "Share"],
  244. ["Public", public]
  245. ]);
  246. $.each(infos, function(index) {
  247. if (infos[index][1]===""||infos[index][1]===undefined||infos[index][1]===null) infos[index][1] = "-";
  248. switch (infos[index][0]) {
  249. case "": // Separator
  250. infobox += "</table>";
  251. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  252. infobox += "<table>";
  253. break;
  254. case "Tags": // Tags
  255. if (forView!==true&&!lychee.publicMode) {
  256. infobox += "</table>";
  257. infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>";
  258. infobox += "<div id='tags'>" + infos[index][1] + "</div>";
  259. }
  260. break;
  261. default: // Item
  262. infobox += "<tr>";
  263. infobox += "<td>" + infos[index][0] + "</td>";
  264. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  265. infobox += "</tr>";
  266. break;
  267. }
  268. });
  269. infobox += "</table>";
  270. infobox += "<div class='bumper'></div>";
  271. infobox += "</div>";
  272. return infobox;
  273. },
  274. build.infoboxAlbum = function(albumJSON, forView) {
  275. if (!albumJSON) return "";
  276. var infobox = "",
  277. public = "-",
  278. password = "-",
  279. downloadable = "-",
  280. editTitleHTML,
  281. editDescriptionHTML,
  282. infos;
  283. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  284. infobox += "<div class='wrapper'>";
  285. switch (albumJSON.public) {
  286. case "0":
  287. public = "No";
  288. break;
  289. case "1":
  290. public = "Yes";
  291. break;
  292. }
  293. switch (albumJSON.password) {
  294. case false:
  295. password = "No";
  296. break;
  297. case true:
  298. password = "Yes";
  299. break;
  300. }
  301. switch (albumJSON.downloadable) {
  302. case "0":
  303. downloadable = "No";
  304. break;
  305. case "1":
  306. downloadable = "Yes";
  307. break;
  308. }
  309. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title_album");
  310. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description_album");
  311. infos = [
  312. ["", "Basics"],
  313. ["Title", albumJSON.title + editTitleHTML],
  314. ["Description", albumJSON.description + editDescriptionHTML],
  315. ["", "Album"],
  316. ["Created", albumJSON.sysdate],
  317. ["Images", albumJSON.num],
  318. ["", "Share"],
  319. ["Public", public],
  320. ["Downloadable", downloadable],
  321. ["Password", password]
  322. ];
  323. $.each(infos, function(index) {
  324. if (infos[index][1]===""||infos[index][1]===undefined||infos[index][1]===null) infos[index][1] = "-";
  325. if (infos[index][0]==="") {
  326. infobox += "</table>";
  327. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  328. infobox += "<table id='infos'>";
  329. } else {
  330. infobox += "<tr>";
  331. infobox += "<td>" + infos[index][0] + "</td>";
  332. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  333. infobox += "</tr>";
  334. }
  335. });
  336. infobox += "</table>";
  337. infobox += "<div class='bumper'></div>";
  338. infobox += "</div>";
  339. return infobox;
  340. }