view.js 10 KB

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