view.js 9.0 KB

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