build.js 5.6 KB

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