2 lines
62 KiB
JavaScript
Executable File
2 lines
62 KiB
JavaScript
Executable File
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){if(data===true)data=1;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;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(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: <input class='text' type='text' placeholder='Description' value='"+oldDescription+"'>",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"<div class='divider fadeIn'><h1>"+title+"</h1></div>"},editIcon:function(id){return"<div id='"+id+"' class='edit'><a class='icon-pencil'></a></div>"},album:function(albumJSON){if(!albumJSON)return"";var album="",longTitle="",title=albumJSON.title;if(title.length>18){title=albumJSON.title.substr(0,18)+"...";longTitle=albumJSON.title}typeThumb0=albumJSON.thumb0.split(".").pop();typeThumb1=albumJSON.thumb1.split(".").pop();typeThumb2=albumJSON.thumb2.split(".").pop();album+="<div class='album' data-id='"+albumJSON.id+"' data-password='"+albumJSON.password+"'>";album+="<img src='"+albumJSON.thumb2+"' width='200' height='200' alt='thumb' data-type='"+typeThumb2+"'>";album+="<img src='"+albumJSON.thumb1+"' width='200' height='200' alt='thumb' data-type='"+typeThumb1+"'>";album+="<img src='"+albumJSON.thumb0+"' width='200' height='200' alt='thumb' data-type='"+typeThumb0+"'>";album+="<div class='overlay'>";if(albumJSON.password&&!lychee.publicMode)album+="<h1><span class='icon-lock'></span> "+title+"</h1>";else album+="<h1 title='"+longTitle+"'>"+title+"</h1>";album+="<a>"+albumJSON.sysdate+"</a>";album+="</div>";if(!lychee.publicMode&&albumJSON.star==1)album+="<a class='badge red icon-star'></a>";if(!lychee.publicMode&&albumJSON.public==1)album+="<a class='badge red icon-share'></a>";if(!lychee.publicMode&&albumJSON.unsorted==1)album+="<a class='badge red icon-reorder'></a>";album+="</div>";return album},photo:function(photoJSON){if(!photoJSON)return"";var photo="",longTitle="",title=photoJSON.title;if(title.length>18){title=photoJSON.title.substr(0,18)+"...";longTitle=photoJSON.title}photo+="<div class='photo' data-album-id='"+photoJSON.album+"' data-id='"+photoJSON.id+"'>";photo+="<img src='"+photoJSON.thumbUrl+"' width='200' height='200' alt='thumb'>";photo+="<div class='overlay'>";photo+="<h1 title='"+longTitle+"'>"+title+"</h1>";photo+="<a>"+photoJSON.sysdate+"</a>";photo+="</div>";if(photoJSON.star==1)photo+="<a class='badge red icon-star'></a>";if(!lychee.publicMode&&photoJSON.public==1&&album.json.public!=1)photo+="<a class='badge red icon-share'></a>";photo+="</div>";return photo},imageview:function(photoJSON,isSmall,visibleControls){if(!photoJSON)return"";var view="";view+="<div class='arrow_wrapper previous'><a id='previous' class='icon-caret-left'></a></div>";view+="<div class='arrow_wrapper next'><a id='next' class='icon-caret-right'></a></div>";if(isSmall){if(visibleControls)view+="<div id='image' class='small' style='background-image: url("+photoJSON.url+"); width: "+photoJSON.width+"px; height: "+photoJSON.height+"px; margin-top: -"+parseInt(photoJSON.height/2-20)+"px; margin-left: -"+photoJSON.width/2+"px;'></div>";else view+="<div id='image' class='small' style='background-image: url("+photoJSON.url+"); width: "+photoJSON.width+"px; height: "+photoJSON.height+"px; margin-top: -"+parseInt(photoJSON.height/2)+"px; margin-left: -"+photoJSON.width/2+"px;'></div>"}else{if(visibleControls)view+="<div id='image' style='background-image: url("+photoJSON.url+")'></div>";else view+="<div id='image' style='background-image: url("+photoJSON.url+"); top: 0px; right: 0px; bottom: 0px; left: 0px;'></div>"}return view},no_content:function(typ){var no_content="";no_content+="<div class='no_content fadeIn'>";no_content+="<a class='icon icon-"+typ+"'></a>";if(typ==="search")no_content+="<p>No results</p>";else if(typ==="picture")no_content+="<p>No public albums</p>";else if(typ==="cog")no_content+="<p>No Configuration!</p>";no_content+="</div>";return no_content},modal:function(title,text,button,marginTop,closeButton){var modal="",custom_style="";if(marginTop)custom_style="style='margin-top: "+marginTop+"px;'";modal+="<div class='message_overlay fadeIn'>";modal+="<div class='message center'"+custom_style+">";modal+="<h1>"+title+"</h1>";if(closeButton!=false){modal+="<a class='close icon-remove-sign'></a>"}modal+="<p>"+text+"</p>";$.each(button,function(index){if(this[0]!=""){if(index===0)modal+="<a class='button active'>"+this[0]+"</a>";else modal+="<a class='button'>"+this[0]+"</a>"}});modal+="</div>";modal+="</div>";return modal},signInModal:function(){var modal="";modal+="<div class='message_overlay'>";modal+="<div class='message center'>";modal+="<h1><a class='icon-lock'></a> Sign In</h1>";modal+="<a class='close icon-remove-sign'></a>";modal+="<div class='sign_in'>";modal+="<input id='username' type='text' name='' value='' placeholder='username'>";modal+="<input id='password' type='password' name='' value='' placeholder='password'>";modal+="</div>";modal+="<div id='version'>Version "+lychee.version+"<span> – <a target='_blank' href='"+lychee.updateURL+"'>Update available!</a><span></div>";modal+="<a onclick='lychee.login()' class='button active'>Sign in</a>";modal+="</div>";modal+="</div>";return modal},uploadModal:function(icon,text){var modal="";modal+="<div class='upload_overlay fadeIn'>";modal+="<div class='upload_message center'>";modal+="<a class='icon-"+icon+"'></a>";if(text!==undefined)modal+="<p>"+text+"</p>";else modal+="<div class='progressbar'><div></div></div>";modal+="</div>";modal+="</div>";return modal},contextMenu:function(items){var menu="";menu+="<div class='contextmenu_bg'></div>";menu+="<div class='contextmenu'>";menu+="<table>";menu+="<tbody>";$.each(items,function(index){if(items[index][0]==="separator"&&items[index][1]===-1)menu+="<tr class='separator'></tr>";else if(items[index][1]===-1)menu+="<tr class='no_hover'><td>"+items[index][0]+"</td></tr>";else if(items[index][2]!=undefined)menu+="<tr><td onclick='"+items[index][2]+"; window.contextMenu.close();'>"+items[index][0]+"</td></tr>";else menu+="<tr><td onclick='window.contextMenu.fns["+items[index][1]+"](); window.contextMenu.close();'>"+items[index][0]+"</td></tr>"});menu+="</tbody>";menu+="</table>";menu+="</div>";return menu},infoboxPhoto:function(photoJSON,forView){if(!photoJSON)return"";var infobox="",public,editTitleHTML,editDescriptionHTML,infos;infobox+="<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";infobox+="<div class='wrapper'>";switch(photoJSON.public){case"0":public="Private";break;case"1":public="Public";break;case"2":public="Public (Album)";break;default:public="-";break}editTitleHTML=forView===true||lychee.publicMode?"":" "+build.editIcon("edit_title");editDescriptionHTML=forView===true||lychee.publicMode?"":" "+build.editIcon("edit_description");infos=[["","Basics"],["Name",photoJSON.title+editTitleHTML],["Uploaded",photoJSON.sysdate],["Description",photoJSON.description+editDescriptionHTML],["","Image"],["Size",photoJSON.size],["Format",photoJSON.type],["Resolution",photoJSON.width+" x "+photoJSON.height]];if(photoJSON.takedate+photoJSON.make+photoJSON.model+photoJSON.shutter+photoJSON.aperture+photoJSON.focal+photoJSON.iso!=""){infos=infos.concat([["","Camera"],["Captured",photoJSON.takedate],["Make",photoJSON.make],["Type/Model",photoJSON.model],["Shutter Speed",photoJSON.shutter],["Aperture",photoJSON.aperture],["Focal Length",photoJSON.focal],["ISO",photoJSON.iso]])}infos=infos.concat([["","Share"],["Visibility",public]]);$.each(infos,function(index){if(infos[index][1]===""||infos[index][1]==undefined||infos[index][1]==null)infos[index][1]="-";switch(infos[index][0]){case"":infobox+="</table>";infobox+="<div class='separator'><h1>"+infos[index][1]+"</h1></div>";infobox+="<table>";break;case"Tags":infobox+="</table>";infobox+="<div class='separator'><h1>"+infos[index][0]+"</h1></div>";infobox+="<tr>";infobox+="<div id='tags'>"+infos[index][1]+"</div>";infobox+="</tr>";break;default:infobox+="<tr>";infobox+="<td>"+infos[index][0]+"</td>";infobox+="<td class='attr_"+infos[index][0].toLowerCase()+"'>"+infos[index][1]+"</td>";infobox+="</tr>";break}});infobox+="</table>";infobox+="<div class='bumper'></div>";infobox+="</div>";return infobox},infoboxAlbum:function(albumJSON,forView){if(!albumJSON)return"";var infobox="",public,password,editTitleHTML,editDescriptionHTML,infos;infobox+="<div class='header'><h1>About</h1><a class='icon-remove-sign'></a></div>";infobox+="<div class='wrapper'>";switch(albumJSON.public){case"0":public="Private";break;case"1":public="Public";break;default:public="-";break}switch(albumJSON.password){case false:password="No";break;case true:password="Yes";break;default:password="-";break}editTitleHTML=forView===true||lychee.publicMode?"":" "+build.editIcon("edit_title_album");editDescriptionHTML=forView===true||lychee.publicMode?"":" "+build.editIcon("edit_description_album");infos=[["","Basics"],["Name",albumJSON.title+editTitleHTML],["Description",albumJSON.description+editDescriptionHTML],["","Album"],["Created",albumJSON.sysdate],["Images",albumJSON.num],["","Share"],["Visibility",public],["Password",password]];$.each(infos,function(index){if(infos[index][1]===""||infos[index][1]==undefined||infos[index][1]==null)infos[index][1]="-";if(infos[index][0]===""){infobox+="</table>";infobox+="<div class='separator'><h1>"+infos[index][1]+"</h1></div>";infobox+="<table id='infos'>"}else{infobox+="<tr>";infobox+="<td>"+infos[index][0]+"</td>";infobox+="<td class='attr_"+infos[index][0].toLowerCase()+"'>"+infos[index][1]+"</td>";infobox+="</tr>"}});infobox+="</table>";infobox+="<div class='bumper'></div>";infobox+="</div>";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();upload.notify();contextMenu.fns=[function(){$("#upload_files").click()},function(){upload.start.url()},function(){upload.start.dropbox()},function(){upload.start.server()},function(){album.add()}];items=[["<a class='icon-picture'></a> Upload Photo",0],["separator",-1],["<a class='icon-link'></a> Import from Link",1],["<a class='icon-folder-open'></a> Import from Dropbox",2],["<a class='icon-hdd'></a> Import from Server",3],["separator",-1],["<a class='icon-folder-close'></a> 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=[["<a class='icon-user'></a> Change Login",0],["<a class='icon-sort'></a> Change Sorting",1],["<a class='icon-info-sign'></a> About Lychee",2],["separator",-1],["<a class='icon-signout'></a> 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=[["<a class='icon-edit'></a> Rename",0],["<a class='icon-trash'></a> 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=[["<a class='icon-star'></a> Star",0],["separator",-1],["<a class='icon-edit'></a> Rename",1],["<a class='icon-folder-open'></a> Move",2],["<a class='icon-trash'></a> 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=[["<input readonly id='link' value='"+link+"'>",-1],["separator",-1],["<a class='icon-eye-close'></a> Make Private",0],["separator",-1],["<a class='icon-twitter'></a> Twitter",1],["<a class='icon-facebook'></a> Facebook",2],["<a class='icon-envelope'></a> Mail",3],["<a class='icon-hdd'></a> Dropbox",4],["<a class='icon-link'></a> 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=[["<input readonly id='link' value='"+location.href+"'>",-1],["separator",-1],["<a class='icon-eye-close'></a> Make Private",0],["<a class='icon-lock'></a> Set Password",1],["separator",-1],["<a class='icon-twitter'></a> Twitter",2],["<a class='icon-facebook'></a> Facebook",3],["<a class='icon-envelope'></a> Mail",4]];if(album.json.password==true)items[3]=["<a class='icon-unlock'></a> 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","auto")}};$(document).ready(function(){var event_name=mobileBrowser()?"touchend":"click";$(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? <input class='text' type='password' placeholder='password (optional)' value=''>",[["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())});$("#clearSearch").on(event_name,function(){$("#search").focus();search.reset()});$("#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("<h1>Error: <span>"+errorText+"</span></h1>").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.3",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<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!=="")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+"'?<br>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: <input class='text' type='text' placeholder='Title' value='"+oldTitle+"'>",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: <input class='text' type='text' placeholder='Description' value='"+oldDescription+"'>",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");$("img[data-type!='svg']").retina()}},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 <b>'php/'</b>. Please set the read, write and execute rights for others in <b>'php/'</b> and <b>'uploads/'</b>. 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: <input id='dbHost' class='text less' type='text' placeholder='Host (optional)' value=''><input id='dbUser' class='text less' type='text' placeholder='Username' value=''><input id='dbPassword' class='text more' type='password' placeholder='Password' value=''><br>Lychee will create its own database. If required, you can enter the name of an existing database instead:<input id='dbName' class='text more' type='text' placeholder='Database (optional)' value=''>",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: <input id='username' class='text less' type='text' placeholder='New Username' value=''><input id='password' class='text' type='password' placeholder='New Password' value=''>",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: <input id='old_password' class='text more' type='password' placeholder='Current Password' value=''><br>Your username and password will be changed to the following: <input id='username' class='text less' type='text' placeholder='New Username' value=''><input id='password' class='text' type='password' placeholder='New Password' value=''>",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 <select id='settings_type'> <option value='id'>Upload Time</option> <option value='title'>Title</option> <option value='description'>Description</option> <option value='public'>Public</option> <option value='star'>Star</option> <option value='type'>Photo Format</option> </select> in an <select id='settings_order'> <option value='ASC'>Ascending</option> <option value='DESC'>Descending</option> </select> 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("<a class='icon-"+icon+"'></a>")},setProgress:function(progress){$(".progressbar div").css("width",progress+"%")},setText:function(text){$(".progressbar").remove();$(".upload_message").append("<p>"+text+"</p>")},notify:function(title){var popup;if(!window.webkitNotifications)return false;if(window.webkitNotifications.checkPermission()!=0)window.webkitNotifications.requestPermission();if(window.webkitNotifications.checkPermission()==0&&title){popup=window.webkitNotifications.createNotification("",title,"You can now manage your new photo(s).");popup.show()}},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;i<files.length;i++){if(files[i].type!=="image/jpeg"&&files[i].type!=="image/jpg"&&files[i].type!=="image/png"&&files[i].type!=="image/gif"&&files[i].type!=="image/webp"){loadingBar.show("error","The file format of "+files[i].name+" is not supported.");return false}else{formData.append(i,files[i])}}upload.show();window.onbeforeunload=function(){return"Lychee is currently uploading!"};xhr.open("POST",lychee.api_path);xhr.onload=function(){if(xhr.status===200){upload.close();upload.notify("Upload complete");window.onbeforeunload=null;if(album.getID()===false)lychee.goto("0");else album.load(albumID)}};xhr.upload.onprogress=function(e){if(e.lengthComputable){progress=e.loaded/e.total*100|0;if(progress>pre_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();upload.notify("Import complete");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: <input class='text' type='text' placeholder='http://' value='http://'>",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();upload.notify("Import complete");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 <b>'uploads/import/'</b> 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;i<files.length;i++)files[i]=files[i].link}else files=files[0].link;upload.show("cog","Importing photos");params="importUrl&url="+escape(files)+"&albumID="+albumID;lychee.api(params,function(data){upload.close();upload.notify("Import complete");if(album.getID()===false)lychee.goto("0");else album.load(albumID);if(data!==true)lychee.error(null,params,data)})}})})}},close:function(force){if(force===true){$(".upload_overlay").remove()}else{upload.setProgress(100);$(".upload_overlay").removeClass("fadeIn").css("opacity",0);setTimeout(function(){$(".upload_overlay").remove()},300)}}};view={header:{show:function(){clearTimeout($(window).data("timeout"));if(visible.photo()){lychee.imageview.removeClass("full");lychee.loadingBar.css("opacity",1);lychee.header.removeClass("hidden");if($("#imageview #image.small").length>0){$("#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("<div id='infobox_overlay' class='fadeIn'></div>");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="",longTitle="",title=albums.json.content[albumID].title;if(albums.json.content[albumID].password)prefix="<span class='icon-lock'></span> ";if(title.length>18){longTitle=title;title=title.substr(0,18)+"..."}$(".album[data-id='"+albumID+"'] .overlay h1").html(prefix+title).attr("title",longTitle)},"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 longTitle="",title=album.json.content[photoID].title;if(title.length>18){longTitle=title;title=title.substr(0,18)+"..."}$(".photo[data-id='"+photoID+"'] .overlay h1").html(title).attr("title",longTitle)},star:function(photoID){$(".photo[data-id='"+photoID+"'] .icon-star").remove();if(album.json.content[photoID].star==1)$(".photo[data-id='"+photoID+"']").append("<a class='badge red icon-star'></a>")},"public":function(photoID){$(".photo[data-id='"+photoID+"'] .icon-share").remove();if(album.json.content[photoID].public==1)$(".photo[data-id='"+photoID+"']").append("<a class='badge red icon-share'></a>")},"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","auto");$(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}}; |