view.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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, true);
  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, true);
  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. password: function() {
  169. if (album.json.password==='1') sidebar.changeAttr('password', 'Yes');
  170. else sidebar.changeAttr('password', 'No');
  171. },
  172. downloadable: function() {
  173. if (album.json.downloadable==='1') sidebar.changeAttr('downloadable', 'Yes');
  174. else sidebar.changeAttr('downloadable', 'No');
  175. },
  176. sidebar: function() {
  177. if ((visible.album()||!album.json.init)&&!visible.photo()) {
  178. sidebar.dom('.wrapper').html(build.sidebarAlbum(album.json));
  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. $(document)
  201. .bind('mouseenter', header.show)
  202. .bind('mouseleave', header.hide);
  203. lychee.animate(lychee.imageview, 'fadeIn');
  204. },
  205. hide: function() {
  206. header.show();
  207. lychee.content.removeClass('view');
  208. header.setMode('album');
  209. // Make body scrollable
  210. $('body').css('overflow', 'auto');
  211. // Disable Fullscreen
  212. $(document)
  213. .unbind('mouseenter')
  214. .unbind('mouseleave');
  215. // Hide Photo
  216. lychee.animate(lychee.imageview, 'fadeOut');
  217. setTimeout(function() {
  218. lychee.imageview.hide();
  219. view.album.sidebar();
  220. }, 300);
  221. },
  222. title: function() {
  223. if (photo.json.init) sidebar.changeAttr('title', photo.json.title, true);
  224. lychee.setTitle(photo.json.title, true);
  225. },
  226. description: function() {
  227. if (photo.json.init) sidebar.changeAttr('description', photo.json.description, true);
  228. },
  229. star: function() {
  230. if (photo.json.star==1) {
  231. // Starred
  232. $('#button_star')
  233. .addClass('active')
  234. .attr('title', 'Unstar Photo');
  235. } else {
  236. // Unstarred
  237. $('#button_star').removeClass('active');
  238. $('#button_star').attr('title', 'Star Photo');
  239. }
  240. },
  241. public: function() {
  242. if (photo.json.public==='1'||photo.json.public==='2') {
  243. // Photo public
  244. $('#button_share')
  245. .addClass('active')
  246. .attr('title', 'Share Photo');
  247. if (photo.json.init) sidebar.changeAttr('public', 'Yes');
  248. } else {
  249. // Photo private
  250. $('#button_share')
  251. .removeClass('active')
  252. .attr('title', 'Make Public');
  253. if (photo.json.init) sidebar.changeAttr('public', 'No');
  254. }
  255. },
  256. tags: function() {
  257. sidebar.dom('#tags').html(build.tags(photo.json.tags));
  258. sidebar.bind();
  259. },
  260. photo: function() {
  261. lychee.imageview.html(build.imageview(photo.json, photo.getSize(), visible.header()));
  262. var $nextArrow = lychee.imageview.find('a#next'),
  263. $previousArrow = lychee.imageview.find('a#previous'),
  264. hasNext = album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto==='',
  265. hasPrevious = album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto==='';
  266. if (hasNext||lychee.viewMode) { $nextArrow.hide(); }
  267. else {
  268. var nextPhotoID = album.json.content[photo.getID()].nextPhoto,
  269. nextPhoto = album.json.content[nextPhotoID];
  270. $nextArrow.css('background-image', 'linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("' + nextPhoto.thumbUrl + '")');
  271. }
  272. if (hasPrevious||lychee.viewMode) { $previousArrow.hide(); }
  273. else {
  274. var previousPhotoID = album.json.content[photo.getID()].previousPhoto,
  275. previousPhoto = album.json.content[previousPhotoID];
  276. $previousArrow.css('background-image', 'linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("' + previousPhoto.thumbUrl + '")');
  277. };
  278. },
  279. sidebar: function() {
  280. sidebar.dom('.wrapper').html(build.sidebarPhoto(photo.json));
  281. sidebar.bind();
  282. }
  283. }