view.js 10 KB

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