/** * @name photos.js * @author Philipp Maurer * @author Tobias Reich * @copyright 2013 by Philipp Maurer, Tobias Reich * * Photos Module * Takes care of every action photos can handle and execute. */ photos = { load: function(albumID, refresh) { // If refresh is true the function will only refresh the content and not change the toolbar buttons either the title /*password = localStorage.getItem("album" + albumID); if (password==null) { if (lychee.publicMode) password = prompt("Please enter a password for this album:", ""); else password = ""; if (password!="") password = hex_md5(password); localStorage.setItem("album" + albumID, password); }*/ password = ""; if (!refresh) { loadingBar.show(); if (visible.imageview()) photos.hideView(); lychee.animate(".album, .photo", "contentZoomOut"); lychee.animate(".divider", "fadeOut"); } startTime = new Date().getTime(); params = "getPhotos&albumID=" + albumID + "&password=" + password; lychee.api(params, "json", function(data) { if (data=="HTTP/1.1 403 Wrong password!") { localStorage.removeItem("album" + albumID); photos.load(albumID, refresh); return false; } durationTime = (new Date().getTime() - startTime); if (durationTime>300) waitTime = 0; else if (refresh) waitTime = 0; else waitTime = 300 - durationTime; $.timer(waitTime,function(){ photosData = ""; $.each(data, function() { photosData += build.photo(this); }); lychee.content.html(photosData); if (!refresh) { lychee.animate(".album, .photo", "contentZoomIn"); $("#tools_albums, #tools_photo").hide(); $("#tools_album").show(); $("img").retina(); albums.loadInfo(albumID, password); } }, false); }); }, loadInfo: function(photoID, albumID) { /*password = localStorage.getItem("album" + albumID); if (password==null) { if (lychee.publicMode) password = prompt("Please enter a password for this album:", ""); else password = ""; if (password!="") password = hex_md5(password); localStorage.setItem("album" + albumID, password); }*/ password = ""; photos.showView(); params = "getPhotoInfo&photoID=" + photoID + "&password=" + password; lychee.api(params, "json", function(data) { if (data=="HTTP/1.1 403 Wrong password!") { localStorage.removeItem("album" + albumID); photos.loadInfo(photoID, albumID); return false; } if (!data.title) data.title = "Untitled"; document.title = "Lychee - " + data.title; lychee.headerTitle.html(data.title).addClass("editable"); $("#button_star a").removeClass("icon-star-empty icon-star"); if (data.star=="1") { $("#button_star a").addClass("icon-star"); $("#button_star").attr("title", "Unstar Photo"); } else { $("#button_star a").addClass("icon-star-empty"); $("#button_star").attr("title", "Star Photo"); } if (data.public=="1") { $("#button_share a").addClass("active"); $("#button_share").attr("title", "Share Photo"); } else { $("#button_share a").removeClass("active"); $("#button_share").attr("title", "Make Public"); } data.url = lychee.upload_path + data.url; if (visible.controls()&&photos.isSmall(data)) lychee.image_view.html("
"); else if (visible.controls()) lychee.image_view.html(""); else if (photos.isSmall(data)) lychee.image_view.html(""); else lychee.image_view.html(""); lychee.animate(image_view, "fadeIn"); lychee.image_view.show(); if (!visible.controls()) lychee.hideControls(); lychee.infobox.html(build.infobox(data)).show(); $.timer(300,function(){ lychee.content.show(); }); }); }, isSmall: function(photo) { size = [ ["width", false], ["height", false] ]; if (photo.width<$(window).width()-60) size["width"] = true; if (photo.height<$(window).height()-100) size["height"] = true; if (size["width"]&&size["height"]) return true; else return false; }, showView: function() { // Change toolbar-buttons $("#tools_albums, #tools_album").hide(); $("#tools_photo").show(); // Make body not scrollable $("body").css("overflow", "hidden"); }, hideView: function() { // Change toolbar-buttons $("#tools_photo, #tools_albums").hide(); $("#tools_album").show(); // Make body scrollable $("body").css("overflow", "scroll"); // Change website title and url by using albums.loadInfo albums.loadInfo(lychee.content.attr("data-id")); // Hide ImageViewer lychee.animate(image_view, "fadeOut"); $.timer(300,function(){ lychee.image_view.hide() }); }, showInfobox: function() { if (!visible.infobox()) $("body").append(""); lychee.infobox.css("right", "0px"); }, hideInfobox: function() { $("#infobox_overlay").remove(); lychee.infobox.css("right", "-320px"); }, hide: function(photoID) { $(".photo[data-id='" + photoID + "']").css("opacity", 0).animate({ width: 0, marginLeft: 0 }, 300, function() { $(this).remove(); if (!visible.imageview()) { imgNum = parseInt($("#title span").html().replace("- ", "").replace(" photos", ""))-1; $("#title span").html(" - " + imgNum + " photos"); } }); }, delete: function(photoID) { params = "deletePhoto&photoID=" + photoID; lychee.api(params, "text", function(data) { if (data) { photos.hide(photoID); lychee.goto("a" + lychee.content.attr("data-id")); } else loadingBar.show("error"); }); }, deleteDialog: function(photoID) { if (!photoID) photoID = lychee.image_view.attr("data-id"); if (visible.imageview()) photoTitle = lychee.title(); else photoTitle = $(".photo[data-id='" + photoID + "'] .overlay h1").html(); if (photoTitle=="") photoTitle = "Untitled"; f1 = "photos.delete(" + photoID + ");"; f2 = ""; modal = build.modal("Delete Photo", "Are you sure you want to delete the photo '" + photoTitle + "'?