view.js 11 KB

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