build.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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: thumbPath, hasRetina: thumbRetina } = 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='thumb' data-overlay='false'>
  30. <img src='$${ data.thumbs[1] }' width='200' height='200' alt='thumb' data-overlay='false'>
  31. <img src='$${ thumbPath }' width='200' height='200' alt='thumb' data-overlay='$${ thumbRetina }'>
  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: thumbPath, hasRetina: thumbRetina } = lychee.retinize(data.thumbUrl)
  54. html += lychee.html`
  55. <div class='photo' data-album-id='$${ data.album }' data-id='$${ data.id }'>
  56. <img src='$${ thumbPath }' width='200' height='200' alt='thumb'>
  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, size, visibleControls) {
  75. let html = ''
  76. if (size==='big') {
  77. if (visibleControls===true) html += lychee.html`<div id='image' style='background-image: url($${ data.url })'></div>`
  78. else html += lychee.html`<div id='image' style='background-image: url($${ data.url });' class='full'></div>`
  79. } else if (size==='medium') {
  80. if (visibleControls===true) html += lychee.html`<div id='image' style='background-image: url($${ data.medium })'></div>`
  81. else html += lychee.html`<div id='image' style='background-image: url($${ data.medium });' class='full'></div>`
  82. } else if (size==='small') {
  83. if (visibleControls===true) html += lychee.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>`
  84. else html += lychee.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>`
  85. }
  86. html += `
  87. <div class='arrow_wrapper arrow_wrapper--previous'><a id='previous'>${ build.iconic('caret-left') }</a></div>
  88. <div class='arrow_wrapper arrow_wrapper--next'><a id='next'>${ build.iconic('caret-right') }</a></div>
  89. `
  90. return html
  91. }
  92. build.no_content = function(typ) {
  93. let html = ''
  94. html += `
  95. <div class='no_content fadeIn'>
  96. ${ build.iconic(typ) }
  97. `
  98. switch (typ) {
  99. case 'magnifying-glass':
  100. html += `<p>No results</p>`
  101. break
  102. case 'eye':
  103. html += `<p>No public albums</p>`
  104. break
  105. case 'cog':
  106. html += `<p>No configuration</p>`
  107. break
  108. case 'question-mark':
  109. html += `<p>Photo not found</p>`
  110. break
  111. }
  112. html += `</div>`
  113. return html
  114. }
  115. build.uploadModal = function(title, files) {
  116. let html = ''
  117. html += lychee.html`
  118. <h1>$${ title }</h1>
  119. <div class='rows'>
  120. `
  121. let i = 0
  122. while (i<files.length) {
  123. let file = files[i]
  124. if (file.name.length>40) file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length-20, 20)
  125. html += lychee.html`
  126. <div class='row'>
  127. <a class='name'>$${ file.name }</a>
  128. `
  129. if (file.supported===true) html += `<a class='status'></a>`
  130. else html += `<a class='status error'>Not supported</a>`
  131. html += `
  132. <p class='notice'></p>
  133. </div>
  134. `
  135. i++
  136. }
  137. html += `</div>`
  138. return html
  139. }
  140. build.tags = function(tags) {
  141. let html = ''
  142. if (tags!=='') {
  143. tags = tags.split(',')
  144. tags.forEach(function(tag, index, array) {
  145. html += lychee.html`<a class='tag'>$${ tag }<span data-index='$${ index }'>${ build.iconic('x') }</span></a>`
  146. })
  147. } else {
  148. html = `<div class='empty'>No Tags</div>`
  149. }
  150. return html
  151. }