view.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. clearTimeout($(window).data("timeout"));
  11. if (visible.photo()) {
  12. lychee.imageview.removeClass("full");
  13. lychee.loadingBar.css("opacity", 1);
  14. lychee.header.removeClass("hidden");
  15. if ($("#imageview #image.small").length>0) {
  16. $("#imageview #image").css({
  17. marginTop: -1*($("#imageview #image").height()/2)+20
  18. });
  19. } else {
  20. $("#imageview #image").css({
  21. top: 60,
  22. right: 30,
  23. bottom: 30,
  24. left: 30
  25. });
  26. }
  27. }
  28. },
  29. hide: function() {
  30. if (visible.photo()&&!visible.infobox()&&!visible.contextMenu()&&!visible.message()) {
  31. clearTimeout($(window).data("timeout"));
  32. $(window).data("timeout", setTimeout(function() {
  33. lychee.imageview.addClass("full");
  34. lychee.loadingBar.css("opacity", 0);
  35. lychee.header.addClass("hidden");
  36. if ($("#imageview #image.small").length>0) {
  37. $("#imageview #image").css({
  38. marginTop: -1*($("#imageview #image").height()/2)
  39. });
  40. } else {
  41. $("#imageview #image").css({
  42. top: 0,
  43. right: 0,
  44. bottom: 0,
  45. left: 0
  46. });
  47. }
  48. }, 500));
  49. }
  50. },
  51. mode: function(mode) {
  52. var albumID = album.getID();
  53. switch (mode) {
  54. case "albums":
  55. lychee.header.removeClass("view");
  56. $("#tools_album, #tools_photo").hide();
  57. $("#tools_albums").show();
  58. break;
  59. case "album":
  60. lychee.header.removeClass("view");
  61. $("#tools_albums, #tools_photo").hide();
  62. $("#tools_album").show();
  63. album.json.content === false ? $("#button_archive").hide() : $("#button_archive").show();
  64. if (albumID==="s"||albumID==="f") {
  65. $("#button_info_album, #button_trash_album, #button_share_album").hide();
  66. } else if (albumID==="0") {
  67. $("#button_info_album, #button_share_album").hide();
  68. $("#button_trash_album").show();
  69. } else {
  70. $("#button_info_album, #button_trash_album, #button_share_album").show();
  71. }
  72. break;
  73. case "photo":
  74. lychee.header.addClass("view");
  75. $("#tools_albums, #tools_album").hide();
  76. $("#tools_photo").show();
  77. break;
  78. }
  79. }
  80. },
  81. infobox: {
  82. show: function() {
  83. if (!visible.infobox()) $("body").append("<div id='infobox_overlay' class='fadeIn'></div>");
  84. lychee.infobox.addClass("active");
  85. },
  86. hide: function() {
  87. lychee.animate("#infobox_overlay", "fadeOut");
  88. setTimeout(function() { $("#infobox_overlay").remove() }, 300);
  89. lychee.infobox.removeClass("active");
  90. }
  91. },
  92. albums: {
  93. init: function() {
  94. view.albums.title();
  95. view.albums.content.init();
  96. },
  97. title: function() {
  98. lychee.setTitle("Albums", false);
  99. },
  100. content: {
  101. init: function() {
  102. var smartData = "",
  103. albumsData = "";
  104. /* Smart Albums */
  105. albums.parse(albums.json.unsortedAlbum);
  106. albums.parse(albums.json.publicAlbum);
  107. albums.parse(albums.json.starredAlbum);
  108. if (!lychee.publicMode) smartData = build.divider("Smart Albums") + build.album(albums.json.unsortedAlbum) + build.album(albums.json.starredAlbum) + build.album(albums.json.publicAlbum);
  109. /* Albums */
  110. if (albums.json.content) {
  111. if (!lychee.publicMode) albumsData = build.divider("Albums");
  112. $.each(albums.json.content, function() {
  113. albums.parse(this);
  114. albumsData += build.album(this);
  115. });
  116. }
  117. if (smartData===""&&albumsData==="") $("body").append(build.no_content("picture"));
  118. else lychee.content.html(smartData + albumsData);
  119. $("img[data-type!='svg']").retina();
  120. },
  121. title: function(albumID) {
  122. var prefix = "",
  123. title = albums.json.content[albumID].title;
  124. if (albums.json.content[albumID].password) prefix = "<span class='icon-lock'></span> ";
  125. if (title.length>18) title = title.substr(0, 18) + "...";
  126. $(".album[data-id='" + albumID + "'] .overlay h1").html(prefix + title);
  127. },
  128. delete: function(albumID) {
  129. $(".album[data-id='" + albumID + "']").css("opacity", 0).animate({
  130. width: 0,
  131. marginLeft: 0
  132. }, 300, function() {
  133. $(this).remove();
  134. if (albums.json.num<=0) lychee.animate(".divider:last-of-type", "fadeOut");
  135. });
  136. }
  137. }
  138. },
  139. album: {
  140. init: function() {
  141. album.parse();
  142. view.album.infobox();
  143. view.album.title();
  144. view.album.public();
  145. view.album.content.init();
  146. album.json.init = 1;
  147. },
  148. hide: function() {
  149. view.infobox.hide();
  150. },
  151. title: function(oldTitle) {
  152. if ((visible.album()||!album.json.init)&&!visible.photo()) {
  153. switch (album.getID()) {
  154. case "f":
  155. lychee.setTitle("Starred", false);
  156. break;
  157. case "s":
  158. lychee.setTitle("Public", false);
  159. break;
  160. case "0":
  161. lychee.setTitle("Unsorted", false);
  162. break;
  163. default:
  164. if (album.json.init) $("#infobox .attr_name").html(album.json.title + " " + build.editIcon("edit_title_album"));
  165. lychee.setTitle(album.json.title, true);
  166. break;
  167. }
  168. }
  169. },
  170. description: function() {
  171. $("#infobox .attr_description").html(album.json.description + " " + build.editIcon("edit_description_album"));
  172. },
  173. content: {
  174. init: function() {
  175. var photosData = "";
  176. $.each(album.json.content, function() {
  177. album.parse(this);
  178. photosData += build.photo(this);
  179. });
  180. lychee.content.html(photosData);
  181. $("img[data-type!='svg']").retina();
  182. },
  183. title: function(photoID) {
  184. var title = album.json.content[photoID].title;
  185. if (title.length>18) title = title.substr(0, 18) + "...";
  186. $(".photo[data-id='" + photoID + "'] .overlay h1").html(title);
  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. if (!visible.controls()) 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", "scroll");
  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(oldTitle) {
  275. if (photo.json.init) $("#infobox .attr_name").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. photo: function() {
  307. lychee.imageview.html(build.imageview(photo.json, photo.isSmall(), visible.controls()));
  308. if ((album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto==="")||lychee.viewMode) $("a#next").hide();
  309. if ((album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto==="")||lychee.viewMode) $("a#previous").hide();
  310. },
  311. infobox: function() {
  312. lychee.infobox.html(build.infoboxPhoto(photo.json)).show();
  313. }
  314. }
  315. }