album={json:null,getID:function(){var id;if(photo.json)id=photo.json.album;else if(album.json)id=album.json.id;else id=$(".album:hover, .album.active").attr("data-id");if(!id)id=$(".photo:hover, .photo.active").attr("data-album-id");if(id)return id;else return false},load:function(albumID,refresh){var startTime,params,durationTime,waitTime;password.get(albumID,function(){if(!refresh){loadingBar.show();lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut")}startTime=(new Date).getTime();params="getAlbum&albumID="+albumID+"&password="+password.value;lychee.api(params,function(data){if(data==="Warning: Album private!"){lychee.setMode("view");return false}if(data==="Warning: Wrong password!"){album.load(albumID,refresh);return false}album.json=data;durationTime=(new Date).getTime()-startTime;if(durationTime>300)waitTime=0;else if(refresh)waitTime=0;else waitTime=300-durationTime;if(!visible.albums()&&!visible.photo()&&!visible.album())waitTime=0;setTimeout(function(){view.album.init();if(!refresh){lychee.animate(".album, .photo","contentZoomIn");view.header.mode("album")}},waitTime)})})},parse:function(photo){if(photo&&photo.thumbUrl)photo.thumbUrl=lychee.upload_path_thumb+photo.thumbUrl;else if(!album.json.title)album.json.title="Untitled"},add:function(){var title,params,buttons;buttons=[["Create Album",function(){title=$(".message input.text").val();if(title==="")title="Untitled";if(title.length>0&&title.length<31){modal.close();params="addAlbum&title="+escape(encodeURI(title));lychee.api(params,function(data){if(data!==false)lychee.goto(data);else lychee.error(null,params,data)})}else loadingBar.show("error","Title too short or too long. Please try again!")}],["Cancel",function(){}]];modal.show("New Album","Please enter a title for this album: ",buttons)},"delete":function(albumID){var params,buttons,albumTitle;buttons=[["Delete Album and Photos",function(){params="deleteAlbum&albumID="+albumID;lychee.api(params,function(data){if(visible.albums()){albums.json.num--;view.albums.content.delete(albumID)}else lychee.goto("");if(data!==true)lychee.error(null,params,data)})}],["Keep Album",function(){}]];if(albumID==="0"){buttons[0][0]="Clear Unsorted";modal.show("Clear Unsorted","Are you sure you want to delete all photos from 'Unsorted'? This action can't be undone!",buttons)}else{if(album.json)albumTitle=album.json.title;else if(albums.json)albumTitle=albums.json.content[albumID].title;modal.show("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!",buttons)}},setTitle:function(albumID){var oldTitle="",newTitle,params,buttons;if(!albumID)return false;if(album.json)oldTitle=album.json.title;else if(albums.json)oldTitle=albums.json.content[albumID].title;buttons=[["Set Title",function(){newTitle=$(".message input.text").val();if(newTitle==="")newTitle="Untitled";if(albumID!==""&&albumID!=null&&albumID&&newTitle.length<31){if(visible.album()){album.json.title=newTitle;view.album.title(oldTitle)}else if(visible.albums()){albums.json.content[albumID].title=newTitle;view.albums.content.title(albumID)}params="setAlbumTitle&albumID="+albumID+"&title="+escape(encodeURI(newTitle));lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}else if(newTitle.length>0)loadingBar.show("error","New title too short or too long. Please try again!")}],["Cancel",function(){}]];modal.show("Set Title","Please enter a new title for this album: ",buttons)},setDescription:function(photoID){var oldDescription=album.json.description,description,params,buttons;buttons=[["Set Description",function(){description=$(".message input.text").val();if(description.length<800){if(visible.album()){album.json.description=description;view.album.description()}params="setAlbumDescription&albumID="+photoID+"&description="+escape(description);lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}else loadingBar.show("error","Description too long. Please try again!")}],["Cancel",function(){}]];modal.show("Set Description","Please enter a description for this album: ",buttons)},setPublic:function(albumID,e){var params;if($(".message input.text").length>0&&$(".message input.text").val().length>0){params="setAlbumPublic&albumID="+albumID+"&password="+hex_md5($(".message input.text").val());album.json.password=true}else{params="setAlbumPublic&albumID="+albumID;album.json.password=false}if(visible.album()){album.json.public=album.json.public==0?1:0;view.album.public();view.album.password();if(album.json.public==1)contextMenu.shareAlbum(albumID,e)}lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})},share:function(service){var link="",url=location.href;switch(service){case 0:link="https://twitter.com/share?url="+encodeURI(url);break;case 1:link="http://www.facebook.com/sharer.php?u="+encodeURI(url)+"&t="+encodeURI(album.json.title);break;case 2:link="mailto:?subject="+encodeURI(album.json.title)+"&body="+encodeURI("Hi! Check this out: "+url);break;default:link="";break}if(link.length>5)location.href=link},getArchive:function(albumID){var link;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;if(lychee.publicMode)link+="&password="+password.value;location.href=link}};albums={json:null,load:function(){var startTime,durationTime,waitTime;lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut");startTime=(new Date).getTime();lychee.api("getAlbums",function(data){data.unsortedAlbum={id:0,title:"Unsorted",sysdate:data.unsortedNum+" photos",unsorted:1,thumb0:data.unsortedThumb0,thumb1:data.unsortedThumb1,thumb2:data.unsortedThumb2};data.starredAlbum={id:"f",title:"Starred",sysdate:data.starredNum+" photos",star:1,thumb0:data.starredThumb0,thumb1:data.starredThumb1,thumb2:data.starredThumb2};data.publicAlbum={id:"s",title:"Public",sysdate:data.publicNum+" photos","public":1,thumb0:data.publicThumb0,thumb1:data.publicThumb1,thumb2:data.publicThumb2};albums.json=data;durationTime=(new Date).getTime()-startTime;if(durationTime>300)waitTime=0;else waitTime=300-durationTime;if(!visible.albums()&&!visible.photo()&&!visible.album())waitTime=0;setTimeout(function(){view.header.mode("albums");view.albums.init();lychee.animate(".album, .photo","contentZoomIn")},waitTime)})},parse:function(album){if(album.password&&lychee.publicMode){album.thumb0="assets/img/password.svg";album.thumb1="assets/img/password.svg";album.thumb2="assets/img/password.svg"}else{if(album.thumb0)album.thumb0=lychee.upload_path_thumb+album.thumb0;else album.thumb0="assets/img/no_images.svg";if(album.thumb1)album.thumb1=lychee.upload_path_thumb+album.thumb1;else album.thumb1="assets/img/no_images.svg";if(album.thumb2)album.thumb2=lychee.upload_path_thumb+album.thumb2;else album.thumb2="assets/img/no_images.svg"}}};build={divider:function(title){return"
";return infobox}};contextMenu={fns:null,show:function(items,mouse_x,mouse_y,orientation){if(visible.contextMenu())contextMenu.close();$("body").css("overflow","hidden").append(build.contextMenu(items));if(mouse_x+$(".contextmenu").outerWidth(true)>$("html").width())orientation="left";if(mouse_y+$(".contextmenu").outerHeight(true)>$("html").height())mouse_y-=mouse_y+$(".contextmenu").outerHeight(true)-$("html").height();if(orientation==="left")mouse_x-=$(".contextmenu").outerWidth(true);if(!mouse_x||!mouse_y){mouse_x="10px";mouse_y="10px"}$(".contextmenu").css({top:mouse_y,left:mouse_x,opacity:.98})},add:function(e){var mouse_x=e.pageX,mouse_y=e.pageY,items;mouse_y-=$(document).scrollTop();contextMenu.fns=[function(){$("#upload_files").click()},function(){upload.start.url()},function(){upload.start.dropbox()},function(){upload.start.server()},function(){album.add()}];items=[[" Upload Photo",0],["separator",-1],[" Import from Link",1],[" Import from Dropbox",2],[" Import from Server",3],["separator",-1],[" New Album",4]];contextMenu.show(items,mouse_x,mouse_y,"left")},settings:function(e){var mouse_x=e.pageX,mouse_y=e.pageY,items;mouse_y-=$(document).scrollTop();contextMenu.fns=[function(){settings.setLogin()},function(){settings.setSorting()},function(){window.open(lychee.website,"_newtab")},function(){lychee.logout()}];items=[[" Change Login",0],[" Change Sorting",1],[" About Lychee",2],["separator",-1],[" Sign Out",3]];contextMenu.show(items,mouse_x,mouse_y,"right")},album:function(albumID,e){var mouse_x=e.pageX,mouse_y=e.pageY,items;if(albumID==="0"||albumID==="f"||albumID==="s")return false;mouse_y-=$(document).scrollTop();contextMenu.fns=[function(){album.setTitle(albumID)},function(){album.delete(albumID)}];items=[[" Rename",0],[" Delete",1]];contextMenu.show(items,mouse_x,mouse_y,"right");$(".album[data-id='"+albumID+"']").addClass("active")},photo:function(photoID,e){var mouse_x=e.pageX,mouse_y=e.pageY,items;mouse_y-=$(document).scrollTop();contextMenu.fns=[function(){photo.setStar(photoID)},function(){photo.setTitle(photoID)},function(){contextMenu.move(photoID,e,"right")},function(){photo.delete(photoID)}];items=[[" Star",0],["separator",-1],[" Rename",1],[" Move",2],[" Delete",3]];contextMenu.show(items,mouse_x,mouse_y,"right");$(".photo[data-id='"+photoID+"']").addClass("active")},move:function(photoID,e,orientation){var mouse_x=e.pageX,mouse_y=e.pageY,items=[];contextMenu.fns=[];if(album.getID()!=="0"){items=[["Unsorted",0,"photo.setAlbum(0, "+photoID+")"],["separator",-1]]}lychee.api("getAlbums",function(data){if(!data.albums){items=[["New Album",0,"album.add()"]]}else{$.each(data.content,function(index){if(this.id!=album.getID())items.push([this.title,0,"photo.setAlbum("+this.id+", "+photoID+")"])})}contextMenu.close();$(".photo[data-id='"+photoID+"']").addClass("active");if(!visible.photo())contextMenu.show(items,mouse_x,mouse_y,"right");else contextMenu.show(items,mouse_x,mouse_y,"left")})},sharePhoto:function(photoID,e){var mouse_x=e.pageX,mouse_y=e.pageY,items;mouse_y-=$(document).scrollTop();contextMenu.fns=[function(){photo.setPublic(photoID)},function(){photo.share(photoID,0)},function(){photo.share(photoID,1)},function(){photo.share(photoID,2)},function(){photo.share(photoID,3)},function(){window.open(photo.getDirectLink(),"_newtab")}];link=photo.getViewLink(photoID);if(photo.json.public==="2")link=location.href;items=[["",-1],["separator",-1],[" Make Private",0],["separator",-1],[" Twitter",1],[" Facebook",2],[" Mail",3],[" Dropbox",4],[" Direct Link",5]];contextMenu.show(items,mouse_x,mouse_y,"left");$(".contextmenu input").focus()},shareAlbum:function(albumID,e){var mouse_x=e.pageX,mouse_y=e.pageY,items;mouse_y-=$(document).scrollTop();contextMenu.fns=[function(){album.setPublic(albumID)},function(){password.set(albumID)},function(){album.share(0)},function(){album.share(1)},function(){album.share(2)},function(){password.remove(albumID)}];items=[["",-1],["separator",-1],[" Make Private",0],[" Set Password",1],["separator",-1],[" Twitter",2],[" Facebook",3],[" Mail",4]];if(album.json.password==true)items[3]=[" Remove Password",5];contextMenu.show(items,mouse_x,mouse_y,"left");$(".contextmenu input").focus()},close:function(){contextMenu.js=null;$(".contextmenu_bg, .contextmenu").remove();$(".photo.active, .album.active").removeClass("active");$("body").css("overflow","scroll")}};$(document).ready(function(){var event_name=mobileBrowser()?"touchend":"click";if(window.webkitNotifications)window.webkitNotifications.requestPermission();$(document).bind("contextmenu",function(e){e.preventDefault()});if(!mobileBrowser())$(".tools").tipsy({gravity:"n",fade:false,delayIn:0,opacity:1});$("#hostedwith").on(event_name,function(){window.open(lychee.website,"_newtab")});$("#button_signin").on(event_name,lychee.loginDialog);$("#button_settings").on(event_name,contextMenu.settings);$("#button_share").on(event_name,function(e){if(photo.json.public==1||photo.json.public==2)contextMenu.sharePhoto(photo.getID(),e);else photo.setPublic(photo.getID(),e)});$("#button_share_album").on(event_name,function(e){if(album.json.public==1)contextMenu.shareAlbum(album.getID(),e);else modal.show("Share Album","All photos inside this album will be public and visible for everyone. Existing public photos will have the same sharing permission as this album. Are your sure you want to share this album? ",[["Share Album",function(){album.setPublic(album.getID(),e)}],["Cancel",function(){}]])});$("#button_download").on(event_name,function(){photo.getArchive(photo.getID())});$("#button_trash_album").on(event_name,function(){album.delete(album.getID())});$("#button_move").on(event_name,function(e){contextMenu.move(photo.getID(),e)});$("#button_trash").on(event_name,function(){photo.delete(photo.getID())});$("#button_info_album").on(event_name,function(){view.infobox.show()});$("#button_info").on(event_name,function(){view.infobox.show()});$("#button_archive").on(event_name,function(){album.getArchive(album.getID())});$("#button_star").on(event_name,function(){photo.setStar(photo.getID())});$("#search").on("keyup click",function(){search.find($(this).val())});$("#button_back_home").on(event_name,function(){lychee.goto("")});$("#button_back").on(event_name,function(){lychee.goto(album.getID())});lychee.imageview.on(event_name,".arrow_wrapper.previous",function(){if(album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].previousPhoto!=="")lychee.goto(album.getID()+"/"+album.json.content[photo.getID()].previousPhoto)}).on(event_name,".arrow_wrapper.next",function(){if(album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto!=="")lychee.goto(album.getID()+"/"+album.json.content[photo.getID()].nextPhoto)});$("#infobox").on(event_name,".header a",function(){view.infobox.hide()}).on(event_name,"#edit_title_album",function(){album.setTitle(album.getID())}).on(event_name,"#edit_description_album",function(){album.setDescription(album.getID())}).on(event_name,"#edit_title",function(){photo.setTitle(photo.getID())}).on(event_name,"#edit_description",function(){photo.setDescription(photo.getID())});Mousetrap.bind("u",function(){$("#upload_files").click()}).bind("s",function(){if(visible.photo())$("#button_star").click()}).bind("command+backspace",function(){if(visible.photo()&&!visible.message())photo.delete(photo.getID())}).bind("left",function(){if(visible.photo())$("#imageview a#previous").click()}).bind("right",function(){if(visible.photo())$("#imageview a#next").click()}).bind("i",function(){if(visible.infobox())view.infobox.hide();else if(!visible.albums())view.infobox.show()});Mousetrap.bindGlobal("enter",function(){if($(".message .button.active").length)$(".message .button.active").addClass("pressed").click()});Mousetrap.bindGlobal(["esc","command+up"],function(e){e.preventDefault();if(visible.message()&&$(".message .close").length>0)modal.close();else if(visible.contextMenu())contextMenu.close();else if(visible.infobox())view.infobox.hide();else if(visible.photo())lychee.goto(album.getID());else if(visible.album())lychee.goto("");else if(visible.albums()&&$("#search").val().length!==0)search.reset()});$(document).on("keyup","#password",function(){if($(this).val().length>0)$(this).removeClass("error")}).on(event_name,"#title.editable",function(){if(visible.photo())photo.setTitle(photo.getID());else album.setTitle(album.getID())}).on("click",".album",function(){lychee.goto($(this).attr("data-id"))}).on("click",".photo",function(){lychee.goto(album.getID()+"/"+$(this).attr("data-id"))}).on(event_name,".message .close",modal.close).on(event_name,".message .button:first",function(){if(modal.fns!=null)modal.fns[0]();if(!visible.signin())modal.close()}).on(event_name,".message .button:last",function(){if(modal.fns!=null)modal.fns[1]();if(!visible.signin())modal.close()}).on(event_name,".button_add",function(e){contextMenu.add(e)}).on("change","#upload_files",function(){modal.close();upload.start.local(this.files)}).on("contextmenu",".photo",function(e){contextMenu.photo(photo.getID(),e)}).on("contextmenu",".album",function(e){contextMenu.album(album.getID(),e)}).on(event_name,".contextmenu_bg",contextMenu.close).on("contextmenu",".contextmenu_bg",contextMenu.close).on(event_name,"#infobox_overlay",view.infobox.hide).on("dragover",function(e){e.preventDefault()},false).on("drop",function(e){e.stopPropagation();e.preventDefault();if(e.originalEvent.dataTransfer.files.length>0)upload.start.local(e.originalEvent.dataTransfer.files);else if(e.originalEvent.dataTransfer.getData("Text").length>3)upload.start.url(e.originalEvent.dataTransfer.getData("Text"));return true});lychee.init()});loadingBar={status:null,show:function(status,errorText){if(status==="error"){loadingBar.status="error";if(!errorText)errorText="Whoops, it looks like something went wrong. Please reload the site and try again!";lychee.loadingBar.removeClass("loading uploading error").addClass(status).html("
Error: "+errorText+"
").show().css("height","40px");if(visible.controls())lychee.header.addClass("error");clearTimeout(lychee.loadingBar.data("timeout"));lychee.loadingBar.data("timeout",setTimeout(function(){loadingBar.hide(true)},3e3))}else if(loadingBar.status==null){loadingBar.status="loading";clearTimeout(lychee.loadingBar.data("timeout"));lychee.loadingBar.data("timeout",setTimeout(function(){lychee.loadingBar.show().removeClass("loading uploading error").addClass("loading");if(visible.controls())lychee.header.addClass("loading")},1e3))}},hide:function(force_hide){if(loadingBar.status!=="error"&&loadingBar.status!=null||force_hide){loadingBar.status=null;clearTimeout(lychee.loadingBar.data("timeout"));lychee.loadingBar.html("").css("height","3px");if(visible.controls())lychee.header.removeClass("error loading");setTimeout(function(){lychee.loadingBar.hide()},300)}}};var lychee={version:"2.0.1",api_path:"php/api.php",update_path:"http://lychee.electerious.com/version/index.php",updateURL:"https://github.com/electerious/Lychee",website:"http://lychee.electerious.com",upload_path_thumb:"uploads/thumb/",upload_path_big:"uploads/big/",publicMode:false,viewMode:false,debugMode:false,username:"",checkForUpdates:false,sorting:"",dropbox:false,loadingBar:$("#loading"),header:$("header"),content:$("#content"),imageview:$("#imageview"),infobox:$("#infobox"),init:function(){lychee.api("init",function(data){if(data.loggedIn!==true){lychee.setMode("public")}else{lychee.username=data.config.username;lychee.sorting=data.config.sorting}if(data==="Warning: No configuration!"){lychee.header.hide();lychee.content.hide();$("body").append(build.no_content("cog"));settings.createConfig();return true}if(data.config.login===false){settings.createLogin()}lychee.checkForUpdates=data.config.checkForUpdates;$(window).bind("popstate",lychee.load);lychee.load()})},api:function(params,callback,loading){if(loading==undefined)loadingBar.show();$.ajax({type:"POST",url:lychee.api_path,data:"function="+params,dataType:"text",success:function(data){setTimeout(function(){loadingBar.hide()},100);if(typeof data==="string"&&data.substring(0,7)==="Error: "){lychee.error(data.substring(7,data.length),params,data);return false}if(data==="1")data=true;else if(data==="")data=false;if(typeof data==="string"&&data.substring(0,1)==="{"&&data.substring(data.length-1,data.length)==="}")data=$.parseJSON(data);if(lychee.debugMode)console.log(data);callback(data)},error:function(jqXHR,textStatus,errorThrown){lychee.error("Server error or API not found.",params,errorThrown)}})},login:function(){var user=$("input#username").val(),password=hex_md5($("input#password").val()),params;params="login&user="+user+"&password="+password;lychee.api(params,function(data){if(data===true){localStorage.setItem("username",user);window.location.reload()}else{$("#password").val("").addClass("error");$(".message .button.active").removeClass("pressed")}})},loginDialog:function(){var local_username;$("body").append(build.signInModal());$("#username").focus();if(localStorage){local_username=localStorage.getItem("username");if(local_username!=null){if(local_username.length>0)$("#username").val(local_username);$("#password").focus()}}if(lychee.checkForUpdates==="1")lychee.getUpdate()},logout:function(){lychee.api("logout",function(data){window.location.reload()})},"goto":function(url){if(url==undefined)url="";document.location.hash=url},load:function(){var albumID="",photoID="",hash=document.location.hash.replace("#","").split("/");contextMenu.close();if(hash[0]!==undefined)albumID=hash[0];if(hash[1]!==undefined)photoID=hash[1];if(albumID&&photoID){albums.json=null;photo.json=null;if(lychee.content.html()===""||$("#search").length&&$("#search").val().length!==0){lychee.content.hide();album.load(albumID,true)}photo.load(photoID,albumID)}else if(albumID){albums.json=null;photo.json=null;if(visible.photo())view.photo.hide();if(album.json&&albumID==album.json.id)view.album.title();else album.load(albumID)}else{albums.json=null;album.json=null;photo.json=null;search.code="";if(visible.album())view.album.hide();if(visible.photo())view.photo.hide();albums.load()}},getUpdate:function(){$.ajax({url:lychee.update_path,success:function(data){if(data!=lychee.version)$("#version span").show()}})},setTitle:function(title,editable){if(title==="Albums")document.title="Lychee";else document.title="Lychee - "+title;if(editable)$("#title").addClass("editable");else $("#title").removeClass("editable");$("#title").html(title)},setMode:function(mode){$("#button_settings, #button_settings, #button_search, #search, #button_trash_album, #button_share_album, .button_add, .button_divider").remove();
$("#button_trash, #button_move, #button_share, #button_star").remove();$(document).on("mouseenter","#title.editable",function(){$(this).removeClass("editable")}).off("click","#title.editable").off("touchend","#title.editable").off("contextmenu",".photo").off("contextmenu",".album").off("drop");Mousetrap.unbind("n").unbind("u").unbind("s").unbind("backspace");if(mode==="public"){$("header #button_signin, header #hostedwith").show();lychee.publicMode=true}else if(mode==="view"){Mousetrap.unbind("esc");$("#button_back, a#next, a#previous").remove();lychee.publicMode=true;lychee.viewMode=true}},animate:function(obj,animation){var animations=[["fadeIn","fadeOut"],["contentZoomIn","contentZoomOut"]];if(!obj.jQuery)obj=$(obj);for(var i=0;i",buttons)},get:function(albumID,callback){var passwd=$(".message input.text").val(),params;if(!lychee.publicMode)callback();else if(album.json&&album.json.password==false)callback();else if(albums.json&&albums.json.content[albumID].password==false)callback();else if(!albums.json&&!album.json){album.json={password:true};callback("")}else if(passwd==undefined){password.getDialog(albumID,callback)}else{params="checkAlbumAccess&albumID="+albumID+"&password="+hex_md5(passwd);lychee.api(params,function(data){if(data===true){password.value=hex_md5(passwd);callback()}else{lychee.goto("");loadingBar.show("error","Access denied. Wrong password!")}})}},getDialog:function(albumID,callback){var buttons;buttons=[["Enter",function(){password.get(albumID,callback)}],["Cancel",lychee.goto]];modal.show(" Enter Password","This album is protected by a password. Enter the password below to view the photos of this album: ",buttons,-110,false)},remove:function(albumID){var params;if(visible.album()){album.json.password=false;view.album.password()}params="setAlbumPassword&albumID="+albumID+"&password=";lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}};photo={json:null,getID:function(){var id;if(photo.json)id=photo.json.id;else id=$(".photo:hover, .photo.active").attr("data-id");if(id)return id;else return false},load:function(photoID,albumID){var params,checkPasswd;params="getPhoto&photoID="+photoID+"&albumID="+albumID+"&password="+password.value;lychee.api(params,function(data){if(data==="Warning: Wrong password!"){checkPasswd=function(){if(password.value!=="")photo.load(photoID,albumID);else setTimeout(checkPasswd,250)};checkPasswd();return false}photo.json=data;if(!visible.photo())view.photo.show();view.photo.init();lychee.imageview.show();setTimeout(function(){lychee.content.show()},300)})},parse:function(){if(!photo.json.title)photo.json.title="Untitled";photo.json.url=lychee.upload_path_big+photo.json.url},"delete":function(photoID){var params,buttons,photoTitle;if(!photoID)return false;if(visible.photo())photoTitle=photo.json.title;else photoTitle=album.json.content[photoID].title;if(photoTitle=="")photoTitle="Untitled";buttons=[["Delete Photo",function(){if(album.json.content[photoID].nextPhoto!==""||album.json.content[photoID].previousPhoto!==""){nextPhoto=album.json.content[photoID].nextPhoto;previousPhoto=album.json.content[photoID].previousPhoto;album.json.content[previousPhoto].nextPhoto=nextPhoto;album.json.content[nextPhoto].previousPhoto=previousPhoto}album.json.content[photoID]=null;view.album.content.delete(photoID);if(!visible.albums())lychee.goto(album.getID());params="deletePhoto&photoID="+photoID;lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}],["Keep Photo",function(){}]];modal.show("Delete Photo","Are you sure you want to delete the photo '"+photoTitle+"'? This action can't be undone!",buttons)},setTitle:function(photoID){var oldTitle="",newTitle,params,buttons;if(!photoID)return false;if(photo.json)oldTitle=photo.json.title;else if(album.json)oldTitle=album.json.content[photoID].title;buttons=[["Set Title",function(){newTitle=$(".message input.text").val();if(photoID!=null&&photoID&&newTitle.length<31){if(visible.photo()){photo.json.title=newTitle===""?"Untitled":newTitle;view.photo.title(oldTitle)}album.json.content[photoID].title=newTitle;view.album.content.title(photoID);params="setPhotoTitle&photoID="+photoID+"&title="+escape(encodeURI(newTitle));lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}else if(newTitle.length>0)loadingBar.show("error","New title to short or too long. Please try another one!")}],["Cancel",function(){}]];modal.show("Set Title","Please enter a new title for this photo: ",buttons)},setAlbum:function(albumID,photoID){var params;if(albumID>=0){if(album.json.content[photoID].nextPhoto!==""||album.json.content[photoID].previousPhoto!==""){nextPhoto=album.json.content[photoID].nextPhoto;previousPhoto=album.json.content[photoID].previousPhoto;album.json.content[previousPhoto].nextPhoto=nextPhoto;album.json.content[nextPhoto].previousPhoto=previousPhoto}if(visible.photo)lychee.goto(album.getID());album.json.content[photoID]=null;view.album.content.delete(photoID);params="setAlbum&photoID="+photoID+"&albumID="+albumID;lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}},setStar:function(photoID){var params;if(visible.photo()){photo.json.star=photo.json.star==0?1:0;view.photo.star()}album.json.content[photoID].star=album.json.content[photoID].star==0?1:0;view.album.content.star(photoID);params="setPhotoStar&photoID="+photoID;lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})},setPublic:function(photoID,e){var params;if(photo.json.public==2){modal.show("Public Album","This photo is located in a public album. To make this photo private or public, edit the visibility of the associated album.",[["Show Album",function(){lychee.goto(photo.json.original_album)}],["Close",function(){}]]);return false}if(visible.photo()){photo.json.public=photo.json.public==0?1:0;view.photo.public();if(photo.json.public==1)contextMenu.sharePhoto(photoID,e)}album.json.content[photoID].public=album.json.content[photoID].public==0?1:0;view.album.content.public(photoID);params="setPhotoPublic&photoID="+photoID+"&url="+photo.getViewLink(photoID);lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})},setDescription:function(photoID){var oldDescription=photo.json.description,description,params,buttons;buttons=[["Set Description",function(){description=$(".message input.text").val();if(description.length<800){if(visible.photo()){photo.json.description=description;view.photo.description()}params="setPhotoDescription&photoID="+photoID+"&description="+escape(description);lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}else loadingBar.show("error","Description too long. Please try again!")}],["Cancel",function(){}]];modal.show("Set Description","Please enter a description for this photo: ",buttons)},share:function(photoID,service){var link="",url=photo.getViewLink(photoID),filename="unknown";switch(service){case 0:link="https://twitter.com/share?url="+encodeURI(url);break;case 1:link="http://www.facebook.com/sharer.php?u="+encodeURI(url)+"&t="+encodeURI(photo.json.title);break;case 2:link="mailto:?subject="+encodeURI(photo.json.title)+"&body="+encodeURI(url);break;case 3:lychee.loadDropbox(function(){filename=photo.json.title+"."+photo.getDirectLink().split(".").pop();Dropbox.save(photo.getDirectLink(),filename)});break;default:link="";break}if(link.length>5)location.href=link},isSmall:function(){var size=[["width",false],["height",false]];if(photo.json.width<$(window).width()-60)size["width"]=true;if(photo.json.height<$(window).height()-100)size["height"]=true;if(size["width"]&&size["height"])return true;else return false},getArchive:function(photoID){var link;if(location.href.indexOf("index.html")>0)link=location.href.replace(location.hash,"").replace("index.html","php/api.php?function=getPhotoArchive&photoID="+photoID);else link=location.href.replace(location.hash,"")+"php/api.php?function=getPhotoArchive&photoID="+photoID;if(lychee.publicMode)link+="&password="+password.value;location.href=link},getDirectLink:function(){return $("#imageview #image").css("background-image").replace(/"/g,"").replace(/url\(|\)$/gi,"")},getViewLink:function(photoID){if(location.href.indexOf("index.html")>0)return location.href.replace("index.html"+location.hash,"view.php?p="+photoID);else return location.href.replace(location.hash,"view.php?p="+photoID)}};search={code:null,find:function(term){var params,albumsData="",photosData="",code;clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){if($("#search").val().length!==0){params="search&term="+term;lychee.api(params,function(data){if(data&&data.albums){albums.json={content:data.albums};$.each(albums.json.content,function(){albums.parse(this);albumsData+=build.album(this)})}if(data&&data.photos){album.json={content:data.photos};$.each(album.json.content,function(){album.parse(this);photosData+=build.photo(this)})}if(albumsData===""&&photosData==="")code="error";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(search.code!==hex_md5(code)){$(".no_content").remove();lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut");search.code=hex_md5(code);setTimeout(function(){if(code==="error")$("body").append(build.no_content("search"));else{lychee.content.html(code);lychee.animate(".album, .photo","contentZoomIn")}},300)}})}else search.reset()},250))},reset:function(){$("#search").val("");$(".no_content").remove();if(search.code!==""){search.code="";lychee.animate(".divider","fadeOut");albums.load()}}};var settings={createConfig:function(){var dbName,dbUser,dbPassword,dbHost,buttons;buttons=[["Connect",function(){dbHost=$(".message input.text#dbHost").val();dbUser=$(".message input.text#dbUser").val();dbPassword=$(".message input.text#dbPassword").val();dbName=$(".message input.text#dbName").val();if(dbHost.length<1)dbHost="localhost";if(dbName.length<1)dbName="lychee";params="createConfig&dbName="+escape(dbName)+"&dbUser="+escape(dbUser)+"&dbPassword="+escape(dbPassword)+"&dbHost="+escape(dbHost);lychee.api(params,function(data){if(data!==true){setTimeout(function(){if(data.indexOf("Warning: Connection failed!")!==-1){buttons=[["Retry",function(){setTimeout(settings.createConfig,400)}],["",function(){}]];modal.show("Connection Failed","Unable to connect to host database because access was denied. Double-check your host, username and password and ensure that access from your current location is permitted.",buttons,null,false);return false}if(data.indexOf("Warning: Could not create file!")!==-1){buttons=[["Retry",function(){setTimeout(settings.createConfig,400)}],["",function(){}]];modal.show("Saving Failed","Unable to save this configuration. Permission denied in 'php/'. Please set the read, write and execute rights for others in 'php/' and 'uploads/'. Take a look the readme for more information.",buttons,null,false);return false}buttons=[["Retry",function(){setTimeout(settings.createConfig,400)}],["",function(){}]];modal.show("Configuration Failed","Something unexpected happened. Please try again and check your installation and server. Take a look the readme for more information.",buttons,null,false);return false},400)}else{lychee.api("update",function(data){window.location.reload()})}})}],["",function(){}]];modal.show("Configuration","Enter your database connection details below: Lychee will create its own database. If required, you can enter the name of an existing database instead:",buttons,-215,false)},createLogin:function(){var username,password,params,buttons;buttons=[["Create Login",function(){username=$(".message input.text#username").val();password=$(".message input.text#password").val();if(username.length<1||password.length<1){setTimeout(function(){buttons=[["Retry",function(){setTimeout(settings.createLogin,400)}],["",function(){}]];modal.show("Wrong Input","The username or password you entered is not long enough. Please try again with another username and password!",buttons,null,false);return false},400)}else{params="setLogin&username="+escape(username)+"&password="+hex_md5(password);lychee.api(params,function(data){if(data!==true){setTimeout(function(){buttons=[["Retry",function(){setTimeout(settings.createLogin,400)}],["",function(){}]];modal.show("Creation Failed","Unable to save login. Please try again with another username and password!",buttons,null,false);return false},400)}})}}],["",function(){}]];modal.show("Create Login","Enter a username and password for your installation: ",buttons,-122,false)},setLogin:function(){var old_password,username,password,params,buttons;buttons=[["Change Login",function(){old_password=$(".message input.text#old_password").val();username=$(".message input.text#username").val();password=$(".message input.text#password").val();if(old_password.length<1){loadingBar.show("error","Your old password was entered incorrectly. Please try again!");return false}if(username.length<1){loadingBar.show("error","Your new username was entered incorrectly. Please try again!");return false}if(password.length<1){loadingBar.show("error","Your new password was entered incorrectly. Please try again!");return false}params="setLogin&oldPassword="+hex_md5(old_password)+"&username="+escape(username)+"&password="+hex_md5(password);lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}],["Cancel",function(){}]];modal.show("Change Login","Enter your current password: Your username and password will be changed to the following: ",buttons,-171)},setSorting:function(){var buttons,sorting;buttons=[["Change Sorting",function(){sorting[0]=$("select#settings_type").val();sorting[1]=$("select#settings_order").val();params="setSorting&type="+sorting[0]+"&order="+sorting[1];lychee.api(params,function(data){if(data===true){lychee.sorting="ORDER BY "+sorting[0]+" "+sorting[1];lychee.load()}else lychee.error(null,params,data)})}],["Cancel",function(){}]];modal.show("Change Sorting","Sort photos by in an order. ",buttons);if(lychee.sorting!=""){sorting=lychee.sorting.replace("ORDER BY ","").replace(" ",";").split(";");$("select#settings_type").val(sorting[0]);$("select#settings_order").val(sorting[1])}}};upload={show:function(icon,text){if(icon===undefined)icon="upload";upload.close(true);$("body").append(build.uploadModal(icon,text))},setIcon:function(icon){$(".upload_message a").remove();$(".upload_message").prepend("")},setProgress:function(progress){$(".progressbar div").css("width",progress+"%")},setText:function(text){$(".progressbar").remove();$(".upload_message").append("
"+text+"
")},start:{local:function(files){var pre_progress=0,formData=new FormData,xhr=new XMLHttpRequest,albumID=album.getID(),popup,progress;if(files.length<=0)return false;if(albumID===false)albumID=0;formData.append("function","upload");formData.append("albumID",albumID);for(var i=0;ipre_progress){upload.setProgress(progress);pre_progress=progress}if(progress>=100){upload.setIcon("cog");upload.setText("Processing photos")}}};$("#upload_files").val("");xhr.send(formData)},url:function(){var albumID=album.getID(),params,extension,buttons;if(albumID===false)albumID=0;buttons=[["Import",function(){link=$(".message input.text").val();if(link&&link.length>3){extension=link.split(".").pop();if(extension!=="jpeg"&&extension!=="jpg"&&extension!=="png"&&extension!=="gif"&&extension!=="webp"){loadingBar.show("error","The file format of this link is not supported.");return false}modal.close();upload.show("cog","Importing from URL");params="importUrl&url="+escape(encodeURI(link))+"&albumID="+albumID;lychee.api(params,function(data){upload.close();if(album.getID()===false)lychee.goto("0");else album.load(albumID);if(data!==true)lychee.error(null,params,data)})}else loadingBar.show("error","Link to short or too long. Please try another one!")}],["Cancel",function(){}]];modal.show("Import from Link","Please enter the direct link to a photo to import it: ",buttons)},server:function(){var albumID=album.getID(),params,buttons;if(albumID===false)albumID=0;buttons=[["Import",function(){modal.close();upload.show("cog","Importing photos");params="importServer&albumID="+albumID;lychee.api(params,function(data){upload.close();if(album.getID()===false)lychee.goto("0");else album.load(albumID);if(data==="Warning: Folder empty!")lychee.error("Folder empty. No photos imported!",params,data);else if(data!==true)lychee.error(null,params,data)})}],["Cancel",function(){}]];modal.show("Import from Server","This action will import all photos which are located in 'uploads/import/' of your Lychee installation.",buttons)},dropbox:function(){var albumID=album.getID(),params;if(albumID===false)albumID=0;lychee.loadDropbox(function(){Dropbox.choose({linkType:"direct",multiselect:true,success:function(files){if(files.length>1){for(var i=0;i0){$("#imageview #image").css({marginTop:-1*($("#imageview #image").height()/2)+20})}else{$("#imageview #image").css({top:60,right:30,bottom:30,left:30})}}},hide:function(){if(visible.photo()&&!visible.infobox()&&!visible.contextMenu()&&!visible.message()){clearTimeout($(window).data("timeout"));$(window).data("timeout",setTimeout(function(){lychee.imageview.addClass("full");lychee.loadingBar.css("opacity",0);lychee.header.addClass("hidden");if($("#imageview #image.small").length>0){$("#imageview #image").css({marginTop:-1*($("#imageview #image").height()/2)})}else{$("#imageview #image").css({top:0,right:0,bottom:0,left:0})}},500))}},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("");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="";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);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="",title=albums.json.content[albumID].title;if(albums.json.content[albumID].password)prefix=" ";if(title.length>18)title=title.substr(0,18)+"...";$(".album[data-id='"+albumID+"'] .overlay h1").html(prefix+title)},"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(oldTitle){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_name").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 title=album.json.content[photoID].title;if(title.length>18)title=title.substr(0,18)+"...";$(".photo[data-id='"+photoID+"'] .overlay h1").html(title)},star:function(photoID){$(".photo[data-id='"+photoID+"'] .icon-star").remove();if(album.json.content[photoID].star==1)$(".photo[data-id='"+photoID+"']").append("")},"public":function(photoID){$(".photo[data-id='"+photoID+"'] .icon-share").remove();if(album.json.content[photoID].public==1)$(".photo[data-id='"+photoID+"']").append("")},"delete":function(photoID){$(".photo[data-id='"+photoID+"']").css("opacity",0).animate({width:0,marginLeft:0},300,function(){$(this).remove();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(){lychee.content.addClass("view");view.header.mode("photo");$("body").css("overflow","hidden");$(document).bind("mouseenter",view.header.show).bind("mouseleave",view.header.hide);lychee.animate(lychee.imageview,"fadeIn")},hide:function(){if(!visible.controls())view.header.show();if(visible.infobox)view.infobox.hide();lychee.content.removeClass("view");view.header.mode("album");$("body").css("overflow","scroll");$(document).unbind("mouseenter").unbind("mouseleave");lychee.animate(lychee.imageview,"fadeOut");setTimeout(function(){lychee.imageview.hide();view.album.infobox()},300)},title:function(oldTitle){if(photo.json.init)$("#infobox .attr_name").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){$("#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")}},"public":function(){if(photo.json.public==1||photo.json.public==2){$("#button_share a").addClass("active");$("#button_share").attr("title","Share Photo");if(photo.json.init)$("#infobox .attr_visibility").html("Public")}else{$("#button_share a").removeClass("active");$("#button_share").attr("title","Make Public");if(photo.json.init)$("#infobox .attr_visibility").html("Private")}},photo:function(){lychee.imageview.html(build.imageview(photo.json,photo.isSmall(),visible.controls()));if(album.json&&album.json.content[photo.getID()]&&album.json.content[photo.getID()].nextPhoto===""||lychee.viewMode)$("a#next").hide();if(album.json&&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()}}};visible={albums:function(){if($("#tools_albums").css("display")==="block")return true;else return false},album:function(){if($("#tools_album").css("display")==="block")return true;else return false},photo:function(){if($("#imageview.fadeIn").length>0)return true;else return false},infobox:function(){if($("#infobox.active").length>0)return true;else return false},controls:function(){if(lychee.loadingBar.css("opacity")<1)return false;else return true},message:function(){if($(".message").length>0)return true;else return false},signin:function(){if($(".message .sign_in").length>0)return true;else return false},contextMenu:function(){if($(".contextmenu").length>0)return true;else return false}};