view.js 9.1 KB

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