view.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. 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('eye'));
  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 longTitle = '',
  59. title = albums.json.content[albumID].title;
  60. if (title!==null&&title.length>18) {
  61. longTitle = title;
  62. title = title.substr(0, 18) + '...';
  63. }
  64. $('.album[data-id="' + albumID + '"] .overlay h1')
  65. .html(title)
  66. .attr('title', longTitle);
  67. },
  68. delete: function(albumID) {
  69. $('.album[data-id="' + albumID + '"]').css('opacity', 0).animate({
  70. width: 0,
  71. marginLeft: 0
  72. }, 300, function() {
  73. $(this).remove();
  74. if (albums.json.num<=0) lychee.animate('.divider:last-of-type', 'fadeOut');
  75. });
  76. }
  77. }
  78. }
  79. view.album = {
  80. init: function() {
  81. album.parse();
  82. view.album.infobox();
  83. view.album.title();
  84. view.album.public();
  85. view.album.content.init();
  86. album.json.init = 1;
  87. },
  88. hide: function() {
  89. view.infobox.hide();
  90. },
  91. title: function() {
  92. if ((visible.album()||!album.json.init)&&!visible.photo()) {
  93. switch (album.getID()) {
  94. case 'f':
  95. lychee.setTitle('Starred', false);
  96. break;
  97. case 's':
  98. lychee.setTitle('Public', false);
  99. break;
  100. case 'r':
  101. lychee.setTitle('Recent', false);
  102. break;
  103. case '0':
  104. lychee.setTitle('Unsorted', false);
  105. break;
  106. default:
  107. if (album.json.init) $('#infobox .attr_title').html(album.json.title + ' ' + build.editIcon('edit_title_album'));
  108. lychee.setTitle(album.json.title, true);
  109. break;
  110. }
  111. }
  112. },
  113. content: {
  114. init: function() {
  115. var photosData = '';
  116. // Save and reset scroll position
  117. view.albums.content.scrollPosition = $(document).scrollTop();
  118. $('html, body').scrollTop(0);
  119. $.each(album.json.content, function() {
  120. photosData += build.photo(this);
  121. });
  122. lychee.content.html(photosData);
  123. $('img[data-type!="svg"]').retina();
  124. },
  125. title: function(photoID) {
  126. var longTitle = '',
  127. title = album.json.content[photoID].title;
  128. if (title!==null&&title.length>18) {
  129. longTitle = title;
  130. title = title.substr(0, 18) + '...';
  131. }
  132. $('.photo[data-id="' + photoID + '"] .overlay h1')
  133. .html(title)
  134. .attr('title', longTitle);
  135. },
  136. star: function(photoID) {
  137. $('.photo[data-id="' + photoID + '"] .iconic-star').remove();
  138. if (album.json.content[photoID].star==1) $('.photo[data-id="' + photoID + '"]').append("<a class='badge iconic-star'>" + build.iconic('star') + "</a>");
  139. },
  140. public: function(photoID) {
  141. $('.photo[data-id="' + photoID + '"] .iconic-share').remove();
  142. if (album.json.content[photoID].public==1) $('.photo[data-id="' + photoID + '"]').append("<a class='badge iconic-share'>" + build.iconic('eye') + "</a>");
  143. },
  144. delete: function(photoID) {
  145. $('.photo[data-id="' + photoID + '"]').css('opacity', 0).animate({
  146. width: 0,
  147. marginLeft: 0
  148. }, 300, function() {
  149. $(this).remove();
  150. // Only when search is not active
  151. if (!visible.albums()) {
  152. album.json.num--;
  153. view.album.num();
  154. view.album.title();
  155. }
  156. });
  157. }
  158. },
  159. description: function() {
  160. $('#infobox .attr_description').html(album.json.description + ' ' + build.editIcon('edit_description_album'));
  161. },
  162. num: function() {
  163. $('#infobox .attr_images').html(album.json.num);
  164. },
  165. public: function() {
  166. if (album.json.public==1) {
  167. $('#button_share_album')
  168. .addClass('active')
  169. .attr('title', 'Share Album');
  170. $('.photo .iconic-share').remove();
  171. if (album.json.init) $('#infobox .attr_visibility').html('Public');
  172. } else {
  173. $('#button_share_album')
  174. .removeClass('active')
  175. .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. }