build.js 11 KB

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