view.js 11 KB

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