You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lychee/js/functions.js

1 line
29 KiB

albums={load:function(){loadingBar.show();lychee.animate(".album, .photo","contentZoomOut");lychee.content.attr("data-search","");lychee.animate(".divider","fadeOut");startTime=(new Date).getTime();lychee.api("getAlbums","json",function(e){durationTime=(new Date).getTime()-startTime;if(durationTime>300)waitTime=0;else waitTime=300-durationTime;$.timer(waitTime,function(){$("#tools_album, #tools_photo").hide();$("#tools_albums").show();unsortedAlbum=new Object;unsortedAlbum.id=0;unsortedAlbum.title="Unsorted";unsortedAlbum.sysdate=e.unsortNum+" photos";unsortedAlbum.unsorted=1;if(e.unsortThumb0)unsortedAlbum.thumb0=lychee.upload_path+e.unsortThumb0;else unsortedAlbum.thumb0="";if(e.unsortThumb1)unsortedAlbum.thumb1=lychee.upload_path+e.unsortThumb1;else unsortedAlbum.thumb1="";if(e.unsortThumb2)unsortedAlbum.thumb2=lychee.upload_path+e.unsortThumb2;else unsortedAlbum.thumb2="";starredAlbum=new Object;starredAlbum.id="f";starredAlbum.title="Starred";starredAlbum.sysdate=e.starredNum+" photos";starredAlbum.star=1;if(e.starredThumb0)starredAlbum.thumb0=lychee.upload_path+e.starredThumb0;else starredAlbum.thumb0="";if(e.starredThumb1)starredAlbum.thumb1=lychee.upload_path+e.starredThumb1;else starredAlbum.thumb1="";if(e.starredThumb2)starredAlbum.thumb2=lychee.upload_path+e.starredThumb2;else starredAlbum.thumb2="";publicAlbum=new Object;publicAlbum.id="s";publicAlbum.title="Public";publicAlbum.sysdate=e.publicNum+" photos";publicAlbum.public=1;if(e.publicThumb0)publicAlbum.thumb0=lychee.upload_path+e.publicThumb0;else publicAlbum.thumb0="";if(e.publicThumb1)publicAlbum.thumb1=lychee.upload_path+e.publicThumb1;else publicAlbum.thumb1="";if(e.publicThumb2)publicAlbum.thumb2=lychee.upload_path+e.publicThumb2;else publicAlbum.thumb2="";smartData=build.divider("Smart Albums")+build.album(unsortedAlbum)+build.album(starredAlbum)+build.album(publicAlbum);if(e.albums){albumsData=build.divider("Albums");$.each(e.album,function(){albumsData+=build.album(this)})}else albumsData="";lychee.content.html(smartData+albumsData);lychee.animate(".album, .photo","contentZoomIn");document.title="Lychee";lychee.headerTitle.html("Albums").removeClass("editable");$("img").retina();loadingBar.hide()})})},loadInfo:function(e){if(e=="f"||e=="s"||e==0){lychee.headerTitle.removeClass("editable");lychee.api("getSmartInfo","json",function(t){switch(e){case"f":document.title="Lychee - Starred";lychee.headerTitle.html("Starred<span> - "+t.starredNum+" photos</span>");$("#button_edit_album, #button_trash_album, .button_divider").hide();break;case"s":document.title="Lychee - Public";lychee.headerTitle.html("Public<span> - "+t.publicNum+" photos</span>");$("#button_edit_album, #button_trash_album, .button_divider").hide();break;case"0":document.title="Lychee - Unsorted";lychee.headerTitle.html("Unsorted<span> - "+t.unsortNum+" photos</span>");$("#button_edit_album").hide();$("#button_trash_album, .button_divider").show();break}loadingBar.hide()})}else{params="getAlbumInfo&albumID="+e;lychee.api(params,"json",function(e){$("#button_edit_album, #button_trash_album, .button_divider").show();if(!e.title)e.title="Untitled";document.title="Lychee - "+e.title;lychee.headerTitle.html(e.title+"<span> - "+e.num+" photos</span>").addClass("editable");loadingBar.hide()})}},add:function(){title=prompt("Please enter a title for this album:","Untitled");lychee.closeModal();if(title.length>2&&title.length<31){loadingBar.show();params="addAlbum&title="+escape(title);lychee.api(params,"text",function(e){if(e)lychee.goto("a"+e);else loadingBar.show("error")})}else if(title.length>0)loadingBar.show("error","Error","Title to short or too long. Please try another one!")},hide:function(e){$(".album[data-id='"+e+"']").css("opacity",0).animate({width:0,marginLeft:0},300,function(){$(this).remove()})},"delete":function(e,t){loadingBar.show();params="deleteAlbum&albumID="+e+"&delAll="+t;lychee.api(params,"text",function(t){if(t){if(visible.albums()){albums.hide(e);loadingBar.hide()}else lychee.goto("")}else loadingBar.show("error")})},deleteDialog:function(e){if(e==0){f1="albums.delete(0, true);";f2="";modal=build.modal("Clear Unsorted","Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!",["Clear Unsorted","Keep Photos"],[f1,f2]);$("body").append(modal)}else{if(visible.albums())albumTitle=$(".album[data-id='"+e+"'] .overlay h1").html();else albumTitle=lychee.title();f1="albums.delete("+e+", true);";f2="albums.delete("+e+", false);";modal=build.modal("Delete Album","Are you sure you want to delete the album '"+albumTitle+"' and all of the photos it contains? This action can't be undone!",["Delete Album and Photos","Keep Photos"],[f1,f2]);$("body").append(modal)}},rename:function(e){if(!e)oldTitle=lychee.title();else oldTitle="";if(!e)e=lychee.content.attr("data-id");newTitle=prompt("Please enter a new title for this album:",oldTitle);if(e!=""&&e!=null&&e&&newTitle.length>2&&newTitle.length<31){loadingBar.show();params="setAlbumTitle&albumID="+e+"&title="+encodeURI(newTitle);lychee.api(params,"text",function(t){if(t){if(visible.albums())$(".album[data-id='"+e+"'] .overlay h1").html(newTitle);else{lychee.headerTitle.html(newTitle+"<span>"+$("#title span").html()+"</span>");document.title="Lychee - "+newTitle}loadingBar.hide()}else loadingBar.show("error")})}else if(newTitle.length>0)loadingBar.show("error","Error","New title to short or too long. Please try another one!")},getArchive:function(){albumID=lychee.content.attr("data-id");if(location.href.indexOf("index.html")>0)link=location.href.replace(location.hash,"").replace("index.html","php/api.php?function=getAlbumArchive&albumID="+albumID);else link=location.href.replace(location.hash,"")+"php/api.php?function=getAlbumArchive&albumID="+albumID;location.href=link}};build={divider:function(e){return"<div class='divider fadeIn'><h1>"+e+"</h1></div>"},album:function(e){if(!e)return"";if(!e.thumb0)e.thumb0="img/no_images.png";if(!e.thumb1)e.thumb1="img/no_images.png";if(!e.thumb2)e.thumb2="img/no_images.png";if(!e.title)e.title="Untitled";if(e.title.length>18)e.title=e.title.substr(0,18)+"...";var t="";t+="<div class='album' data-id='"+e.id+"'>";t+="<img src='"+lychee.upload_path+e.thumb2+"' width='200' height='200' alt='thumb'>";t+="<img src='"+lychee.upload_path+e.thumb1+"' width='200' height='200' alt='thumb'>";t+="<img src='"+lychee.upload_path+e.thumb0+"' width='200' height='200' alt='thumb'>";t+="<div class='overlay'>";t+="<h1>"+e.title+"</h1>";t+="<a>"+e.sysdate+"</a>";t+="</div>";if(e.star=="1")t+="<a class='badge red icon-star'></a>";if(e.public=="1")t+="<a class='badge red icon-rss'></a>";if(e.unsorted=="1")t+="<a class='badge red icon-reorder'></a>";t+="</div>";return t},photo:function(e){if(e=="")return"";if(!e.title)e.title="";if(!e.thumbUrl)e.thumbUrl="img/no_image.png";if(e.title.length>18)e.title=e.title.substr(0,18)+"...";var t="";t+="<div class='photo' data-album-id='"+e.album+"' data-id='"+e.id+"'>";t+="<img src='"+lychee.upload_path+e.thumbUrl+"' width='200' height='200' alt='thumb'>";t+="<div class='overlay'>";t+="<h1>"+e.title+"</h1>";t+="<a>"+e.sysdate+"</a>";t+="</div>";if(e.star=="1")t+="<a class='badge red icon-star'></a>";if(e.public=="1")t+="<a class='badge red icon-rss'></a>";t+="</div>";return t},modal:function(e,t,n,r){var i="";i+="<div class='message_overlay fadeIn'>";i+="<div class='message center'>";i+="<h1>"+e+"</h1>";i+="<a class='close icon-remove-sign'></a>";i+="<p>"+t+"</p>";$.each(n,function(e){if(e==0)i+="<a onclick='message_click("+e+")' class='button active'>"+this+"</a>";else i+="<a onclick='message_click("+e+")' class='button'>"+this+"</a>"});i+="</div>";i+="<script>";i+="function message_click(action) {";i+="switch (action) {";$.each(r,function(e){i+="case "+e+":";i+=this.toString();i+="break;"});i+="} lychee.closeModal(); }";i+="</script>";i+="</div>";return i},addModal:function(){var e="";e+="<div class='message_overlay fadeIn'>";e+="<div class='message center add'>";e+="<h1>Add Album or Photo</h1>";e+="<a class='close icon-remove-sign'></a>";e+="<div id='add_album' class='add_album'>";e+="<div class='icon icon-folder-close'></div>";e+="<a>Add new Album</a>";e+="</div>";e+="<div id='add_photo' class='add_album'>";e+="<div class='icon icon-picture'></div>";e+="<a>Upload new Photo</a>";e+="</div>";e+="</div>";e+="</div>";return e},signInModal:function(){var e="";e+="<div class='message_overlay'>";e+="<div class='message center'>";e+="<h1><a class='icon-lock'></a> Sign in</h1>";e+="<div class='sign_in'>";e+="<input id='username' type='text' name='' value='' placeholder='username'>";e+="<input id='password' type='password' name='' value='' placeholder='password'>";e+="</div>";e+="<div id='version'>Version "+lychee.version+"</div>";e+="<a onclick='lychee.login()' class='button active'>Sign in</a>";e+="</div>";e+="</div>";return e},uploadModal:function(){var e="";e+="<div class='upload_overlay fadeIn'>";e+="<div class='upload_message center'>";e+="<a class='icon-upload'></a>";e+="<div class='progressbar'><div></div></div>";e+="</div>";e+="</div>";return e},contextMenu:function(e){var t="";t+="<div class='contextmenu_bg'></div>";t+="<div class='contextmenu'>";t+="<table>";t+="<tbody>";$.each(e,function(n){if(e[n][1].length!=0){t+="<tr><td onclick='"+e[n][1]+"; contextMenu.close();'>"+e[n][0]+"</td></tr>"}});t+="</tbody>";t+="</table>";t+="</div>";return t},infobox:function(e,t){var n="";n+="<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";n+="<div class='wrapper'>";if(e.public==1)e.public="Public";else e.public="Private";if(t==true)editTitleHTML="";else editTitleHTML=" <div id='edit_title'><a class='icon-pencil'></a></div>";if(t==true)editDescriptionHTML="";else editDescriptionHTML=" <div id='edit_description'><a class='icon-pencil'></a></div>";infos=[["","Basics"],["Name",e.title+editTitleHTML],["Uploaded",e.sysdate],["Description",e.description+editDescriptionHTML],["","Image"],["Size",e.size],["Format",e.type],["Resolution",e.width+" x "+e.height],["","Camera"],["Captured",e.takedate],["Make",e.make],["Type/Model",e.model],["Shutter Speed",e.shutter],["Aperture",e.aperture],["Focal Length",e.focal],["ISO",e.iso],["","Share"],["Privacy",e.public],["Short Link",e.shortlink]];$.each(infos,function(e){if(infos[e][1]==""||infos[e][1]==undefined||infos[e][1]==null)infos[e][1]="-";if(infos[e][0]==""){n+="</table>";n+="<div class='separater'><h1>"+infos[e][1]+"</h1></div>";n+="<table id='infos'>"}else{n+="<tr>";n+="<td>"+infos[e][0]+"</td>";n+="<td class='attr_"+infos[e][0].toLowerCase()+"'>"+infos[e][1]+"</td>";n+="</tr>"}});n+="</table>";n+="<div class='bumper'></div>";n+="</div>";return n}};contextMenu={album:function(e){e.preventDefault();mouse_x=e.pageX;mouse_y=e.pageY;albumID=$(this).attr("data-id");if(albumID=="0"||albumID=="f"||albumID=="s")return false;mouse_y-=$(document).scrollTop();items=[["Rename","albums.rename("+albumID+")"],["Delete","albums.deleteDialog("+albumID+")"]];contextMenu.close();$("body").css("overflow","hidden");$(".album[data-id='"+albumID+"']").addClass("active");$("body").append(build.contextMenu(items));$(".contextmenu").css({top:mouse_y,left:mouse_x})},photo:function(e){e.preventDefault();mouse_x=e.pageX;mouse_y=e.pageY;photoID=$(this).attr("data-id");mouse_y-=$(document).scrollTop();items=[["Rename","photos.rename("+photoID+")"],["Move to Album","contextMenu.move("+photoID+", "+(mouse_x+150)+", "+(mouse_y+$(document).scrollTop())+")"],["Delete","photos.deleteDialog("+photoID+")"]];contextMenu.close();$("body").css("overflow","hidden");$(".photo[data-id='"+photoID+"']").addClass("active");$("body").append(build.contextMenu(items));$(".contextmenu").css({top:mouse_y,left:mouse_x})},move:function(e,t,n){n-=$(document).scrollTop();lychee.api("getAlbums","json",function(r){if(lychee.content.attr("data-id")==0){items=[]}else{items=[["Unsorted","photos.move("+e+", 0)"]]}if(!r.albums){items=[["Create new Album","albums.add()"]]}else{$.each(r.album,function(t){if(this.id!=lychee.content.attr("data-id")){if(!this.title)this.title="Untitled";items[items.length]=new Array(this.title,"photos.move("+e+", "+this.id+")")}else{items[items.length]=new Array("","")}})}contextMenu.close();$("body").css("overflow","hidden");$(".photo[data-id='"+e+"']").addClass("active");$("body").append(build.contextMenu(items));$(".contextmenu").css({top:n,left:t-150})})},share:function(e,t,n){n-=$(document).scrollTop();items=[["<a class='icon-eye-close'></a> Make Private","photos.setPublic()"],["<a class='icon-twitter'></a> Twitter","photos.share(0, "+e+")"],["<a class='icon-facebook'></a> Facebook","photos.share(1, "+e+")"],["<a class='icon-envelope'></a> Mail","photos.share(2, "+e+")"],["<a class='icon-link'></a> Copy Link","photos.share(3, "+e+")"],["<a class='icon-link'></a> Copy Shortlink","photos.share(4, "+e+")"]];contextMenu.close();$("body").css("overflow","hidden");$(".photo[data-id='"+e+"']").addClass("active");$("body").append(build.contextMenu(items));$(".contextmenu").css({top:n,left:t})},close:function(){$(".contextmenu_bg, .contextmenu").remove();$(".photo.active, .album.active").removeClass("active");$("body").css("overflow","scroll")}};loadingBar={show:function(e,t,n){if(!e)e="loading";switch(e){case"error":if(!t||!n){t="Error";n="Whoops, it looks like something went wrong. Please reload the site and try again!"}lychee.loadingBar.removeClass("loading uploading error").addClass(e).html("<h1>"+t+": <span>"+n+"</span></h1>").show().css("height","40px");lychee.header.css("margin-Top","40px");$.timer(3e3,function(){loadingBar.hide()});break;case"loading":clearTimeout(lychee.loadingBar.data("timeout"));lychee.loadingBar.data("timeout",setTimeout(function(){lychee.loadingBar.show().removeClass("loading uploading error").addClass(e);if(visible.controls())lychee.header.css("margin-Top","3px")},1e3));break}},hide:function(){clearTimeout(lychee.loadingBar.data("timeout"));lychee.loadingBar.html("").css("height","3px");if(visible.controls())lychee.header.css("marginTop","0px");$.timer(300,function(){lychee.loadingBar.hide()})}};lychee={init:function(e,t){this.version="1.1";this.api_path=e;this.upload_path=t;this.loadingBar=$("#loading");this.header=$("header");this.headerTitle=$("#title");this.content=$("#content");this.image_view=$("#image_view");this.infobox=$("#infobox")},ready:function(){$("#tools_albums").show();if(!mobileBrowser())$(".tools").tipsy({gravity:"n"});if(window.webkitNotifications){window.webkitNotifications.requestPermission()}lychee.api("loggedIn","text",function(e){if(e!=1){$("body").append(build.signInModal());$("#username").focus();if(localStorage){local_username=localStorage.getItem("username");if(local_username==null)return false;if(local_username.length>1)$("#username").val(local_username);$("#password").focus()}}else if(e){$(window).bind("popstate",lychee.load);lychee.load()}})},api:function(e,t,n){$.ajax({type:"POST",url:lychee.api_path,data:"function="+e,dataType:t,success:n,error:lychee.error})},login:function(){user=$("input#username").val();password=hex_md5($("input#password").val());params="login&user="+user+"&password="+password;lychee.api(params,"text",function(e){if(e){if(localStorage){localStorage.setItem("username",user)}$(window).bind("popstate",lychee.load);lychee.load();lychee.closeModal()}else{$("#password").val("").addClass("error");$(".message .button.active").removeClass("pressed")}})},logout:function(){lychee.api("logout","text",function(e){window.location.reload()})},upload:function(e){pre_progress=0;$(".upload_overlay").remove();$("body").append(build.uploadModal());var t=new FormData;for(var n=0;n<e.length;n++)t.append(n,e[n]);t.append("function","upload");if(lychee.content.attr("data-id")=="")t.append("albumID",0);else t.append("albumID",lychee.content.attr("data-id"));var r=new XMLHttpRequest;r.open("POST",lychee.api_path);r.onload=function(){if(r.status===200){$(".progressbar div").css("width","100%");$(".upload_overlay").removeClass("fadeIn").css("opacity",0);$.timer(300,function(){$(".upload_overlay").remove()});if(window.webkitNotifications&&BrowserDetect.browser=="Safari"){var e=window.webkitNotifications.createNotification("","Upload complete","You can now manage your new photos.");e.show()}if(lychee.content.attr("data-id")=="")lychee.goto("a0");else photos.load(lychee.content.attr("data-id"))}};r.upload.onprogress=function(e){if(e.lengthComputable){var t=e.loaded/e.total*100|0;if(t>pre_progress){$(".progressbar div").css("width",t+"%");pre_progress=t}if(t>=100)$(".progressbar div").css("opacity",.2)}};$("#upload_files").val("");r.send(t)},load:function(){contextMenu.close();hash=document.location.hash.replace("#","");albumID="";photoID="";if(hash.indexOf("a")!=-1)albumID=hash.split("p")[0].replace("a","");else albumID="";if(hash.indexOf("p")!=-1)photoID=hash.split("p")[1];else photoID="";lychee.content.attr("data-id",albumID);lychee.image_view.attr("data-id",photoID);if(albumID&&photoID){if(lychee.content.html()==""||$("#search").val().length!=0){lychee.content.hide();photos.load(albumID,true)}photos.loadInfo(photoID)}else if(albumID){if(visible.infobox)photos.hideInfobox();if(!visible.controls())lychee.showControls();if(visible.imageview())photos.hideView();else photos.load(albumID,false)}else{if(visible.infobox)photos.hideInfobox();if(!visible.controls())lychee.showControls();if(visible.imageview())photos.hideView();albums.load()}},"goto":function(e){document.location.hash=e},title:function(){return lychee.headerTitle.html().replace($("#title span").html(),"").replace("<span></span>","")},showControls:function(){clearTimeout($(window).data("timeout"));if(visible.imageview()){lychee.image_view.removeClass("full");lychee.loadingBar.css("opacity",1);lychee.header.css("margin-Top","0px");if($("#image_view #image.small").length>0){$("#image_view #image").css({marginTop:-1*($("#image_view #image").height()/2)+20})}else{$("#image_view #image").css({top:70,right:30,bottom:30,left:30})}}},hideControls:function(){if(visible.imageview()){clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){lychee.image_view.addClass("full");lychee.loadingBar.css("opacity",0);lychee.header.css("margin-Top","-45px");if($("#image_view #image.small").length>0){$("#image_view #image").css({marginTop:-1*($("#image_view #image").height()/2)})}else{$("#image_view #image").css({top:0,right:0,bottom:0,left:0})}},500))}},closeModal:function(){$(".message_overlay").removeClass("fadeIn").css("opacity",0);$.timer(300,function(){$(".message_overlay").remove()})},animate:function(e,t){animations=[["fadeIn","fadeOut"],["contentZoomIn","contentZoomOut"]];if(!e.jQuery)e=$(e);for(i=0;i<animations.length;i++){for(var n=0;n<animations[i].length;n++){if(animations[i][n]==t){e.removeClass(animations[i][0]+" "+animations[i][1]).addClass(t);return true}}}return false},error:function(e,t,n){console.log(e);console.log(t);console.log(n);loadingBar.show("error",t,n)}};photos={load:function(e,t){if(!t){loadingBar.show();if(visible.imageview())photos.hideView();lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut")}startTime=(new Date).getTime();params="getPhotos&albumID="+e;lychee.api(params,"json",function(n){durationTime=(new Date).getTime()-startTime;if(durationTime>300)waitTime=0;else if(t)waitTime=0;else waitTime=300-durationTime;$.timer(waitTime,function(){photosData="";$.each(n,function(){photosData+=build.photo(this)});lychee.content.html(photosData);if(!t){lychee.animate(".album, .photo","contentZoomIn");$("#tools_albums, #tools_photo").hide();$("#tools_album").show();$("img").retina();albums.loadInfo(e)}})})},loadInfo:function(e){photos.showView();loadingBar.show();params="getPhotoInfo&photoID="+e;lychee.api(params,"json",function(e){if(!e.title)e.title="Untitled";document.title="Lychee - "+e.title;lychee.headerTitle.html(e.title).addClass("editable");$("#button_star a").removeClass("icon-star-empty icon-star");if(e.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(e.public=="1"){$("#button_share a").addClass("active");$("#button_share").attr("title","Make Photo Private")}else{$("#button_share a").removeClass("active");$("#button_share").attr("title","Share Photo")}e.url=lychee.upload_path+e.url;if(visible.controls()&&photos.isSmall(e))lychee.image_view.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("+e.url+"); width: "+e.width+"px; height: "+e.height+"px; margin-top: -"+parseInt(e.height/2-20)+"px; margin-left: -"+e.width/2+"px;'></div>");else if(visible.controls())lychee.image_view.html("<a id='previous' class='icon-caret-left'></a><a id='next' class='icon-caret-right'></a><div id='image' style='background-image: url("+e.url+")'></div>");else if(photos.isSmall(e))lychee.image_view.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("+e.url+"); width: "+e.width+"px; height: "+e.height+"px; margin-top: -"+parseInt(e.height/2)+"px; margin-left: -"+e.width/2+"px;'></div>");else lychee.image_view.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("+e.url+"); top: 0px; right: 0px; bottom: 0px; left: 0px;'></div>");lychee.animate(image_view,"fadeIn");lychee.image_view.show();if(!visible.controls())lychee.hideControls();lychee.infobox.html(build.infobox(e)).show();$.timer(300,function(){lychee.content.show()});loadingBar.hide()})},isSmall:function(e){size=[["width",false],["height",false]];if(e.width<$(window).width()-60)size["width"]=true;if(e.height<$(window).height()-100)size["height"]=true;if(size["width"]&&size["height"])return true;else return false},showView:function(){$("#tools_albums, #tools_album").hide();$("#tools_photo").show();$("body").css("overflow","hidden")},hideView:function(){$("#tools_photo, #tools_albums").hide();$("#tools_album").show();$("body").css("overflow","scroll");albums.loadInfo(lychee.content.attr("data-id"));lychee.animate(image_view,"fadeOut");$.timer(300,function(){lychee.image_view.hide()})},showInfobox:function(){if(!visible.infobox())$("body").append("<div id='infobox_overlay'></div>");lychee.infobox.css("right","0px")},hideInfobox:function(){$("#infobox_overlay").remove();lychee.infobox.css("right","-320px")},hide:function(e){$(".photo[data-id='"+e+"']").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(e){loadingBar.show();params="deletePhoto&photoID="+e;lychee.api(params,"text",function(t){if(t){photos.hide(e);lychee.goto("a"+lychee.content.attr("data-id"));loadingBar.hide()}else loadingBar.show("error")})},deleteDialog:function(e){if(!e)e=lychee.image_view.attr("data-id");if(visible.imageview())photoTitle=lychee.title();else photoTitle=$(".photo[data-id='"+e+"'] .overlay h1").html();if(photoTitle=="")photoTitle="Untitled";f1="photos.delete("+e+");";f2="";modal=build.modal("Delete Photo","Are you sure you want to delete the photo '"+photoTitle+"'?<br>This action can't be undone!",["Delete Photo","Keep Photo"],[f1,f2]);$("body").append(modal)},rename:function(e){if(!e)oldTitle=lychee.title();else oldTitle="";if(!e)e=lychee.image_view.attr("data-id");newTitle=prompt("Please enter a new title for this photo:",oldTitle);if(e!=null&&e&&newTitle.length<31){loadingBar.show();if(newTitle=="")newTitle="Untitled";params="setPhotoTitle&photoID="+e+"&title="+encodeURI(newTitle);lychee.api(params,"text",function(t){if(t){if(visible.imageview()){$("#infobox .attr_name").html($("#infobox .attr_name").html().replace(lychee.title(),newTitle));lychee.headerTitle.html(newTitle);document.title="Lychee - "+newTitle}$(".photo[data-id='"+e+"'] .overlay h1").html(newTitle);loadingBar.hide()}else loadingBar.show("error")})}else if(newTitle.length>0)loadingBar.show("error","Error","New title to short or too long. Please try another one!")},move:function(e,t){if(t>=0){loadingBar.show();params="movePhoto&photoID="+e+"&albumID="+t;lychee.api(params,"text",function(t){if(t){photos.hide(e);lychee.goto("a"+lychee.content.attr("data-id"));loadingBar.hide()}else loadingBar.show("error")})}},setStar:function(){loadingBar.show();photoID=lychee.image_view.attr("data-id");params="setPhotoStar&photoID="+photoID;lychee.api(params,"text",function(e){if(e){if($("#button_star a.icon-star-empty").length){$("#button_star a").removeClass("icon-star-empty icon-star").addClass("icon-star");$("#button_star").attr("title","Unstar Photo")}else{$("#button_star a").removeClass("icon-star-empty icon-star").addClass("icon-star-empty");$("#button_star").attr("title","Star Photo")}photos.load(lychee.content.attr("data-id"),true);loadingBar.hide()}else loadingBar.show("error")})},setPublic:function(e){loadingBar.show();photoID=lychee.image_view.attr("data-id");params="setPhotoPublic&photoID="+photoID+"&url="+photos.getViewLink(photoID);lychee.api(params,"text",function(t){if(t){if($("#button_share a.active").length){$("#button_share a").removeClass("active");$("#button_share").attr("title","Make Private")}else{$("#button_share a").addClass("active");$("#button_share").attr("title","Share Photo");contextMenu.share(photoID,e.pageX,e.pageY)}photos.load(lychee.content.attr("data-id"),true);loadingBar.hide()}else loadingBar.show("error")})},setDescription:function(){description=prompt("Please enter a description for this photo:","");photoID=lychee.image_view.attr("data-id");if(description.length>0&&description.length<160){loadingBar.show();params="setPhotoDescription&photoID="+photoID+"&description="+escape(description);lychee.api(params,"text",function(e){if(e)photos.loadInfo(photoID);else loadingBar.show("error")})}else if(description.length>0)loadingBar.show("error","Error","Description to short or too long. Please try another one!")},share:function(e,t){loadingBar.show();params="sharePhoto&photoID="+t+"&url="+photos.getViewLink(t);lychee.api(params,"json",function(n){switch(e){case 0:link=n.twitter;break;case 1:link=n.facebook;break;case 2:link=n.mail;break;case 3:link="copy";modal=build.modal("Copy Link","You can use this link to share your image with other people: <input class='copylink' value='"+photos.getViewLink(t)+"'>",["Close"],[""]);$("body").append(modal);$(".copylink").focus();break;case 4:link="copy";modal=build.modal("Copy Shortlink","You can use this link to share your image with other people: <input class='copylink' value='"+n.shortlink+"'>",["Close"],[""]);$("body").append(modal);$(".copylink").focus();break;default:link="";break}if(link=="copy")loadingBar.hide();else if(link.length>5){location.href=link;loadingBar.hide()}else loadingBar.show("error")})},getViewLink:function(e){if(location.href.indexOf("index.html")>0)return location.href.replace("index.html"+location.hash,"view.php?p="+e);else return location.href.replace(location.hash,"view.php?p="+e)},previous:function(){albumID=lychee.content.attr("data-id");photoID=lychee.image_view.attr("data-id");params="previousPhoto&photoID="+photoID+"&albumID="+albumID;lychee.api(params,"json",function(e){if(e!=false)lychee.goto("a"+albumID+"p"+e.id)})},next:function(){albumID=lychee.content.attr("data-id");photoID=lychee.image_view.attr("data-id");params="nextPhoto&photoID="+photoID+"&albumID="+albumID;lychee.api(params,"json",function(e){if(e)lychee.goto("a"+albumID+"p"+e.id)})}};search={find:function(e){clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){if($("#search").val().length!=0){params="search&term="+e;lychee.api(params,"json",function(e){albumsData="";if(e&&e.albums)$.each(e.albums,function(){albumsData+=build.album(this)});photosData="";if(e&&e.photos)$.each(e.photos,function(){photosData+=build.photo(this)});if(albumsData==""&&photosData=="")code="";else if(albumsData=="")code=build.divider("Photos")+photosData;else if(photosData=="")code=build.divider("Albums")+albumsData;else code=build.divider("Photos")+photosData+build.divider("Albums")+albumsData;if(lychee.content.attr("data-search")!=code){lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut");$.timer(300,function(){lychee.content.attr("data-search",code);lychee.content.html(code);lychee.animate(".album, .photo","contentZoomIn")})}})}else search.reset()},250))},reset:function(){$("#search").val("");if(lychee.content.attr("data-search")!=""){lychee.content.attr("data-search","");lychee.animate(".divider","fadeOut");albums.load()}}};visible={albums:function(){if($("#tools_albums").css("display")=="block")return true;else return false},imageview:function(){if($("#image_view.fadeIn").length>0)return true;else return false},infobox:function(){if(parseInt(lychee.infobox.css("right").replace("px",""))==-320)return false;else return true},controls:function(){if(lychee.loadingBar.css("opacity")>0)return true;else return false}}