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/assets/js/min/main.js

2 lines
60 KiB

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: <input class='text' type='text' placeholder='Title' value='Untitled'>",buttons)},"delete":function(albumID){var params,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)}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'?<br>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: <input class='text' type='text' placeholder='Title' value='"+oldTitle+"'>",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(dat
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<animations.length;i++){for(var x=0;x<animations[i].length;x++){if(animations[i][x]==animation){obj.removeClass(animations[i][0]+" "+animations[i][1]).addClass(animation);return true}}}return false},loadDropbox:function(callback){if(!lychee.dropbox){loadingBar.show();var g=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(){var rs=this.readyState;if(rs&&rs!=="complete"&&rs!=="loaded")return;lychee.dropbox=true;loadingBar.hide();callback()};s.parentNode.insertBefore(g,s)}else callback()},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){var buttons=[["",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){var buttons,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){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("<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){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!=="")pho