view.js 10 KB

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