view.js 10 KB

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