build.js 5.6 KB

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