build.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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) {
  7. var html = '';
  8. classes = classes || '';
  9. html = `
  10. <svg class='iconic ${ classes }'>
  11. <use xlink:href='#${ icon }' />
  12. </svg>
  13. `
  14. return html;
  15. }
  16. build.divider = function(title) {
  17. var html = '';
  18. html = `
  19. <div class='divider fadeIn'>
  20. <h1>${ title }</h1>
  21. </div>
  22. `
  23. return html;
  24. }
  25. build.editIcon = function(id) {
  26. var html = '';
  27. html = `<div id='${ id }' class='edit'>${ build.iconic('pencil') }</div>`
  28. return html;
  29. }
  30. build.multiselect = function(top, left) {
  31. var html = '';
  32. html = `<div id='multiselect' style='top: ${ top }px; left: ${ left }px;'></div>`
  33. return html;
  34. }
  35. build.album = function(data) {
  36. if (data===null||data===undefined) return '';
  37. var html = '',
  38. title = data.title,
  39. longTitle = '';
  40. if (title!==null&&title.length>18) {
  41. title = data.title.substr(0, 18) + '...';
  42. longTitle = data.title;
  43. }
  44. var {path: thumbPath, hasRetina: thumbRetina} = lychee.retinize(data.thumbs[0]);
  45. html = `
  46. <div class='album' data-id='${ data.id }'>
  47. <img src='${ data.thumbs[2] }' width='200' height='200' alt='thumb' data-retina='false'>
  48. <img src='${ data.thumbs[1] }' width='200' height='200' alt='thumb' data-retina='false'>
  49. <img src='${ thumbPath }' width='200' height='200' alt='thumb' data-retina='${ thumbRetina }'>
  50. <div class='overlay'>
  51. <h1 title='${ longTitle }'>${ title }</h1>
  52. <a>${ data.sysdate }</a>
  53. </div>
  54. `
  55. if (lychee.publicMode===false) {
  56. if (data.star==='1') html += `<a class='badge icn-star'>${ build.iconic('star') }</a>`;
  57. if (data.public==='1') html += `<a class='badge icn-share'>${ build.iconic('eye') }</a>`;
  58. if (data.unsorted==='1') html += `<a class='badge'>${ build.iconic('list') }</a>`;
  59. if (data.recent==='1') html += `<a class='badge'>${ build.iconic('clock') }</a>`;
  60. if (data.password==='1') html += `<a class='badge'>${ build.iconic('lock-locked') }</a>`;
  61. }
  62. html += '</div>'
  63. return html;
  64. }
  65. build.photo = function(data) {
  66. if (data===null||data===undefined) return '';
  67. var html = '',
  68. title = data.title,
  69. longTitle = '';
  70. if (title!==null&&title.length>18) {
  71. title = data.title.substr(0, 18) + '...';
  72. longTitle = data.title;
  73. }
  74. var {path: thumbPath, hasRetina: thumbRetina} = lychee.retinize(data.thumbUrl);
  75. html = `
  76. <div class='photo' data-album-id='${ data.album }' data-id='${ data.id }'>
  77. <img src='${ thumbPath }' width='200' height='200' alt='thumb'>
  78. <div class='overlay'>
  79. <h1 title='${ longTitle }'>${ title }</h1>
  80. `
  81. if (data.cameraDate==='1') html += `<a><span title='Camera Date'>${ build.iconic('camera-slr') }</span>${ data.sysdate }</a>`;
  82. else html += `<a>${ data.sysdate }</a>`;
  83. html += '</div>';
  84. if (lychee.publicMode===false) {
  85. if (data.star==='1') html += `<a class='badge iconic-star'>${ build.iconic('star') }</a>`;
  86. if (data.public==='1'&&album.json.public!=='1') html += `<a class='badge iconic-share'>${ build.iconic('eye') }</a>`;
  87. }
  88. html += '</div>';
  89. return html
  90. }
  91. build.imageview = function(data, size, visibleControls) {
  92. if (data===null||data===undefined) return '';
  93. var html = '';
  94. html = `
  95. <div class='arrow_wrapper arrow_wrapper--previous'><a id='previous'>${ build.iconic('caret-left') }</a></div>
  96. <div class='arrow_wrapper arrow_wrapper--next'><a id='next'>${ build.iconic('caret-right') }</a></div>
  97. `
  98. if (size==='big') {
  99. if (visibleControls===true)
  100. html += `<div id='image' style='background-image: url(${ data.url })'></div>`;
  101. else
  102. html += `<div id='image' style='background-image: url(${ data.url });' class='full'></div>`;
  103. } else if (size==='medium') {
  104. if (visibleControls===true)
  105. html += `<div id='image' style='background-image: url(${ data.medium })'></div>`;
  106. else
  107. html += `<div id='image' style='background-image: url(${ data.medium });' class='full'></div>`;
  108. } else if (size==='small') {
  109. if (visibleControls===true)
  110. 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>`;
  111. else
  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) }px; margin-left: -${ data.width/2 }px;'></div>`;
  113. }
  114. return html;
  115. }
  116. build.no_content = function(typ) {
  117. var html;
  118. html = `
  119. <div class='no_content fadeIn'>
  120. ${ build.iconic(typ) }
  121. `
  122. switch (typ) {
  123. case 'magnifying-glass': html += '<p>No results</p>';
  124. break;
  125. case 'eye': html += '<p>No public albums</p>';
  126. break;
  127. case 'cog': html += '<p>No configuration</p>';
  128. break;
  129. }
  130. html += '</div>';
  131. return html;
  132. }
  133. build.uploadModal = function(title, files) {
  134. var html = '',
  135. i = 0,
  136. file = null;
  137. html = `
  138. <h1>${ title }</h1>
  139. <div class='rows'>
  140. `
  141. while (i<files.length) {
  142. file = files[i];
  143. if (file.name.length>40) file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length-20, 20);
  144. html += `
  145. <div class='row'>
  146. <a class='name'>${ lychee.escapeHTML(file.name) }</a>
  147. `
  148. if (file.supported===true) html += `<a class='status'></a>`;
  149. else html += `<a class='status error'>Not supported</a>`;
  150. html += `
  151. <p class='notice'></p>
  152. </div>
  153. `
  154. i++;
  155. }
  156. html += '</div>';
  157. return html;
  158. }
  159. build.tags = function(tags) {
  160. var html = '',
  161. editTagsHTML = '';
  162. if (tags!=='') {
  163. tags = tags.split(',');
  164. tags.forEach(function(tag, index, array) {
  165. html += `<a class='tag'>${ tag }<span data-index='${ index }'>${ build.iconic('x') }</span></a>`
  166. });
  167. } else {
  168. html = `<div class='empty'>No Tags</div>`;
  169. }
  170. return html;
  171. }