build.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. if (title!==null&&title.length>18) {
  43. title = data.title.substr(0, 18) + '...';
  44. longTitle = data.title;
  45. }
  46. var {path: thumbPath, hasRetina: thumbRetina} = lychee.retinize(data.thumbs[0]);
  47. html = `
  48. <div class='album' data-id='${ data.id }'>
  49. <img src='${ data.thumbs[2] }' width='200' height='200' alt='thumb' data-retina='false'>
  50. <img src='${ data.thumbs[1] }' width='200' height='200' alt='thumb' data-retina='false'>
  51. <img src='${ thumbPath }' width='200' height='200' alt='thumb' data-retina='${ thumbRetina }'>
  52. <div class='overlay'>
  53. <h1 title='${ longTitle }'>${ title }</h1>
  54. <a>${ data.sysdate }</a>
  55. </div>
  56. `
  57. if (lychee.publicMode===false) {
  58. if (data.star==='1') html += `<a class='badge icn-star'>${ build.iconic('star') }</a>`;
  59. if (data.public==='1') html += `<a class='badge icn-share'>${ build.iconic('eye') }</a>`;
  60. if (data.unsorted==='1') html += `<a class='badge'>${ build.iconic('list') }</a>`;
  61. if (data.recent==='1') html += `<a class='badge'>${ build.iconic('clock') }</a>`;
  62. if (data.password==='1') html += `<a class='badge'>${ build.iconic('lock-locked') }</a>`;
  63. }
  64. html += '</div>'
  65. return html;
  66. }
  67. build.photo = function(data) {
  68. if (data===null||data===undefined) return '';
  69. var html = '',
  70. title = data.title,
  71. longTitle = '';
  72. if (title!==null&&title.length>18) {
  73. title = data.title.substr(0, 18) + '...';
  74. longTitle = data.title;
  75. }
  76. var {path: thumbPath, hasRetina: thumbRetina} = lychee.retinize(data.thumbUrl);
  77. html = `
  78. <div class='photo' data-album-id='${ data.album }' data-id='${ data.id }'>
  79. <img src='${ thumbPath }' 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) {
  162. var html = '',
  163. editTagsHTML = '';
  164. if (tags!=='') {
  165. tags = tags.split(',');
  166. tags.forEach(function(tag, index, array) {
  167. html += `<a class='tag'>${ tag }<span data-index='${ index }'>${ build.iconic('x') }</span></a>`
  168. });
  169. } else {
  170. html = `<div class='empty'>No Tags</div>`;
  171. }
  172. return html;
  173. }