view.js 9.3 KB

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