build.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /**
  2. * @description This module is used to generate HTML-Code.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. window.build = {}
  6. build.iconic = function(icon, classes, file) {
  7. var html = '',
  8. path = 'src/images/';
  9. file = file || 'iconic';
  10. classes = classes || '';
  11. html = `
  12. <svg viewBox='0 0 8 8' class='iconic ${ classes }'>
  13. <use xlink:href='${ path }${ file }.svg#${ icon }' />
  14. </svg>
  15. `
  16. return html;
  17. }
  18. build.divider = function(title) {
  19. var html = '';
  20. html = `
  21. <div class='divider fadeIn'>
  22. <h1>${ title }</h1>
  23. </div>
  24. `
  25. return html;
  26. }
  27. build.editIcon = function(id) {
  28. var html = '';
  29. html = `<div id='${ id }' class='edit'>${ build.iconic('pencil') }</div>`
  30. return html;
  31. }
  32. build.multiselect = function(top, left) {
  33. var html = '';
  34. html = `<div id='multiselect' style='top: ${ top }px; left: ${ left }px;'></div>`
  35. return html;
  36. }
  37. build.album = function(data) {
  38. if (data===null||data===undefined) return '';
  39. var html = '',
  40. title = data.title,
  41. longTitle = '',
  42. typeThumb = '';
  43. if (title!==null&&title.length>18) {
  44. title = data.title.substr(0, 18) + '...';
  45. longTitle = data.title;
  46. }
  47. if (data.thumb0.split('.').pop()==='svg') typeThumb = 'nonretina';
  48. html = `
  49. <div class='album' data-id='${ data.id }' data-password='${ data.password }'>
  50. <img src='${ data.thumb2 }' width='200' height='200' alt='thumb' data-type='nonretina'>
  51. <img src='${ data.thumb1 }' width='200' height='200' alt='thumb' data-type='nonretina'>
  52. <img src='${ data.thumb0 }' width='200' height='200' alt='thumb' data-type='${ typeThumb }'>
  53. <div class='overlay'>
  54. <h1 title='${ longTitle }'>${ title }</h1>
  55. <a>${ data.sysdate }</a>
  56. </div>
  57. `
  58. if (lychee.publicMode===false) {
  59. if (data.star==='1') html += `<a class='badge icn-star'>${ build.iconic('star') }</a>`;
  60. if (data.public==='1') html += `<a class='badge icn-share'>${ build.iconic('eye') }</a>`;
  61. if (data.unsorted==='1') html += `<a class='badge'>${ build.iconic('list') }</a>`;
  62. if (data.recent==='1') html += `<a class='badge'>${ build.iconic('clock') }</a>`;
  63. if (data.password===true) html += `<a class='badge'>${ build.iconic('lock-locked') }</a>`;
  64. }
  65. html += '</div>'
  66. return html;
  67. }
  68. build.photo = function(data) {
  69. if (data===null||data===undefined) return '';
  70. var html = '',
  71. title = data.title,
  72. longTitle = '';
  73. if (title!==null&&title.length>18) {
  74. title = data.title.substr(0, 18) + '...';
  75. longTitle = data.title;
  76. }
  77. html = `
  78. <div class='photo' data-album-id='${ data.album }' data-id='${ data.id }'>
  79. <img src='${ data.thumbUrl }' width='200' height='200' alt='thumb'>
  80. <div class='overlay'>
  81. <h1 title='${ longTitle }'>${ title }</h1>
  82. `
  83. if (data.cameraDate===1) html += `<a><span title='Camera Date'>${ build.iconic('camera-slr') }</span>${ data.sysdate }</a>`;
  84. else html += `<a>${ data.sysdate }</a>`;
  85. html += '</div>';
  86. if (lychee.publicMode===false) {
  87. if (data.star==='1') html += `<a class='badge iconic-star'>${ build.iconic('star') }</a>`;
  88. if (data.public==='1'&&album.json.public!=='1') html += `<a class='badge iconic-share'>${ build.iconic('eye') }</a>`;
  89. }
  90. html += '</div>';
  91. return html
  92. }
  93. build.imageview = function(data, size, visibleControls) {
  94. if (data===null||data===undefined) return '';
  95. var html = '';
  96. html = `
  97. <div class='arrow_wrapper arrow_wrapper--previous'><a id='previous'>${ build.iconic('caret-left') }</a></div>
  98. <div class='arrow_wrapper arrow_wrapper--next'><a id='next'>${ build.iconic('caret-right') }</a></div>
  99. `
  100. if (size==='big') {
  101. if (visibleControls===true)
  102. html += `<div id='image' style='background-image: url(${ data.url })'></div>`;
  103. else
  104. html += `<div id='image' style='background-image: url(${ data.url });' class='full'></div>`;
  105. } else if (size==='medium') {
  106. if (visibleControls===true)
  107. html += `<div id='image' style='background-image: url(${ data.medium })'></div>`;
  108. else
  109. html += `<div id='image' style='background-image: url(${ data.medium });' class='full'></div>`;
  110. } else if (size==='small') {
  111. if (visibleControls===true)
  112. html += `<div id='image' class='small' style='background-image: url(${ data.url }); width: ${ data.width }px; height: ${ data.height }px; margin-top: -${ parseInt(data.height/2-20) }px; margin-left: -${ data.width/2 }px;'></div>`;
  113. else
  114. html += `<div id='image' class='small' style='background-image: url(${ data.url }); width: ${ data.width }px; height: ${ data.height }px; margin-top: -${ parseInt(data.height/2) }px; margin-left: -${ data.width/2 }px;'></div>`;
  115. }
  116. return html;
  117. }
  118. build.no_content = function(typ) {
  119. var html;
  120. html = `
  121. <div class='no_content fadeIn'>
  122. ${ build.iconic(typ) }
  123. `
  124. switch (typ) {
  125. case 'magnifying-glass': html += '<p>No results</p>';
  126. break;
  127. case 'eye': html += '<p>No public albums</p>';
  128. break;
  129. case 'cog': html += '<p>No configuration</p>';
  130. break;
  131. }
  132. html += '</div>';
  133. return html;
  134. }
  135. build.uploadModal = function(title, files) {
  136. var html = '',
  137. i = 0,
  138. file = null;
  139. html = `
  140. <h1>${ title }</h1>
  141. <div class='rows'>
  142. `
  143. while (i<files.length) {
  144. file = files[i];
  145. if (file.name.length>40) file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length-20, 20);
  146. html += `
  147. <div class='row'>
  148. <a class='name'>${ lychee.escapeHTML(file.name) }</a>
  149. `
  150. if (file.supported===true) html += `<a class='status'></a>`;
  151. else html += `<a class='status error'>Not supported</a>`;
  152. html += `
  153. <p class='notice'></p>
  154. </div>
  155. `
  156. i++;
  157. }
  158. html += '</div>';
  159. return html;
  160. }
  161. build.tags = function(tags, forView) {
  162. var html = '',
  163. editTagsHTML = '';
  164. if (forView!==true&&lychee.publicMode!==true) editTagsHTML = ' ' + build.editIcon('edit_tags');
  165. if (tags!=='') {
  166. tags = tags.split(',');
  167. tags.forEach(function(tag, index, array) {
  168. html += `<a class='tag'>${ tag }<span data-index='${ index }'>${ build.iconic('x') }</span></a>`
  169. });
  170. html += editTagsHTML;
  171. } else {
  172. html = `<div class='empty'>No Tags${ editTagsHTML }</div>`;
  173. }
  174. return html;
  175. }
  176. build.infoboxPhoto = function(data, forView) {
  177. var html = '',
  178. visible = '',
  179. editTitleHTML = '',
  180. editDescriptionHTML = '',
  181. exifHash = '',
  182. info = [];
  183. switch (data.public) {
  184. case '0': visible = 'No';
  185. break;
  186. case '1': visible = 'Yes';
  187. break;
  188. case '2': visible = 'Yes (Album)';
  189. break;
  190. default: visible = '-';
  191. break;
  192. }
  193. if (forView!==true&&lychee.publicMode!==true) {
  194. editTitleHTML = ' ' + build.editIcon('edit_title');
  195. editDescriptionHTML = ' ' + build.editIcon('edit_description');
  196. }
  197. infos = [
  198. ['', 'Basics'],
  199. ['Title', data.title + editTitleHTML],
  200. ['Uploaded', data.sysdate],
  201. ['Description', data.description + editDescriptionHTML],
  202. ['', 'Image'],
  203. ['Size', data.size],
  204. ['Format', data.type],
  205. ['Resolution', data.width + ' x ' + data.height],
  206. ['Tags', build.tags(data.tags, forView)]
  207. ]
  208. exifHash = data.takestamp+data.make+data.model+data.shutter+data.aperture+data.focal+data.iso;
  209. if (exifHash!=='0') {
  210. infos = infos.concat([
  211. ['', 'Camera'],
  212. ['Captured', data.takedate],
  213. ['Make', data.make],
  214. ['Type/Model', data.model],
  215. ['Shutter Speed', data.shutter],
  216. ['Aperture', data.aperture],
  217. ['Focal Length', data.focal],
  218. ['ISO', data.iso]
  219. ]);
  220. }
  221. infos = infos.concat([
  222. ['', 'Share'],
  223. ['Public', visible]
  224. ]);
  225. infos.forEach(function(info, i, items) {
  226. if (info[1]===''||info[1]===null||info[1]===undefined) info[1] = '-';
  227. switch (info[0]) {
  228. case '':
  229. // Divider
  230. html += `
  231. </table>
  232. <div class='divider'>
  233. <h1>${ info[1] }</h1>
  234. </div>
  235. <table>
  236. `
  237. break;
  238. case 'Tags':
  239. // Tags
  240. if (forView!==true&&lychee.publicMode===false) {
  241. html += `
  242. </table>
  243. <div class='divider'>
  244. <h1>${ info[0] }</h1>
  245. </div>
  246. <div id='tags'>${ info[1] }</div>
  247. `
  248. }
  249. break;
  250. default:
  251. // Item
  252. html += `
  253. <tr>
  254. <td>${ info[0] }</td>
  255. <td class='attr_${ info[0].toLowerCase() }'>${ info[1] }</td>
  256. </tr>
  257. `
  258. break;
  259. }
  260. });
  261. html += `
  262. </table>
  263. <div class='bumper'></div>
  264. `
  265. return html;
  266. }
  267. build.infoboxAlbum = function(data, forView) {
  268. var html = '',
  269. visible = '',
  270. password = '',
  271. downloadable = '',
  272. editTitleHTML = '',
  273. editDescriptionHTML = '',
  274. infos = [];
  275. switch (data.public) {
  276. case '0': visible = 'No';
  277. break;
  278. case '1': visible = 'Yes';
  279. break;
  280. default: visible = '-';
  281. break;
  282. }
  283. switch (data.password) {
  284. case false: password = 'No';
  285. break;
  286. case true: password = 'Yes';
  287. break;
  288. default: password = '-';
  289. break;
  290. }
  291. switch (data.downloadable) {
  292. case '0': downloadable = 'No';
  293. break;
  294. case '1': downloadable = 'Yes';
  295. break;
  296. default: downloadable = '-';
  297. break;
  298. }
  299. if (forView!==true&&lychee.publicMode!==true) {
  300. editTitleHTML = ' ' + build.editIcon('edit_title_album');
  301. editDescriptionHTML = ' ' + build.editIcon('edit_description_album');
  302. }
  303. infos = [
  304. ['', 'Basics'],
  305. ['Title', data.title + editTitleHTML],
  306. ['Description', data.description + editDescriptionHTML],
  307. ['', 'Album'],
  308. ['Created', data.sysdate],
  309. ['Images', data.num],
  310. ['', 'Share'],
  311. ['Public', visible],
  312. ['Downloadable', downloadable],
  313. ['Password', password]
  314. ]
  315. infos.forEach(function(info, i, items) {
  316. if (info[0]==='') {
  317. // Divider
  318. html += `
  319. </table>
  320. <div class='divider'>
  321. <h1>${ info[1] }</h1>
  322. </div>
  323. <table id='infos'>
  324. `
  325. } else {
  326. // Item
  327. html += `
  328. <tr>
  329. <td>${ info[0] }</td>
  330. <td class='attr_${ info[0].toLowerCase() }'>${ info[1] }</td>
  331. </tr>
  332. `
  333. }
  334. });
  335. html += `
  336. </table>
  337. <div class='bumper'></div>
  338. `
  339. return html;
  340. }