view.js 8.8 KB

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