build.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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 + "); top: 0px; right: 0px; bottom: 0px; left: 0px;'></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. infoboxPhoto: function(photoJSON, forView) {
  158. if (!photoJSON) return "";
  159. var infobox = "",
  160. public,
  161. editTitleHTML,
  162. editDescriptionHTML,
  163. infos;
  164. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  165. infobox += "<div class='wrapper'>";
  166. switch (photoJSON.public) {
  167. case "0":
  168. public = "Private";
  169. break;
  170. case "1":
  171. public = "Public";
  172. break;
  173. case "2":
  174. public = "Public (Album)";
  175. break;
  176. default:
  177. public = "-";
  178. break;
  179. }
  180. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title");
  181. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description");
  182. //["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>"]
  183. infos = [
  184. ["", "Basics"],
  185. ["Name", photoJSON.title + editTitleHTML],
  186. ["Uploaded", photoJSON.sysdate],
  187. ["Description", photoJSON.description + editDescriptionHTML],
  188. ["", "Image"],
  189. ["Size", photoJSON.size],
  190. ["Format", photoJSON.type],
  191. ["Resolution", photoJSON.width + " x " + photoJSON.height]
  192. ];
  193. if ((photoJSON.takedate+photoJSON.make+photoJSON.model+photoJSON.shutter+photoJSON.aperture+photoJSON.focal+photoJSON.iso)!="") {
  194. infos = infos.concat([
  195. ["", "Camera"],
  196. ["Captured", photoJSON.takedate],
  197. ["Make", photoJSON.make],
  198. ["Type/Model", photoJSON.model],
  199. ["Shutter Speed", photoJSON.shutter],
  200. ["Aperture", photoJSON.aperture],
  201. ["Focal Length", photoJSON.focal],
  202. ["ISO", photoJSON.iso]
  203. ]);
  204. }
  205. infos = infos.concat([
  206. ["", "Share"],
  207. ["Visibility", public]
  208. ]);
  209. $.each(infos, function(index) {
  210. if (infos[index][1]===""||infos[index][1]==undefined||infos[index][1]==null) infos[index][1] = "-";
  211. switch (infos[index][0]) {
  212. case "": // Separator
  213. infobox += "</table>";
  214. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  215. infobox += "<table>";
  216. break;
  217. case "Tags": // Tags
  218. infobox += "</table>";
  219. infobox += "<div class='separator'><h1>" + infos[index][0] + "</h1></div>";
  220. infobox += "<tr>";
  221. infobox += "<div id='tags'>" + infos[index][1] + "</div>";
  222. infobox += "</tr>";
  223. break;
  224. default: // Item
  225. infobox += "<tr>";
  226. infobox += "<td>" + infos[index][0] + "</td>";
  227. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  228. infobox += "</tr>";
  229. break;
  230. }
  231. });
  232. infobox += "</table>";
  233. infobox += "<div class='bumper'></div>";
  234. infobox += "</div>";
  235. return infobox;
  236. },
  237. infoboxAlbum: function(albumJSON, forView) {
  238. if (!albumJSON) return "";
  239. var infobox = "",
  240. public,
  241. password,
  242. editTitleHTML,
  243. editDescriptionHTML,
  244. infos;
  245. infobox += "<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";
  246. infobox += "<div class='wrapper'>";
  247. switch (albumJSON.public) {
  248. case "0":
  249. public = "Private";
  250. break;
  251. case "1":
  252. public = "Public";
  253. break;
  254. default:
  255. public = "-";
  256. break;
  257. }
  258. switch (albumJSON.password) {
  259. case false:
  260. password = "No";
  261. break;
  262. case true:
  263. password = "Yes";
  264. break;
  265. default:
  266. password = "-";
  267. break;
  268. }
  269. editTitleHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_title_album");
  270. editDescriptionHTML = (forView===true||lychee.publicMode) ? "" : " " + build.editIcon("edit_description_album");
  271. infos = [
  272. ["", "Basics"],
  273. ["Name", albumJSON.title + editTitleHTML],
  274. ["Description", albumJSON.description + editDescriptionHTML],
  275. ["", "Album"],
  276. ["Created", albumJSON.sysdate],
  277. ["Images", albumJSON.num],
  278. ["", "Share"],
  279. ["Visibility", public],
  280. ["Password", password]
  281. ];
  282. $.each(infos, function(index) {
  283. if (infos[index][1]===""||infos[index][1]==undefined||infos[index][1]==null) infos[index][1] = "-";
  284. if (infos[index][0]==="") {
  285. infobox += "</table>";
  286. infobox += "<div class='separator'><h1>" + infos[index][1] + "</h1></div>";
  287. infobox += "<table id='infos'>";
  288. } else {
  289. infobox += "<tr>";
  290. infobox += "<td>" + infos[index][0] + "</td>";
  291. infobox += "<td class='attr_" + infos[index][0].toLowerCase() + "'>" + infos[index][1] + "</td>";
  292. infobox += "</tr>";
  293. }
  294. });
  295. infobox += "</table>";
  296. infobox += "<div class='bumper'></div>";
  297. infobox += "</div>";
  298. return infobox;
  299. }
  300. }