view.js 10 KB

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