123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- /**
- * @name UI View
- * @description Responsible to reflect data changes to the UI.
- * @author Tobias Reich
- * @copyright 2014 by Tobias Reich
- */
- view = {
- header: {
- show: function() {
- var newMargin = -1*($("#imageview #image").height()/2)+20;
- clearTimeout($(window).data("timeout"));
- lychee.imageview.removeClass("full");
- lychee.header.removeClass("hidden");
- lychee.loadingBar.css("opacity", 1);
- if ($("#imageview #image.small").length>0) $("#imageview #image").css('margin-top', newMargin);
- else $("#imageview #image").removeClass('full');
- },
- hide: function(e, delay) {
- var newMargin = -1*($("#imageview #image").height()/2);
- if (delay===undefined) delay = 500;
- if (visible.photo()&&!visible.infobox()&&!visible.contextMenu()&&!visible.message()) {
- clearTimeout($(window).data("timeout"));
- $(window).data("timeout", setTimeout(function() {
- lychee.imageview.addClass("full");
- lychee.header.addClass("hidden");
- lychee.loadingBar.css("opacity", 0);
- if ($("#imageview #image.small").length>0) $("#imageview #image").css('margin-top', newMargin);
- else $("#imageview #image").addClass('full');
- }, delay));
- }
- },
- mode: function(mode) {
- var albumID = album.getID();
- switch (mode) {
- case "albums":
- lychee.header.removeClass("view");
- $("#tools_album, #tools_photo").hide();
- $("#tools_albums").show();
- break;
- case "album":
- lychee.header.removeClass("view");
- $("#tools_albums, #tools_photo").hide();
- $("#tools_album").show();
- album.json.content === false ? $("#button_archive").hide() : $("#button_archive").show();
- if (albumID==="s"||albumID==="f") {
- $("#button_info_album, #button_trash_album, #button_share_album").hide();
- } else if (albumID==="0") {
- $("#button_info_album, #button_share_album").hide();
- $("#button_trash_album").show();
- } else {
- $("#button_info_album, #button_trash_album, #button_share_album").show();
- }
- break;
- case "photo":
- lychee.header.addClass("view");
- $("#tools_albums, #tools_album").hide();
- $("#tools_photo").show();
- break;
- }
- }
- },
- infobox: {
- show: function() {
- if (!visible.infobox()) $("body").append("<div id='infobox_overlay' class='fadeIn'></div>");
- lychee.infobox.addClass("active");
- },
- hide: function() {
- lychee.animate("#infobox_overlay", "fadeOut");
- setTimeout(function() { $("#infobox_overlay").remove() }, 300);
- lychee.infobox.removeClass("active");
- }
- },
- albums: {
- init: function() {
- view.albums.title();
- view.albums.content.init();
- },
- title: function() {
- lychee.setTitle("Albums", false);
- },
- content: {
- init: function() {
- var smartData = "",
- albumsData = "";
- /* Smart Albums */
- albums.parse(albums.json.unsortedAlbum);
- albums.parse(albums.json.publicAlbum);
- albums.parse(albums.json.starredAlbum);
- if (!lychee.publicMode) smartData = build.divider("Smart Albums") + build.album(albums.json.unsortedAlbum) + build.album(albums.json.starredAlbum) + build.album(albums.json.publicAlbum);
- /* Albums */
- if (albums.json.content) {
- if (!lychee.publicMode) albumsData = build.divider("Albums");
- $.each(albums.json.content, function() {
- albums.parse(this);
- albumsData += build.album(this);
- });
- }
- if (smartData===""&&albumsData==="") $("body").append(build.no_content("picture"));
- else lychee.content.html(smartData + albumsData);
- $("img[data-type!='svg']").retina();
- },
- title: function(albumID) {
- var prefix = "",
- longTitle = "",
- title = albums.json.content[albumID].title;
- if (albums.json.content[albumID].password) prefix = "<span class='icon-lock'></span> ";
- if (title.length>18) {
- longTitle = title;
- title = title.substr(0, 18) + "...";
- }
- $(".album[data-id='" + albumID + "'] .overlay h1")
- .html(prefix + title)
- .attr("title", longTitle);
- },
- delete: function(albumID) {
- $(".album[data-id='" + albumID + "']").css("opacity", 0).animate({
- width: 0,
- marginLeft: 0
- }, 300, function() {
- $(this).remove();
- if (albums.json.num<=0) lychee.animate(".divider:last-of-type", "fadeOut");
- });
- }
- }
- },
- album: {
- init: function() {
- album.parse();
- view.album.infobox();
- view.album.title();
- view.album.public();
- view.album.content.init();
- album.json.init = 1;
- },
- hide: function() {
- view.infobox.hide();
- },
- title: function() {
- if ((visible.album()||!album.json.init)&&!visible.photo()) {
- switch (album.getID()) {
- case "f":
- lychee.setTitle("Starred", false);
- break;
- case "s":
- lychee.setTitle("Public", false);
- break;
- case "0":
- lychee.setTitle("Unsorted", false);
- break;
- default:
- if (album.json.init) $("#infobox .attr_title").html(album.json.title + " " + build.editIcon("edit_title_album"));
- lychee.setTitle(album.json.title, true);
- break;
- }
- }
- },
- description: function() {
- $("#infobox .attr_description").html(album.json.description + " " + build.editIcon("edit_description_album"));
- },
- content: {
- init: function() {
- var photosData = "";
- $.each(album.json.content, function() {
- album.parse(this);
- photosData += build.photo(this);
- });
- lychee.content.html(photosData);
- $("img[data-type!='svg']").retina();
- },
- title: function(photoID) {
- var longTitle = "",
- title = album.json.content[photoID].title;
- if (title.length>18) {
- longTitle = title;
- title = title.substr(0, 18) + "...";
- }
- $(".photo[data-id='" + photoID + "'] .overlay h1")
- .html(title)
- .attr("title", longTitle);
- },
- star: function(photoID) {
- $(".photo[data-id='" + photoID + "'] .icon-star").remove();
- if (album.json.content[photoID].star==1) $(".photo[data-id='" + photoID + "']").append("<a class='badge red icon-star'></a>");
- },
- public: function(photoID) {
- $(".photo[data-id='" + photoID + "'] .icon-share").remove();
- if (album.json.content[photoID].public==1) $(".photo[data-id='" + photoID + "']").append("<a class='badge red icon-share'></a>");
- },
- delete: function(photoID) {
- $(".photo[data-id='" + photoID + "']").css("opacity", 0).animate({
- width: 0,
- marginLeft: 0
- }, 300, function() {
- $(this).remove();
- // Only when search is not active
- if (!visible.albums()) {
- album.json.num--;
- view.album.num();
- view.album.title();
- }
- });
- }
- },
- num: function() {
- $("#infobox .attr_images").html(album.json.num);
- },
- public: function() {
- if (album.json.public==1) {
- $("#button_share_album a").addClass("active");
- $("#button_share_album").attr("title", "Share Album");
- $(".photo .icon-share").remove();
- if (album.json.init) $("#infobox .attr_visibility").html("Public");
- } else {
- $("#button_share_album a").removeClass("active");
- $("#button_share_album").attr("title", "Make Public");
- if (album.json.init) $("#infobox .attr_visibility").html("Private");
- }
- },
- password: function() {
- if (album.json.password==1) $("#infobox .attr_password").html("Yes");
- else $("#infobox .attr_password").html("No");
- },
- infobox: function() {
- if ((visible.album()||!album.json.init)&&!visible.photo()) lychee.infobox.html(build.infoboxAlbum(album.json)).show();
- }
- },
- photo: {
- init: function() {
- photo.parse();
- view.photo.infobox();
- view.photo.title();
- view.photo.star();
- view.photo.public();
- view.photo.photo();
- photo.json.init = 1;
- },
- show: function() {
- // Change header
- lychee.content.addClass("view");
- view.header.mode("photo");
- // Make body not scrollable
- $("body").css("overflow", "hidden");
- // Fullscreen
- $(document)
- .bind("mouseenter", view.header.show)
- .bind("mouseleave", view.header.hide);
- lychee.animate(lychee.imageview, "fadeIn");
- },
- hide: function() {
- view.header.show();
- if (visible.infobox) view.infobox.hide();
- lychee.content.removeClass("view");
- view.header.mode("album");
- // Make body scrollable
- $("body").css("overflow", "auto");
- // Disable Fullscreen
- $(document)
- .unbind("mouseenter")
- .unbind("mouseleave");
- // Hide Photo
- lychee.animate(lychee.imageview, "fadeOut");
- setTimeout(function() {
- lychee.imageview.hide();
- view.album.infobox();
- }, 300);
- },
- title: function() {
- if (photo.json.init) $("#infobox .attr_title").html(photo.json.title + " " + build.editIcon("edit_title"));
- lychee.setTitle(photo.json.title, true);
- },
- description: function() {
- if (photo.json.init) $("#infobox .attr_description").html(photo.json.description + " " + build.editIcon("edit_description"));
- },
- star: function() {
- $("#button_star a").removeClass("icon-star-empty icon-star");
- if (photo.json.star==1) {
- // Starred
- $("#button_star a").addClass("icon-star");
- $("#button_star").attr("title", "Unstar Photo");
- } else {
- // Unstarred
- $("#button_star a").addClass("icon-star-empty");
- $("#button_star").attr("title", "Star Photo");
- }
- },
- public: function() {
- if (photo.json.public==1||photo.json.public==2) {
- // Photo public
- $("#button_share a").addClass("active");
- $("#button_share").attr("title", "Share Photo");
- if (photo.json.init) $("#infobox .attr_visibility").html("Public");
- } else {
- // Photo private
- $("#button_share a").removeClass("active");
- $("#button_share").attr("title", "Make Public");
- if (photo.json.init) $("#infobox .attr_visibility").html("Private");
- }
- },
- tags: function() {
- $("#infobox #tags").html(build.tags(photo.json.tags));
- },
- photo: function() {
- lychee.imageview.html(build.imageview(photo.json, photo.isSmall(), visible.controls()));
- if ((album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto==="")||lychee.viewMode) $("a#next").hide();
- if ((album.json&&album.json.content&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto==="")||lychee.viewMode) $("a#previous").hide();
- },
- infobox: function() {
- lychee.infobox.html(build.infoboxPhoto(photo.json)).show();
- }
- }
- };
|