view.js 11 KB

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