view.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /**
  2. * @name view.js
  3. * @author Philipp Maurer
  4. * @author Tobias Reich
  5. * @copyright 2013 by Philipp Maurer, Tobias Reich
  6. *
  7. * UI View
  8. * Responsible to reflect data changes to the UI.
  9. */
  10. view = {
  11. header: {
  12. show: function() {
  13. clearTimeout($(window).data("timeout"));
  14. if (visible.photo()) {
  15. lychee.imageview.removeClass("full");
  16. lychee.loadingBar.css("opacity", 1);
  17. lychee.header.css("margin-Top", "0px");
  18. if ($("#imageview #image.small").length>0) {
  19. $("#imageview #image").css({
  20. marginTop: -1*($("#imageview #image").height()/2)+20
  21. });
  22. } else {
  23. $("#imageview #image").css({
  24. top: 70,
  25. right: 30,
  26. bottom: 30,
  27. left: 30
  28. });
  29. }
  30. }
  31. },
  32. hide: function() {
  33. if (visible.photo()&&!visible.infobox()) {
  34. clearTimeout($(window).data("timeout"));
  35. $(window).data("timeout", setTimeout(function() {
  36. lychee.imageview.addClass("full");
  37. lychee.loadingBar.css("opacity", 0);
  38. lychee.header.css("margin-Top", "-45px");
  39. if ($("#imageview #image.small").length>0) {
  40. $("#imageview #image").css({
  41. marginTop: -1*($("#imageview #image").height()/2)
  42. });
  43. } else {
  44. $("#imageview #image").css({
  45. top: 0,
  46. right: 0,
  47. bottom: 0,
  48. left: 0
  49. });
  50. }
  51. }, 500));
  52. }
  53. },
  54. mode: function(mode) {
  55. var albumID;
  56. switch (mode) {
  57. case "albums":
  58. $("#tools_album, #tools_photo").hide();
  59. $("#tools_albums").show();
  60. break;
  61. case "album":
  62. $("#tools_albums, #tools_photo").hide();
  63. $("#tools_album").show();
  64. albumID = album.getID();
  65. if (albumID=="s"||albumID=="f") $("#button_edit_album, #button_trash_album, #button_share_album").hide();
  66. else if (albumID==0) $("#button_edit_album, #button_share_album").hide();
  67. else $("#button_edit_album, #button_trash_album, #button_share_album").show();
  68. break;
  69. case "photo":
  70. $("#tools_albums, #tools_album").hide();
  71. $("#tools_photo").show();
  72. break;
  73. }
  74. }
  75. },
  76. albums: {
  77. init: function() {
  78. view.albums.title();
  79. view.albums.content.init();
  80. },
  81. title: function() {
  82. lychee.setTitle("Albums", null, false);
  83. },
  84. content: {
  85. init: function() {
  86. var smartData = "",
  87. albumsData = "";
  88. /* Smart Albums */
  89. albums.parse(albums.json.unsortedAlbum);
  90. albums.parse(albums.json.publicAlbum);
  91. albums.parse(albums.json.starredAlbum);
  92. if (!lychee.publicMode) smartData = build.divider("Smart Albums") + build.album(albums.json.unsortedAlbum) + build.album(albums.json.starredAlbum) + build.album(albums.json.publicAlbum);
  93. /* Albums */
  94. if (albums.json.content) {
  95. if (!lychee.publicMode) albumsData = build.divider("Albums");
  96. $.each(albums.json.content, function() {
  97. albums.parse(this);
  98. albumsData += build.album(this);
  99. });
  100. }
  101. if (smartData==""&&albumsData=="") $("body").append(build.no_content("picture"));
  102. else lychee.content.html(smartData + albumsData);
  103. $("img").retina();
  104. },
  105. title: function(albumID) {
  106. var prefix = "",
  107. title = albums.json.content[albumID].title;
  108. if (albums.json.content[albumID].password) prefix = "<span class='icon-lock'></span> ";
  109. if (title.length>18) title = title.substr(0, 18) + "...";
  110. $(".album[data-id='" + albumID + "'] .overlay h1").html(prefix + title);
  111. },
  112. delete: function(albumID) {
  113. $(".album[data-id='" + albumID + "']").css("opacity", 0).animate({
  114. width: 0,
  115. marginLeft: 0
  116. }, 300, function() {
  117. $(this).remove();
  118. });
  119. }
  120. }
  121. },
  122. album: {
  123. init: function() {
  124. album.parse();
  125. view.album.title();
  126. view.album.public();
  127. view.album.content.init();
  128. album.json.init = 1;
  129. },
  130. title: function() {
  131. if ((visible.album()||!album.json.init)&&!visible.photo()) {
  132. switch (album.getID()) {
  133. case "f":
  134. lychee.setTitle("Starred", album.json.num, false);
  135. break;
  136. case "s":
  137. lychee.setTitle("Public", album.json.num, false);
  138. break;
  139. case "0":
  140. lychee.setTitle("Unsorted", album.json.num, false);
  141. break;
  142. default:
  143. lychee.setTitle(album.json.title, album.json.num, true);
  144. break;
  145. }
  146. }
  147. },
  148. content: {
  149. init: function() {
  150. var photosData = "";
  151. $.each(album.json.content, function() {
  152. album.parse(this);
  153. photosData += build.photo(this);
  154. });
  155. lychee.content.html(photosData);
  156. $("img").retina();
  157. },
  158. title: function(photoID) {
  159. var title = album.json.content[photoID].title;
  160. if (title.length>18) title = title.substr(0, 18) + "...";
  161. $(".photo[data-id='" + photoID + "'] .overlay h1").html(title);
  162. },
  163. star: function(photoID) {
  164. $(".photo[data-id='" + photoID + "'] .icon-star").remove();
  165. if (album.json.content[photoID].star==1) $(".photo[data-id='" + photoID + "']").append("<a class='badge red icon-star'></a>");
  166. },
  167. public: function(photoID) {
  168. $(".photo[data-id='" + photoID + "'] .icon-share").remove();
  169. if (album.json.content[photoID].public==1) $(".photo[data-id='" + photoID + "']").append("<a class='badge red icon-share'></a>");
  170. },
  171. delete: function(photoID) {
  172. $(".photo[data-id='" + photoID + "']").css("opacity", 0).animate({
  173. width: 0,
  174. marginLeft: 0
  175. }, 300, function() {
  176. $(this).remove();
  177. // Only when search is not active
  178. if (!visible.albums()) {
  179. album.json.num--;
  180. view.album.title();
  181. }
  182. });
  183. }
  184. },
  185. public: function() {
  186. if (album.json.public==1) {
  187. $("#button_share_album a").addClass("active");
  188. $("#button_share_album").attr("title", "Share Album");
  189. $(".photo .icon-share").remove();
  190. } else {
  191. $("#button_share_album a").removeClass("active");
  192. $("#button_share_album").attr("title", "Make Public");
  193. }
  194. }
  195. },
  196. photo: {
  197. init: function() {
  198. photo.parse();
  199. view.photo.infobox();
  200. view.photo.title();
  201. view.photo.star();
  202. view.photo.public();
  203. view.photo.photo();
  204. photo.json.init = 1;
  205. },
  206. show: function() {
  207. view.header.mode("photo");
  208. // Make body not scrollable
  209. $("body").css("overflow", "hidden");
  210. lychee.animate(lychee.imageview, "fadeIn");
  211. },
  212. hide: function() {
  213. if (!visible.controls()) view.header.show();
  214. if (visible.infobox) view.photo.hideInfobox();
  215. view.header.mode("album");
  216. // Make body scrollable
  217. $("body").css("overflow", "scroll");
  218. // Hide Photo
  219. lychee.animate(lychee.imageview, "fadeOut");
  220. setTimeout(function() { lychee.imageview.hide() }, 300);
  221. },
  222. showInfobox: function() {
  223. if (!visible.infobox()) $("body").append("<div id='infobox_overlay'></div>");
  224. lychee.infobox.css("right", "0px");
  225. },
  226. hideInfobox: function() {
  227. $("#infobox_overlay").remove();
  228. lychee.infobox.css("right", "-320px");
  229. },
  230. title: function(oldTitle) {
  231. if (photo.json.init) $("#infobox .attr_name").html($("#infobox .attr_name").html().replace(oldTitle, photo.json.title));
  232. lychee.setTitle(photo.json.title, null, true);
  233. },
  234. description: function(oldDescription) {
  235. if (photo.json.init) $("#infobox .attr_description").html($("#infobox .attr_description").html().replace(oldDescription, photo.json.description));
  236. },
  237. star: function() {
  238. $("#button_star a").removeClass("icon-star-empty icon-star");
  239. if (photo.json.star==1) {
  240. // Starred
  241. $("#button_star a").addClass("icon-star");
  242. $("#button_star").attr("title", "Unstar Photo");
  243. } else {
  244. // Unstarred
  245. $("#button_star a").addClass("icon-star-empty");
  246. $("#button_star").attr("title", "Star Photo");
  247. }
  248. },
  249. public: function() {
  250. if (photo.json.public==1||photo.json.public==2) {
  251. // Photo public
  252. $("#button_share a").addClass("active");
  253. $("#button_share").attr("title", "Share Photo");
  254. if (photo.json.init) $("#infobox .attr_visibility").html("Public");
  255. } else {
  256. // Photo private
  257. $("#button_share a").removeClass("active");
  258. $("#button_share").attr("title", "Make Public");
  259. if (photo.json.init) $("#infobox .attr_visibility").html("Private");
  260. }
  261. },
  262. photo: function() {
  263. if (visible.controls()&&photo.isSmall()) lychee.imageview.html("<a id='previous' class='icon-caret-left'></a><a id='next' class='icon-caret-right'></a><div id='image' class='small' style='background-image: url(" + photo.json.url + "); width: " + photo.json.width + "px; height: " + photo.json.height + "px; margin-top: -" + parseInt(photo.json.height/2-20) + "px; margin-left: -" + photo.json.width/2 + "px;'></div>");
  264. else if (visible.controls()) lychee.imageview.html("<a id='previous' class='icon-caret-left'></a><a id='next' class='icon-caret-right'></a><div id='image' style='background-image: url(" + photo.json.url + ")'></div>");
  265. else if (photo.isSmall()) lychee.imageview.html("<a id='previous' style='left: -50px' class='icon-caret-left'></a><a id='next' style='right: -50px' class='icon-caret-right'></a><div id='image' class='small' style='background-image: url(" + photo.json.url + "); width: " + photo.json.width + "px; height: " + photo.json.height + "px; margin-top: -" + parseInt(photo.json.height/2) + "px; margin-left: -" + photo.json.width/2 + "px;'></div>");
  266. else lychee.imageview.html("<a id='previous' style='left: -50px' class='icon-caret-left'></a><a id='next' style='right: -50px' class='icon-caret-right'></a><div id='image' style='background-image: url(" + photo.json.url + "); top: 0px; right: 0px; bottom: 0px; left: 0px;'></div>");
  267. if (!photo.json.nextPhoto||lychee.viewMode) $("a#next").hide();
  268. if (!photo.json.previousPhoto||lychee.viewMode) $("a#previous").hide();
  269. },
  270. infobox: function() {
  271. lychee.infobox.html(build.infobox(photo.json)).show();
  272. }
  273. }
  274. }