build.js 12 KB

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