build.js 5.9 KB

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