build.js 5.6 KB

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