album={json:null,getID:function(){varid;if(photo.json)id=photo.json.album;elseif(album.json)id=album.json.id;elseid=$(".album:hover, .album.active").attr("data-id");if(!id)id=$(".photo:hover, .photo.active").attr("data-album-id");if(id)returnid;elsereturnfalse},load:function(albumID,refresh){varstartTime,params,durationTime,waitTime;password.get(albumID,function(){if(!refresh){loadingBar.show();lychee.animate(".album, .photo","contentZoomOut");lychee.animate(".divider","fadeOut")}startTime=(newDate).getTime();params="getAlbum&albumID="+albumID+"&password="+password.value;lychee.api(params,function(data){if(data==="Warning: Album private!"){lychee.setMode("view");returnfalse}if(data==="Warning: Wrong password!"){album.load(albumID,refresh);returnfalse}album.json=data;durationTime=(newDate).getTime()-startTime;if(durationTime>300)waitTime=0;elseif(refresh)waitTime=0;elsewaitTime=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;elseif(!album.json.title)album.json.title="Untitled"},add:function(){vartitle,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);elselychee.error(null,params,data)})}elseloadingBar.show("error","Title too short or too long. Please try again!")}],["Cancel",function(){}]];modal.show("New Album","Please enter a title for this album: <input class='text' type='text' placeholder='Title' value='Untitled'>",buttons)},"delete":function(albumID){varparams,buttons,albumTitle;buttons=[["Delete Album and Photos",function(){params="deleteAlbum&albumID="+albumID+"&delAll=true";lychee.api(params,function(data){if(visible.albums()){albums.json.num--;view.albums.content.delete(albumID)}elselychee.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'?<br>This action can't be undone!",buttons)}else{if(album.json)albumTitle=album.json.title;elseif(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){varoldTitle="",newTitle,params,buttons;if(!albumID)returnfalse;if(album.json)oldTitle=album.json.title;elseif(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)}elseif(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)})}elseif(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: <input class='text' type='text' placeholder='Title' value='"+oldTitle+"'>",buttons)},setDescription:function(photoID){varoldDescription=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(dat
Mousetrap.unbind("n").unbind("u").unbind("s").unbind("backspace");if(mode==="public"){$("header #button_signin, header #hostedwith").show();lychee.publicMode=true}elseif(mode==="view"){Mousetrap.unbind("esc");$("#button_back, a#next, a#previous").remove();lychee.publicMode=true;lychee.viewMode=true}},animate:function(obj,animation){varanimations=[["fadeIn","fadeOut"],["contentZoomIn","contentZoomOut"]];if(!obj.jQuery)obj=$(obj);for(vari=0;i<animations.length;i++){for(varx=0;x<animations[i].length;x++){if(animations[i][x]==animation){obj.removeClass(animations[i][0]+" "+animations[i][1]).addClass(animation);returntrue}}}returnfalse},loadDropbox:function(callback){if(!lychee.dropbox){loadingBar.show();varg=document.createElement("script"),s=document.getElementsByTagName("script")[0];g.src="https://www.dropbox.com/static/api/1/dropins.js";g.id="dropboxjs";g.type="text/javascript";g.async="true";g.setAttribute("data-app-key","iq7lioj9wu0ieqs");g.onload=g.onreadystatechange=function(){varrs=this.readyState;if(rs&&rs!=="complete"&&rs!=="loaded")return;lychee.dropbox=true;loadingBar.hide();callback()};s.parentNode.insertBefore(g,s)}elsecallback()},error:function(errorThrown,params,data){console.log("Error Description: "+errorThrown);console.log("Error Params: "+params);console.log("Server Response: "+data);loadingBar.show("error",errorThrown)}};modal={fns:null,show:function(title,text,buttons,marginTop,closeButton){if(!buttons){varbuttons=[["",function(){}],["",function(){}]]}modal.fns=[buttons[0][1],buttons[1][1]];$("body").append(build.modal(title,text,buttons,marginTop,closeButton));$(".message input:first-child").focus()},close:function(){modal.fns=null;$(".message_overlay").removeClass("fadeIn").css("opacity",0);setTimeout(function(){$(".message_overlay").remove()},300)}};password={value:"",set:function(albumID){varbuttons,params;buttons=[["Set Password",function(){if(visible.album()){album.json.password=true;view.album.password()}params="setAlbumPassword&albumID="+albumID+"&password="+hex_md5($(".message input.text").val());lychee.api(params,function(data){if(data!==true)lychee.error(null,params,data)})}],["Cancel",function(){}]];modal.show("Set Password","Set a password to protect '"+album.json.title+"' from unauthorized viewers. Only people with this password can view this album. <input class='text' type='password' placeholder='password' value=''>",buttons)},get:function(albumID,callback){varpasswd=$(".message input.text").val(),params;if(!lychee.publicMode)callback();elseif(album.json&&album.json.password==false)callback();elseif(albums.json&&albums.json.content[albumID].password==false)callback();elseif(!albums.json&&!album.json){album.json={password:true};callback("")}elseif(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){varbuttons;buttons=[["Enter",function(){password.get(albumID,callback)}],["Cancel",lychee.goto]];modal.show("<a class='icon-lock'></a> Enter Password","This album is protected by a password. Enter the password below to view the photos of this album: <input class='text' type='password' placeholder='password' value=''>",buttons,-110,false)},remove:function(albumID){varparams;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(){varid;if(photo.json)id=photo.json.id;elseid=$(".photo:hover, .photo.active").attr("data-id");if(id)returnid;elsereturnfalse},load:function(photoID,albumID){varparams,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!=="")pho