build.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. * @description This module is used to generate HTML-Code.
  3. */
  4. build = {}
  5. build.iconic = function(icon, classes = '') {
  6. let html = ''
  7. html += lychee.html`<svg class='iconic $${ classes }'><use xlink:href='#$${ icon }' /></svg>`
  8. return html
  9. }
  10. build.divider = function(title) {
  11. let html = ''
  12. html += lychee.html`<div class='divider'><h1>$${ title }</h1></div>`
  13. return html
  14. }
  15. build.editIcon = function(id) {
  16. let html = ''
  17. html += lychee.html`<div id='$${ id }' class='edit'>${ build.iconic('pencil') }</div>`
  18. return html
  19. }
  20. build.multiselect = function(top, left) {
  21. return lychee.html`<div id='multiselect' style='top: $${ top }px; left: $${ left }px;'></div>`
  22. }
  23. build.album = function(data) {
  24. let html = ''
  25. let { path: retinaThumbUrl, isPhoto } = lychee.retinize(data.thumbs[0])
  26. html += lychee.html`
  27. <div class='album' data-id='$${ data.id }'>
  28. <img src='$${ data.thumbs[2] }' width='200' height='200' alt='Photo thumbnail' data-overlay='false' draggable='false'>
  29. <img src='$${ data.thumbs[1] }' width='200' height='200' alt='Photo thumbnail' data-overlay='false' draggable='false'>
  30. <img src='$${ data.thumbs[0] }' srcset='$${ retinaThumbUrl } 1.5x' width='200' height='200' alt='Photo thumbnail' data-overlay='$${ isPhoto }' draggable='false'>
  31. <div class='overlay'>
  32. <h1 title='$${ data.title }'>$${ data.title }</h1>
  33. <a>$${ data.sysdate }</a>
  34. </div>
  35. `
  36. if (lychee.publicMode===false) {
  37. html += lychee.html`
  38. <div class='badges'>
  39. <a class='badge $${ (data.star==='1' ? 'badge--visible' : '') } icn-star'>${ build.iconic('star') }</a>
  40. <a class='badge $${ (data.public==='1' ? 'badge--visible' : '') } icn-share'>${ build.iconic('eye') }</a>
  41. <a class='badge $${ (data.unsorted==='1' ? 'badge--visible' : '') }'>${ build.iconic('list') }</a>
  42. <a class='badge $${ (data.recent==='1' ? 'badge--visible' : '') }'>${ build.iconic('clock') }</a>
  43. <a class='badge $${ (data.password==='1' ? 'badge--visible' : '') }'>${ build.iconic('lock-locked') }</a>
  44. </div>
  45. `
  46. }
  47. html += '</div>'
  48. return html
  49. }
  50. build.photo = function(data) {
  51. let html = ''
  52. let { path: retinaThumbUrl } = lychee.retinize(data.thumbUrl)
  53. html += lychee.html`
  54. <div class='photo' data-album-id='$${ data.album }' data-id='$${ data.id }'>
  55. <img src='$${ data.thumbUrl }' srcset='$${ retinaThumbUrl } 1.5x' width='200' height='200' alt='Photo thumbnail' draggable='false'>
  56. <div class='overlay'>
  57. <h1 title='$${ data.title }'>$${ data.title }</h1>
  58. `
  59. if (data.cameraDate==='1') html += lychee.html`<a><span title='Camera Date'>${ build.iconic('camera-slr') }</span>$${ data.sysdate }</a>`
  60. else html += lychee.html`<a>$${ data.sysdate }</a>`
  61. html += `</div>`
  62. if (lychee.publicMode===false) {
  63. html += lychee.html`
  64. <div class='badges'>
  65. <a class='badge $${ (data.star==='1' ? 'badge--visible' : '') } icn-star'>${ build.iconic('star') }</a>
  66. <a class='badge $${ ((data.public==='1' && album.json.public!=='1') ? 'badge--visible' : '') } icn-share'>${ build.iconic('eye') }</a>
  67. </div>
  68. `
  69. }
  70. html += `</div>`
  71. return html
  72. }
  73. build.imageview = function(data, visibleControls) {
  74. let html = ''
  75. let hasMedium = data.medium!==''
  76. if (hasMedium===false) {
  77. html += lychee.html`<img id='image' class='$${ visibleControls===true ? '' : 'full' }' src='$${ data.url }' draggable='false'>`
  78. } else {
  79. html += lychee.html`<img id='image' class='$${ visibleControls===true ? '' : 'full' }' src='$${ data.url }' srcset='$${ data.medium } 1920w, $${ data.url } $${ data.width }w' draggable='false'>`
  80. }
  81. html += `
  82. <div class='arrow_wrapper arrow_wrapper--previous'><a id='previous'>${ build.iconic('caret-left') }</a></div>
  83. <div class='arrow_wrapper arrow_wrapper--next'><a id='next'>${ build.iconic('caret-right') }</a></div>
  84. `
  85. return html
  86. }
  87. build.no_content = function(typ) {
  88. let html = ''
  89. html += `
  90. <div class='no_content fadeIn'>
  91. ${ build.iconic(typ) }
  92. `
  93. switch (typ) {
  94. case 'magnifying-glass':
  95. html += `<p>No results</p>`
  96. break
  97. case 'eye':
  98. html += `<p>No public albums</p>`
  99. break
  100. case 'cog':
  101. html += `<p>No configuration</p>`
  102. break
  103. case 'question-mark':
  104. html += `<p>Photo not found</p>`
  105. break
  106. }
  107. html += `</div>`
  108. return html
  109. }
  110. build.uploadModal = function(title, files) {
  111. let html = ''
  112. html += lychee.html`
  113. <h1>$${ title }</h1>
  114. <div class='rows'>
  115. `
  116. let i = 0
  117. while (i<files.length) {
  118. let file = files[i]
  119. if (file.name.length>40) file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length - 20, 20)
  120. html += lychee.html`
  121. <div class='row'>
  122. <a class='name'>$${ file.name }</a>
  123. <a class='status'></a>
  124. <p class='notice'></p>
  125. </div>
  126. `
  127. i++
  128. }
  129. html += `</div>`
  130. return html
  131. }
  132. build.tags = function(tags) {
  133. let html = ''
  134. if (tags!=='') {
  135. tags = tags.split(',')
  136. tags.forEach(function(tag, index, array) {
  137. html += lychee.html`<a class='tag'>$${ tag }<span data-index='$${ index }'>${ build.iconic('x') }</span></a>`
  138. })
  139. } else {
  140. html = `<div class='empty'>No Tags</div>`
  141. }
  142. return html
  143. }