view.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. var smartData = '',
  18. 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&&
  44. view.albums.content.scrollPosition!==0) {
  45. $(document).scrollTop(view.albums.content.scrollPosition);
  46. }
  47. },
  48. title: function(albumID) {
  49. var title = albums.getByID(albumID).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. var 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. var title = album.json.content[photoID].title;
  113. $('.photo[data-id="' + photoID + '"] .overlay h1')
  114. .html(title)
  115. .attr('title', title);
  116. },
  117. star: function(photoID) {
  118. $('.photo[data-id="' + photoID + '"] .iconic-star').remove();
  119. if (album.json.content[photoID].star==='1') $('.photo[data-id="' + photoID + '"]').append("<a class='badge iconic-star'>" + build.iconic('star') + "</a>");
  120. },
  121. public: function(photoID) {
  122. $('.photo[data-id="' + photoID + '"] .iconic-share').remove();
  123. if (album.json.content[photoID].public==='1') $('.photo[data-id="' + photoID + '"]').append("<a class='badge iconic-share'>" + build.iconic('eye') + "</a>");
  124. },
  125. delete: function(photoID) {
  126. $('.photo[data-id="' + photoID + '"]').css('opacity', 0).animate({
  127. width: 0,
  128. marginLeft: 0
  129. }, 300, function() {
  130. $(this).remove();
  131. // Only when search is not active
  132. if (!visible.albums()) {
  133. album.json.num--;
  134. view.album.num();
  135. view.album.title();
  136. }
  137. });
  138. }
  139. },
  140. description: function() {
  141. sidebar.changeAttr('description', album.json.description);
  142. },
  143. num: function() {
  144. sidebar.changeAttr('images', album.json.num);
  145. },
  146. public: function() {
  147. if (album.json.public==='1') {
  148. $('#button_share_album')
  149. .addClass('active')
  150. .attr('title', 'Share Album');
  151. $('.photo .iconic-share').remove();
  152. if (album.json.init) sidebar.changeAttr('public', 'Yes');
  153. } else {
  154. $('#button_share_album')
  155. .removeClass('active')
  156. .attr('title', 'Make Public');
  157. if (album.json.init) sidebar.changeAttr('public', 'No');
  158. }
  159. },
  160. visible: function() {
  161. if (album.json.visible==='1') sidebar.changeAttr('visible', 'Yes');
  162. else sidebar.changeAttr('visible', 'No');
  163. },
  164. downloadable: function() {
  165. if (album.json.downloadable==='1') sidebar.changeAttr('downloadable', 'Yes');
  166. else sidebar.changeAttr('downloadable', 'No');
  167. },
  168. password: function() {
  169. if (album.json.password==='1') sidebar.changeAttr('password', 'Yes');
  170. else sidebar.changeAttr('password', 'No');
  171. },
  172. sidebar: function() {
  173. if ((visible.album()||!album.json.init)&&!visible.photo()) {
  174. let structure = sidebar.createStructure.album(album.json),
  175. html = sidebar.render(structure);
  176. sidebar.dom('.wrapper').html(html);
  177. sidebar.bind();
  178. }
  179. }
  180. }
  181. view.photo = {
  182. init: function() {
  183. photo.parse();
  184. view.photo.sidebar();
  185. view.photo.title();
  186. view.photo.star();
  187. view.photo.public();
  188. view.photo.photo();
  189. photo.json.init = 1;
  190. },
  191. show: function() {
  192. // Change header
  193. lychee.content.addClass('view');
  194. header.setMode('photo');
  195. // Make body not scrollable
  196. $('body').css('overflow', 'hidden');
  197. // Fullscreen
  198. $(document)
  199. .bind('mouseenter', header.show)
  200. .bind('mouseleave', header.hide);
  201. lychee.animate(lychee.imageview, 'fadeIn');
  202. },
  203. hide: function() {
  204. header.show();
  205. lychee.content.removeClass('view');
  206. header.setMode('album');
  207. // Make body scrollable
  208. $('body').css('overflow', 'auto');
  209. // Disable Fullscreen
  210. $(document)
  211. .unbind('mouseenter')
  212. .unbind('mouseleave');
  213. // Hide Photo
  214. lychee.animate(lychee.imageview, 'fadeOut');
  215. setTimeout(function() {
  216. lychee.imageview.hide();
  217. view.album.sidebar();
  218. }, 300);
  219. },
  220. title: function() {
  221. if (photo.json.init) sidebar.changeAttr('title', photo.json.title);
  222. lychee.setTitle(photo.json.title, true);
  223. },
  224. description: function() {
  225. if (photo.json.init) sidebar.changeAttr('description', photo.json.description);
  226. },
  227. star: function() {
  228. if (photo.json.star==1) {
  229. // Starred
  230. $('#button_star')
  231. .addClass('active')
  232. .attr('title', 'Unstar Photo');
  233. } else {
  234. // Unstarred
  235. $('#button_star').removeClass('active');
  236. $('#button_star').attr('title', 'Star Photo');
  237. }
  238. },
  239. public: function() {
  240. if (photo.json.public==='1'||photo.json.public==='2') {
  241. // Photo public
  242. $('#button_share')
  243. .addClass('active')
  244. .attr('title', 'Share Photo');
  245. if (photo.json.init) sidebar.changeAttr('public', 'Yes');
  246. } else {
  247. // Photo private
  248. $('#button_share')
  249. .removeClass('active')
  250. .attr('title', 'Make Public');
  251. if (photo.json.init) sidebar.changeAttr('public', 'No');
  252. }
  253. },
  254. tags: function() {
  255. sidebar.changeAttr('tags', build.tags(photo.json.tags));
  256. sidebar.bind();
  257. },
  258. photo: function() {
  259. lychee.imageview.html(build.imageview(photo.json, photo.getSize(), visible.header()));
  260. var $nextArrow = lychee.imageview.find('a#next'),
  261. $previousArrow = lychee.imageview.find('a#previous'),
  262. hasNext = album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto==='',
  263. hasPrevious = album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto==='';
  264. if (hasNext||lychee.viewMode) { $nextArrow.hide(); }
  265. else {
  266. var nextPhotoID = album.json.content[photo.getID()].nextPhoto,
  267. nextPhoto = album.json.content[nextPhotoID];
  268. $nextArrow.css('background-image', 'linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("' + nextPhoto.thumbUrl + '")');
  269. }
  270. if (hasPrevious||lychee.viewMode) { $previousArrow.hide(); }
  271. else {
  272. var previousPhotoID = album.json.content[photo.getID()].previousPhoto,
  273. previousPhoto = album.json.content[previousPhotoID];
  274. $previousArrow.css('background-image', 'linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("' + previousPhoto.thumbUrl + '")');
  275. };
  276. },
  277. sidebar: function() {
  278. var structure = sidebar.createStructure.photo(photo.json),
  279. html = sidebar.render(structure);
  280. sidebar.dom('.wrapper').html(html);
  281. sidebar.bind();
  282. }
  283. }