annotate e2gallerypro/e2upload/Compressed/filemanager-yui-basic.js @ 28:118cb614cf18 judyates tip

judy bio.
author Robert McIntyre <rlm@mit.edu>
date Tue, 29 Dec 2015 16:26:18 -0800
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 var FileManager=new Class({Implements:[Options,Events],Request:null,Directory:null,Current:null,options:{directory:"",url:null,assetBasePath:null,selectable:false,hideOnClick:false,language:"en"},hooks:{show:{},cleanup:{}},initialize:function(a){this.setOptions(a);this.options.assetBasePath=this.options.assetBasePath.replace(/(\/|\\)*$/,"/");this.droppables=[];this.Directory=this.options.directory;this.language=FileManager.Language[this.options.language]||FileManager.Language.en;this.container=new Element("div",{"class":"filemanager-container filemanager-engine-"+Browser.Engine.name+(Browser.Engine.trident?Browser.Engine.version:"")});this.el=new Element("div",{"class":"filemanager"}).inject(this.container);this.menu=new Element("div",{"class":"filemanager-menu"}).inject(this.el);this.loader=new Element("div",{"class":"loader",opacity:0,tween:{duration:200}}).inject(this.menu);this.browser=new Element("ul",{"class":"filemanager-browser"}).addEvents({click:(function(g){if(g.target.match("ul")){return this.deselect()}if(!g.target||!g.target.getParent("li")){return}var f=g.target.getParent("li").getElement("span");if(!f){return}g.stop();var d=f.retrieve("file");if(f.retrieve("block")){f.eliminate("block");return}else{if(d.mime=="text/directory"){f.addClass("selected");this.load(this.Directory+"/"+d.name);return}}this.fillInfo(d);if(this.Current){this.Current.removeClass("selected")}this.Current=f.addClass("selected");this.switchButton()}).bind(this)}).inject(this.el);if(this.options.selectable){this.addMenuButton("open")}this.addMenuButton("create");this.info=new Element("div",{"class":"filemanager-infos",opacity:0}).inject(this.el);var b=new Element("div",{"class":"filemanager-head"}).adopt([new Element("img",{"class":"filemanager-icon"}),new Element("h1")]);this.info.adopt([b,new Element("h2",{text:this.language.information})]);var c=new Element("dl").adopt([new Element("dt",{text:this.language.modified}),new Element("dd",{"class":"filemanager-modified"}),new Element("dt",{text:this.language.type}),new Element("dd",{"class":"filemanager-type"}),new Element("dt",{text:this.language.size}),new Element("dd",{"class":"filemanager-size"}),new Element("dt",{text:this.language.dir}),new Element("dd",{"class":"filemanager-dir"})]).inject(this.info);this.preview=new Element("div",{"class":"filemanager-preview"});this.info.adopt([new Element("h2",{"class":"filemanager-headline",text:this.language.preview}),this.preview]);this.closeIcon=new Element("div",{"class":"filemanager-close",title:this.language.close,events:{click:this.hide.bind(this)}}).adopt(new Asset.image(this.options.assetBasePath+"destroy.png")).inject(this.el);new FileManager.Tips(this.closeIcon.appearOn(this.closeIcon,[1,0.8]).appearOn(this.el,0.8));this.imageadd=new Asset.image(this.options.assetBasePath+"add.png",{"class":"browser-add"}).set("opacity",0).inject(this.container);this.container.inject(document.body);this.overlay=new Overlay(this.options.hideOnClick?{events:{click:this.hide.bind(this)}}:null);this.bound={keydown:(function(d){if(d.control){this.imageadd.fade(1)}}).bind(this),keyup:(function(){this.imageadd.fade(0)}).bind(this),keyesc:(function(d){if(d.key=="esc"){this.hide()}}).bind(this),scroll:(function(){this.el.center(this.offsets);this.fireEvent("scroll")}).bind(this)}},show:function(a){if(a){a.stop()}this.load(this.Directory);this.overlay.show();this.info.set("opacity",0);(function(){this.container.setStyles({opacity:0,display:"block"});this.el.center(this.offsets);this.fireEvent("show");this.container.set("opacity",1);this.fireHooks("show");window.addEvents({scroll:this.bound.scroll,resize:this.bound.scroll,keyup:this.bound.keyesc})}).delay(500,this)},hide:function(a){if(a){a.stop()}this.overlay.hide();this.browser.empty();this.container.setStyle("display","none");this.fireHooks("cleanup").fireEvent("hide");window.removeEvent("scroll",this.bound.scroll).removeEvent("resize",this.bound.scroll).removeEvent("keyup",this.bound.keyesc)},open:function(a){a.stop();if(!this.Current){return false}this.fireEvent("complete",[this.normalize(this.Directory+"/"+this.Current.retrieve("file").name),this.Current.retrieve("file")]);this.hide()},create:function(b){b.stop();var a=this;new Dialog(this.language.createdir,{language:{confirm:this.language.create,decline:this.language.cancel},content:[new Element("input",{"class":"createDirectory"})],onOpen:this.onDialogOpen.bind(this),onClose:this.onDialogClose.bind(this),onShow:function(){var c=this;this.el.getElement("input").addEvent("keyup",function(d){if(d.key=="enter"){c.el.getElement("button-confirm").fireEvent("click")}}).focus()},onConfirm:function(){new FileManager.Request({url:a.options.url+"?event=create",onSuccess:a.fill.bind(a),data:{file:this.el.getElement("input").get("value"),directory:a.Directory}},a).post()}})},deselect:function(a){if(a&&this.Current!=a){return}if(a){this.fillInfo()}if(this.Current){this.Current.removeClass("selected")}this.Current=null;this.switchButton()},load:function(a,b){this.deselect();if(!b){this.info.fade(0)}if(this.Request){this.Request.cancel()}this.Request=new FileManager.Request({url:this.options.url,onSuccess:(function(c){this.fill(c,b)}).bind(this),data:{directory:a}},this).post()},destroy:function(c,b){c.stop();var a=this;new Dialog(this.language.destroyfile,{language:{confirm:this.language.destroy,decline:this.language.cancel},onOpen:this.onDialogOpen.bind(this),onClose:this.onDialogClose.bind(this),onConfirm:function(){new FileManager.Request({url:a.options.url+"?event=destroy",data:{file:b.name,directory:a.Directory},onSuccess:function(d){if(!d||d.content!="destroyed"){new Dialog(a.language.nodestroy,{language:{confirm:a.language.ok},buttons:["confirm"]});return}a.fireEvent("modify",[$unlink(b)]);b.element.getParent().fade(0).get("tween").chain(function(){a.deselect(b.element);this.element.destroy()})}},a).post()}})},rename:function(d,c){d.stop();var b=c.name;if(c.mime!="text/directory"){b=b.replace(/\..*$/,"")}var a=this;new Dialog(this.language.renamefile,{language:{confirm:this.language.rename,decline:this.language.cancel},content:[new Element("input",{"class":"rename",value:b})],onOpen:this.onDialogOpen.bind(this),onClose:this.onDialogClose.bind(this),onShow:function(){var e=this;this.el.getElement("input").addEvent("keyup",function(f){if(f.key=="enter"){e.el.getElement("button-confirm").fireEvent("click")}}).focus()},onConfirm:function(){new FileManager.Request({url:a.options.url+"?event=move",onSuccess:(function(e){if(!e||!e.name){return}a.fireEvent("modify",[$unlink(c)]);c.element.getElement("span").set("text",e.name);c.name=e.name;a.fillInfo(c)}).bind(this),data:{file:c.name,name:this.el.getElement("input").get("value"),directory:a.Directory}},a).post()}})},fill:function(c,e){this.Directory=c.path;this.CurrentDir=c.dir;if(!e){this.fillInfo(c.dir)}this.browser.empty();if(!c.files){return}var d=[[],[]];$each(c.files,function(g){g.dir=c.path;var h=g.element=new Element("span",{"class":"fi",href:"#"}).adopt(new Asset.image(this.options.assetBasePath+"Icons/"+g.icon+".png"),new Element("span",{text:g.name})).store("file",g);var f=[];if(g.mime!="text/directory"){f.push(new Asset.image(this.options.assetBasePath+"disk.png",{title:this.language.download}).addClass("browser-icon").addEvent("click",(function(i){i.stop();window.open(this.normalize(this.Directory+"/"+g.name))}).bind(this)).inject(h,"top"))}if(g.name!=".."){["rename","destroy"].each(function(i){f.push(new Asset.image(this.options.assetBasePath+i+".png",{title:this.language[i]}).addClass("browser-icon").addEvent("click",this[i].bindWithEvent(this,[g])).injectTop(h))},this)}d[g.mime=="text/directory"?1:0].push(h);if(g.name==".."){h.set("opacity",0.7)}h.inject(new Element("li").inject(this.browser));f=$$(f.map(function(i){return i.appearOn(i,[1,0.7])})).appearOn(h.getParent("li"),0.7)},this);var b=this;$$(d[0]).makeDraggable({droppables:$$(this.droppables,d[1]),onDrag:function(f,g){b.imageadd.setStyles(Hash.getValues(g.page).map(function(h){return h+15}).associate(["left","top"]))},onBeforeStart:function(f){f.setStyles({left:"0",top:"0"})},onStart:function(f){b.onDragStart(f,this);f.set("opacity",0.7);document.addEvents({keydown:b.bound.keydown,keyup:b.bound.keyup})},onEnter:function(f,g){g.addClass("droppable")},onLeave:function(f,g){g.removeClass("droppable")},onDrop:function(h,j,i){document.removeEvents("keydown",b.bound.keydown).removeEvents("keyup",b.bound.keydown);b.imageadd.fade(0);h.set("opacity",1).store("block",true);if(i.control||!j){h.setStyles({left:"0",top:"0"})}if(!j&&!i.control){return}var f;if(j){j.addClass("selected");(function(){j.removeClass("droppable").removeClass("selected")}).delay(300);if(b.onDragComplete(h,j)){return}f=j.retrieve("file")}var g=h.retrieve("file");new FileManager.Request({url:b.options.url+"?event=move",data:{file:g.name,directory:b.Directory,newDirectory:f?f.dir+"/"+f.name:b.Directory,copy:i.control?1:0},onSuccess:function(){if(!f){b.load(b.Directory)}}},b).post();b.fireEvent("modify",[$unlink(g)]);if(!i.control){h.fade(0).get("tween").chain(function(){b.deselect(h);h.getParent().destroy()})}}});$$(d).setStyles({left:"0",top:"0"});var a=new FileManager.Tips(this.browser.getElements("img.browser-icon"));a.tip.removeClass("tip-base")},fillInfo:function(b,d){if(!b){b=this.CurrentDir}if(!d){d=this.Directory}if(!b){return}var a=this.size(b.size);this.info.fade(1).getElement("img").set({src:this.options.assetBasePath+"Icons/"+b.icon+".png",alt:b.mime});this.fireHooks("cleanup");this.preview.empty();this.info.getElement("h1").set("text",b.name);this.info.getElement("dd.filemanager-modified").set("text",b.date);this.info.getElement("dd.filemanager-type").set("text",b.mime);this.info.getElement("dd.filemanager-size").set("text",!a[0]&&a[1]=="Bytes"?"-":(a.join(" ")+(a[1]!="Bytes"?" ("+b.size+" Bytes)":"")));this.info.getElement("h2.filemanager-headline").setStyle("display",b.mime=="text/directory"?"none":"block");var e=[],c=[];d.split("/").each(function(f){if(!f){return}c.push(f);e.push(new Element("a",{"class":"icon",href:"#",text:f}).addEvent("click",(function(h,g){h.stop();this.load(g)}).bindWithEvent(this,[c.join("/")])));e.push(new Element("span",{text:" / "}))},this);e.pop();e[e.length-1].addClass("selected").removeEvents("click").addEvent("click",function(f){f.stop()});this.info.getElement("dd.filemanager-dir").empty().adopt(new Element("span",{text:"/ "}),e);if(b.mime=="text/directory"){return}if(this.Request){this.Request.cancel()}this.Request=new FileManager.Request({url:this.options.url+"?event=detail",onSuccess:(function(f){var h=this.preview.removeClass("filemanager-loading").set("html",f&&f.content?f.content.substitute(this.language,/\\?\$\{([^{}]+)\}/g):"").getElement("img.prev");if(h){h.addEvent("load",function(){this.setStyle("background","none")})}var g=this.preview.getElements("button");if(g){g.addEvent("click",function(i){i.stop();window.open(this.get("value"))})}}).bind(this),data:{directory:this.Directory,file:b.name}},this).post()},size:function(b){var c=["Bytes","KB","MB","GB","TB"];for(var a=0;b>1024;a++){b=b/1024}return[Math.round(b),c[a]]},normalize:function(a){return a.replace(/\/+/g,"/")},switchButton:function(){var a=!!this.Current;var b=this.menu.getElement("button.filemanager-open");if(b){b.set("disabled",!a)[(a?"remove":"add")+"Class"]("disabled")}},addMenuButton:function(a){var b=new Element("button",{"class":"filemanager-"+a,text:this.language[a]}).inject(this.menu);if(this[a]){b.addEvent("click",this[a].bind(this))}return b},fireHooks:function(c){var a=Array.slice(arguments,1);for(var b in this.hooks[c]){this.hooks[c][b].apply(this,a)}return this},onRequest:function(){this.loader.set("opacity",1)},onComplete:function(){this.loader.fade(0)},onDialogOpen:$empty,onDialogClose:$empty,onDragStart:$empty,onDragComplete:$lambda(false)});FileManager.Language={};if(!window.FileManager){var FileManager={}}FileManager.Tips=new Class({Extends:Tips,options:{offsets:{x:15,y:0},text:null,onShow:function(b,a){if(b.get("opacity")==0.8&&b.getStyle("visibility")=="visible"){return}b.get("tween").pause();b.set({opacity:0,tween:{duration:200,link:"cancel"}}).fade(0.8)},onHide:function(b,a){b.get("tween").pause().start("opacity",0).chain(function(){b.setStyle("left",0)})}},initialize:function(b,a){this.parent(b,a);this.tip.addClass("tip-filebrowser")}});FileManager.Request=new Class({Extends:Request.JSON,initialize:function(a,b){this.parent(a);if(b){this.addEvents({request:b.onRequest.bind(b),complete:b.onComplete.bind(b)})}}});Element.implement({appearOn:function(c,b,a){b=$type(b)=="array"?[b[0]||1,b[1]||0]:[b||1,0];this.set({opacity:b[1],tween:a||{duration:200}});$(c).addEvents({mouseenter:this.fade.bind(this,b[0]),mouseleave:this.fade.bind(this,b[1])});return this},center:function(e){var a=document.getScroll(),g=document.getSize(),c=this.getSize(),b={x:"left",y:"top"};if(!e){e={}}for(var f in b){var d=a[f]+(g[f]-c[f])/2+(e[f]||0);this.setStyle(b[f],d<10?10:d)}return this}});var Dialog=new Class({Implements:[Options,Events],options:{request:null,buttons:["confirm","decline"],language:{}},initialize:function(b,a){this.setOptions(a);this.el=new Element("div",{"class":"dialog dialog-engine-"+Browser.Engine.name+(Browser.Engine.trident?Browser.Engine.version:""),opacity:0,tween:{duration:250}}).adopt([$type(b)=="string"?new Element("div",{text:b}):b]);if(this.options.content){this.el.getElement("div").adopt(this.options.content)}Array.each(this.options.buttons,function(c){new Element("button",{"class":"dialog-"+c,text:this.options.language[c]}).addEvent("click",(function(d){if(d){d.stop()}this.fireEvent(c).fireEvent("close");this.overlay.hide();this.destroy()}).bind(this)).inject(this.el)},this);this.overlay=new Overlay({"class":"overlay overlay-dialog",events:{click:this.fireEvent.bind(this,["close"])},tween:{duration:250}});this.bound={scroll:(function(){if(!this.el){this.destroy()}else{this.el.center()}}).bind(this),keyesc:(function(c){if(c.key=="esc"){this.fireEvent("close").destroy()}}).bind(this)};this.show()},show:function(){this.overlay.show();var a=this.fireEvent("open");this.el.setStyle("display","block").inject(document.body).center().fade(1).get("tween").chain(function(){a.fireEvent("show")});window.addEvents({scroll:this.bound.scroll,resize:this.bound.scroll,keyup:this.bound.keyesc})},destroy:function(){if(this.el){this.el.fade(0).get("tween").chain((function(){this.overlay.destroy();this.el.destroy()}).bind(this))}window.removeEvent("scroll",this.bound.scroll).removeEvent("resize",this.bound.scroll).removeEvent("keyup",this.bound.keyesc)}}),Overlay=new Class({initialize:function(a){this.el=new Element("div",$extend({"class":"overlay"},a)).inject(document.body)},show:function(){this.objects=$$("object, select, embed").filter(function(a){return a.id=="SwiffFileManagerUpload"||a.style.visibility=="hidden"?false:!!(a.style.visibility="hidden")});this.resize=(function(){if(!this.el){this.destroy()}else{this.el.setStyles({width:document.getScrollWidth(),height:document.getScrollHeight()})}}).bind(this);this.resize();this.el.setStyles({opacity:0,display:"block"}).get("tween").pause().start("opacity",0.5);window.addEvent("resize",this.resize);return this},hide:function(){this.el.fade(0).get("tween").chain((function(){this.revertObjects();this.el.setStyle("display","none")}).bind(this));window.removeEvent("resize",this.resize);return this},destroy:function(){this.revertObjects().el.destroy()},revertObjects:function(){if(this.objects&&this.objects.length){this.objects.each(function(a){a.style.visibility="visible"})}return this}});FileManager.TinyMCE=function(a){return function(f,b,d,e){var c=new FileManager($extend({onComplete:function(g){if(!e.document){return}e.document.getElementById(f).value=g;if(e.ImageDialog){e.ImageDialog.showPreviewImage(g,1)}this.container.destroy()}},a(d)));c.el.setStyle("zIndex",400001);c.overlay.el.setStyle("zIndex",400000);c.show()}};FileManager.implement("SwiffZIndex",400002);var Dialog=new Class({Extends:Dialog,initialize:function(b,a){this.parent(b,a);this.el.setStyle("zIndex",400010);this.overlay.el.setStyle("zIndex",400009)}});FileManager.Language.en={more:"Details",width:"Width:",height:"Height:",ok:"Ok",open:"Select file",upload:"Upload",create:"Create folder",createdir:"Please specify a folder name:",cancel:"Cancel",information:"Information",type:"Type:",size:"Size:",dir:"Path:",modified:"Last modified:",preview:"Preview",close:"Close",destroy:"Delete",destroyfile:"Are you sure to delete this file?",rename:"Rename",renamefile:"Please enter a new file name:",download:"Download",nopreview:"<i>No preview available</i>",title:"Title:",artist:"Artist:",album:"Album:",length:"Length:",bitrate:"Bitrate:",deselect:"Deselect",nodestroy:"Deleting files has been disabled on this Server.","upload.disabled":"Uploading has been disabled on this Server.","upload.authenticated":"You are not authenticated to upload files.","upload.path":"The specified Upload-Folder does not exist. Please contact the administrator of this Website.","upload.exists":"The specified Upload-Location does already exist. Please contact the administrator of this Website.","upload.mime":"The specified file-type is not allowed.","upload.extension":"The uploaded file has an unknown or forbidden file extension.","upload.size":"The size of the file you uploaded is too big to be processed on this server. Please upload a smaller file.","upload.partial":"The file you uploaded was only partially uploaded, please upload the file again.","upload.nofile":"There was no file specified to be uploaded.","upload.default":"Something went wrong with the File-Upload.",uploader:{unknown:"Unknown Error",sizeLimitMin:'You can not attach "<em>${name}</em>" (${size}), the file size minimum is <strong>${size_min}</strong>!',sizeLimitMax:'You can not attach "<em>${name}</em>" (${size}), the file size limit is <strong>${size_max}</strong>!'},flash:{hidden:"To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).",disabled:"To enable the embedded uploader, enable the blocked Flash movie and refresh (see Flashblock).",flash:'In order to upload files you need to install <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Adobe Flash</a>.'},resizeImages:"Resize big images on upload"};