view.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /**
  2. * @description Responsible to reflect data changes to the UI.
  3. * @copyright 2015 by Tobias Reich
  4. */
  5. view = {}
  6. view.albums = {
  7. init: function() {
  8. view.albums.title()
  9. view.albums.content.init()
  10. },
  11. title: function() {
  12. lychee.setTitle('Albums', false)
  13. },
  14. content: {
  15. scrollPosition: 0,
  16. init: function() {
  17. let smartData = ''
  18. let albumsData = ''
  19. // Smart Albums
  20. if (lychee.publicMode===false) {
  21. albums.parse(albums.json.smartalbums.unsorted)
  22. albums.parse(albums.json.smartalbums.public)
  23. albums.parse(albums.json.smartalbums.starred)
  24. albums.parse(albums.json.smartalbums.recent)
  25. smartData = build.divider('Smart Albums') + build.album(albums.json.smartalbums.unsorted) + build.album(albums.json.smartalbums.public) + build.album(albums.json.smartalbums.starred) + build.album(albums.json.smartalbums.recent)
  26. }
  27. // Albums
  28. if (albums.json.albums && albums.json.num!==0) {
  29. $.each(albums.json.albums, function() {
  30. albums.parse(this)
  31. albumsData += build.album(this)
  32. })
  33. // Add divider
  34. if (lychee.publicMode===false) albumsData = build.divider('Albums') + albumsData
  35. }
  36. if (smartData==='' && albumsData==='') {
  37. lychee.content.html('')
  38. $('body').append(build.no_content('eye'))
  39. } else {
  40. lychee.content.html(smartData + albumsData)
  41. }
  42. // Restore scroll position
  43. if (view.albums.content.scrollPosition!=null && view.albums.content.scrollPosition!==0) {
  44. $(document).scrollTop(view.albums.content.scrollPosition)
  45. }
  46. },
  47. title: function(albumID) {
  48. let title = albums.getByID(albumID).title
  49. title = lychee.escapeHTML(title)
  50. $('.album[data-id="' + albumID + '"] .overlay h1')
  51. .html(title)
  52. .attr('title', title)
  53. },
  54. delete: function(albumID) {
  55. $('.album[data-id="' + albumID + '"]').css('opacity', 0).animate({
  56. width : 0,
  57. marginLeft : 0
  58. }, 300, function() {
  59. $(this).remove()
  60. if (albums.json.num<=0) lychee.content.find('.divider:last-child').remove()
  61. })
  62. }
  63. }
  64. }
  65. view.album = {
  66. init: function() {
  67. album.parse()
  68. view.album.sidebar()
  69. view.album.title()
  70. view.album.public()
  71. view.album.content.init()
  72. album.json.init = 1
  73. },
  74. title: function() {
  75. if ((visible.album() || !album.json.init) && !visible.photo()) {
  76. switch (album.getID()) {
  77. case 'f':
  78. lychee.setTitle('Starred', false)
  79. break
  80. case 's':
  81. lychee.setTitle('Public', false)
  82. break
  83. case 'r':
  84. lychee.setTitle('Recent', false)
  85. break
  86. case '0':
  87. lychee.setTitle('Unsorted', false)
  88. break
  89. default:
  90. if (album.json.init) sidebar.changeAttr('title', album.json.title)
  91. lychee.setTitle(album.json.title, true)
  92. break
  93. }
  94. }
  95. },
  96. content: {
  97. init: function() {
  98. let photosData = ''
  99. if (album.json.content && album.json.content!==false) {
  100. // Build photos
  101. $.each(album.json.content, function() {
  102. photosData += build.photo(this)
  103. })
  104. }
  105. // Save and reset scroll position
  106. view.albums.content.scrollPosition = $(document).scrollTop()
  107. requestAnimationFrame(() => $(document).scrollTop(0))
  108. // Add photos to view
  109. lychee.content.html(photosData)
  110. },
  111. title: function(photoID) {
  112. let title = album.json.content[photoID].title
  113. title = lychee.escapeHTML(title)
  114. $('.photo[data-id="' + photoID + '"] .overlay h1')
  115. .html(title)
  116. .attr('title', title)
  117. },
  118. star: function(photoID) {
  119. let $badge = $('.photo[data-id="' + photoID + '"] .icn-star')
  120. if (album.json.content[photoID].star==='1') $badge.addClass('badge--visible')
  121. else $badge.removeClass('badge--visible')
  122. },
  123. public: function(photoID) {
  124. let $badge = $('.photo[data-id="' + photoID + '"] .icn-share')
  125. if (album.json.content[photoID].public==='1') $badge.addClass('badge--visible')
  126. else $badge.removeClass('badge--visible')
  127. },
  128. delete: function(photoID) {
  129. $('.photo[data-id="' + photoID + '"]').css('opacity', 0).animate({
  130. width : 0,
  131. marginLeft : 0
  132. }, 300, function() {
  133. $(this).remove()
  134. // Only when search is not active
  135. if (!visible.albums()) {
  136. album.json.num--
  137. view.album.num()
  138. }
  139. })
  140. }
  141. },
  142. description: function() {
  143. sidebar.changeAttr('description', album.json.description)
  144. },
  145. num: function() {
  146. sidebar.changeAttr('images', album.json.num)
  147. },
  148. public: function() {
  149. if (album.json.public==='1') {
  150. $('#button_share_album')
  151. .addClass('active')
  152. .attr('title', 'Share Album')
  153. $('.photo .iconic-share').remove()
  154. if (album.json.init) sidebar.changeAttr('public', 'Yes')
  155. } else {
  156. $('#button_share_album')
  157. .removeClass('active')
  158. .attr('title', 'Make Public')
  159. if (album.json.init) sidebar.changeAttr('public', 'No')
  160. }
  161. },
  162. hidden: function() {
  163. if (album.json.visible==='1') sidebar.changeAttr('hidden', 'No')
  164. else sidebar.changeAttr('hidden', 'Yes')
  165. },
  166. downloadable: function() {
  167. if (album.json.downloadable==='1') sidebar.changeAttr('downloadable', 'Yes')
  168. else sidebar.changeAttr('downloadable', 'No')
  169. },
  170. password: function() {
  171. if (album.json.password==='1') sidebar.changeAttr('password', 'Yes')
  172. else sidebar.changeAttr('password', 'No')
  173. },
  174. sidebar: function() {
  175. if ((visible.album() || !album.json.init) && !visible.photo()) {
  176. let structure = sidebar.createStructure.album(album.json)
  177. let html = sidebar.render(structure)
  178. sidebar.dom('.sidebar__wrapper').html(html)
  179. sidebar.bind()
  180. }
  181. }
  182. }
  183. view.photo = {
  184. init: function() {
  185. photo.parse()
  186. view.photo.sidebar()
  187. view.photo.title()
  188. view.photo.star()
  189. view.photo.public()
  190. view.photo.photo()
  191. photo.json.init = 1
  192. },
  193. show: function() {
  194. // Change header
  195. lychee.content.addClass('view')
  196. header.setMode('photo')
  197. // Make body not scrollable
  198. $('body').css('overflow', 'hidden')
  199. // Fullscreen
  200. var timeout
  201. $(document).bind('mousemove', function() {
  202. clearTimeout(timeout)
  203. header.show()
  204. timeout = setTimeout(header.hide, 1000)
  205. })
  206. lychee.animate(lychee.imageview, 'fadeIn')
  207. },
  208. hide: function() {
  209. header.show()
  210. lychee.content.removeClass('view')
  211. header.setMode('album')
  212. // Make body scrollable
  213. $('body').css('overflow', 'auto')
  214. // Disable Fullscreen
  215. $(document)
  216. .unbind('mousemove')
  217. // Hide Photo
  218. lychee.animate(lychee.imageview, 'fadeOut')
  219. setTimeout(() => {
  220. lychee.imageview.hide()
  221. view.album.sidebar()
  222. }, 300)
  223. },
  224. title: function() {
  225. if (photo.json.init) sidebar.changeAttr('title', photo.json.title)
  226. lychee.setTitle(photo.json.title, true)
  227. },
  228. description: function() {
  229. if (photo.json.init) sidebar.changeAttr('description', photo.json.description)
  230. },
  231. star: function() {
  232. if (photo.json.star==='1') {
  233. // Starred
  234. $('#button_star')
  235. .addClass('active')
  236. .attr('title', 'Unstar Photo')
  237. } else {
  238. // Unstarred
  239. $('#button_star').removeClass('active')
  240. $('#button_star').attr('title', 'Star Photo')
  241. }
  242. },
  243. public: function() {
  244. if (photo.json.public==='1' || photo.json.public==='2') {
  245. // Photo public
  246. $('#button_share')
  247. .addClass('active')
  248. .attr('title', 'Share Photo')
  249. if (photo.json.init) sidebar.changeAttr('public', 'Yes')
  250. } else {
  251. // Photo private
  252. $('#button_share')
  253. .removeClass('active')
  254. .attr('title', 'Make Public')
  255. if (photo.json.init) sidebar.changeAttr('public', 'No')
  256. }
  257. },
  258. tags: function() {
  259. sidebar.changeAttr('tags', build.tags(photo.json.tags), true)
  260. sidebar.bind()
  261. },
  262. photo: function() {
  263. lychee.imageview.html(build.imageview(photo.json, visible.header()))
  264. let $nextArrow = lychee.imageview.find('a#next')
  265. let $previousArrow = lychee.imageview.find('a#previous')
  266. let photoID = photo.getID()
  267. let hasNext = album.json && album.json.content && album.json.content[photoID] && album.json.content[photoID].nextPhoto!=null && album.json.content[photoID].nextPhoto!==''
  268. let hasPrevious = album.json && album.json.content && album.json.content[photoID] && album.json.content[photoID].previousPhoto!=null && album.json.content[photoID].previousPhoto!==''
  269. if (hasNext===false || lychee.viewMode===true) {
  270. $nextArrow.hide()
  271. } else {
  272. let nextPhotoID = album.json.content[photoID].nextPhoto
  273. let nextPhoto = album.json.content[nextPhotoID]
  274. $nextArrow.css('background-image', lychee.html`linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("$${ nextPhoto.thumbUrl }")`)
  275. }
  276. if (hasPrevious===false || lychee.viewMode===true) {
  277. $previousArrow.hide()
  278. } else {
  279. let previousPhotoID = album.json.content[photoID].previousPhoto
  280. let previousPhoto = album.json.content[previousPhotoID]
  281. $previousArrow.css('background-image', lychee.html`linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("$${ previousPhoto.thumbUrl }")`)
  282. }
  283. },
  284. sidebar: function() {
  285. let structure = sidebar.createStructure.photo(photo.json)
  286. let html = sidebar.render(structure)
  287. sidebar.dom('.sidebar__wrapper').html(html)
  288. sidebar.bind()
  289. }
  290. }