elfinder-dotneet
Version:
File manager for web
1 lines • 16.4 kB
JavaScript
;!function(e,t){if("function"==typeof define&&define.amd)define(["elfinder"],e);else if(t){var i=t.prototype._options.commandsOptions.edit.editors;t.prototype._options.commandsOptions.edit.editors=i.concat(e(t))}}(function(e){var t=window.location.search.match(/getfile=([a-z]+)/),i="function"==typeof define&&define.amd,n=function(){var e;try{e=!!new ActiveXObject("ShockwaveFlash.ShockwaveFlash")}catch(t){e=!!("undefined"==typeof window.orientation||navigator&&navigator.mimeTypes["application/x-shockwave-flash"])}return e}(),o=function(e,t,i,n){var o=$(this).children("img:first"),a=$("<div/>").css({position:"absolute",top:"50%",textAlign:"center",width:"100%",fontSize:"16pt"}).html(n.i18n("ntfloadimg")).hide().appendTo(this);o.attr("id",e+"-img").attr("src",i).css({height:"","max-width":"100%","max-height":"100%",cursor:"pointer"}).data("loading",function(e){var t=o.closest(".elfinder-dialog").find("button,.elfinder-titlebar-button");return t.prop("disabled",!e)[e?"removeClass":"addClass"]("ui-state-disabled"),o.css("opacity",e?"":"0.3"),a[e?"hide":"show"](),o})},a=function(e,t){var i,n,o,a=e.attr("style");try{e.attr("style",""),i=e.get(0),n=document.createElement("canvas"),n.width=i.width,n.height=i.height,e.attr("style",a),n.getContext("2d").drawImage(i,0,0),o=n.toDataURL(t)}catch(r){o=e.attr("src")}return o},r=function(){if(n&&window.parent!==window){var e,t,i,o,a=window.location.search.match(/[?&]pixlr=([^&]+)/),r=window.location.search.match(/[?&]image=([^&]+)/);a&&(e=window.parent,t=e.$("#"+a[1]+"iframe").hide(),o=e.$("#"+a[1]).data("resizeoff")(),"http"===r[1].substr(0,4)?(i=r[1],"https:"===window.location.protocol&&(i=i.replace(/^http:/,"https:")),o.on("load error",function(){o.data("loading")(!0)}).attr("src",i).data("loading")()):o.data("loading")(!0),t.remove())}},c=function(e,t){n&&!t.UA.ltIE8||(this.disabled=!0)},s=function(e,t){var i,n=this.fm,o=$(t).children("img:first").data("loading")().data("resizeoff",function(){return $(window).off("resize."+o.attr("id")),o}).on("click",function(){m()}),a=n.getUI(),r=$('<iframe class="ui-front" allowtransparency="true">'),c=this.file,s="https://pixlr.com/"+e+"/?s=c",d=window.location.href.toString().replace(/#.*$/,""),l=function(e){r.remove(),o.data("loading")(!0),n.error(e||"Can not launch Pixlr.")},m=function(){i=setTimeout(l,1e4),d+=(d.indexOf("?")===-1?"?":"&")+"pixlr="+o.attr("id"),s+="&referrer=elFinder&locktitle=true",s+="&exit="+encodeURIComponent(d+"&image=0"),s+="&target="+encodeURIComponent(d),s+="&title="+encodeURIComponent(c.name),s+="&locktype="+encodeURIComponent("image/png"===c.mime?"png":"jpg"),s+="&image="+encodeURIComponent(o.attr("src")),r.attr("id",o.attr("id")+"iframe").attr("src",s).css({width:"100%",height:$(window).height()+"px",position:"fixed",display:"block",backgroundColor:"transparent",border:"none",top:0,right:0}).on("load",function(){i&&clearTimeout(i),setTimeout(function(){r.is(":hidden")&&l("Please disable your ad blocker.")},1e3)}).on("error",l).appendTo(a.hasClass("elfinder-fullscreen")?a:"body"),$(window).on("resize."+o.attr("id"),function(){r.css("height",$(window).height())})};m()};return r(),t&&(t=t[1],"ckeditor"===t?e.prototype._options.getFileCallback=function(e,t){window.opener.CKEDITOR.tools.callFunction(function(){var e=new RegExp("(?:[?&]|&)CKEditorFuncNum=([^&]+)","i"),t=window.location.search.match(e);return t&&t.length>1?t[1]:""}(),t.convAbsUrl(e.url)),t.destroy(),window.close()}:"tinymce"===t&&(e.prototype._options.getFileCallback=function(e,t){parent.tinymce.activeEditor.windowManager.getParams().oninsert(e,t),parent.tinymce.activeEditor.windowManager.close()})),[{info:{name:"Pixlr Editor",iconImg:"img/edit_pixlreditor.png",urlAsContent:!0,schemeContent:!0,single:!0},mimes:["image/jpeg","image/png"],html:'<div style="width:100%;height:300px;max-height:100%;text-align:center;"><img/></div>',setup:function(e,t){c.call(this,e,t)},init:function(e,t,i,n){o.call(this,e,t,n.convAbsUrl(i),n)},getContent:function(){return $(this).children("img:first").attr("src")},load:function(e){s.call(this,"editor",e)},save:function(e){},close:function(e){}},{info:{name:"Pixlr Express",iconImg:"img/edit_pixlrexpress.png",urlAsContent:!0,schemeContent:!0,single:!0},mimes:["image/jpeg"],html:'<div style="width:100%;height:300px;max-height:100%;text-align:center;"><img/></div>',setup:function(e,t){c.call(this,e,t)},init:function(e,t,i,n){o.call(this,e,t,n.convAbsUrl(i),n)},getContent:function(){return $(this).children("img:first").attr("src")},load:function(e){s.call(this,"express",e)},save:function(e){},close:function(e){}},{info:{name:"Creative Cloud",iconImg:"img/edit_creativecloud.png",schemeContent:!0,single:!0},mimes:["image/jpeg","image/png"],html:'<div style="width:100%;height:300px;max-height:100%;text-align:center;"><img/></div>',setup:function(e,t){!t.UA.ltIE8&&e.extraOptions&&e.extraOptions.creativeCloudApiKey?this.apiKey=e.extraOptions.creativeCloudApiKey:this.disabled=!0},init:function(e,t,i,n){o.call(this,e,t,i,n)},getContent:function(){return $(this).children("img:first").attr("src")},load:function(e){var t,i=this,n=this.fm,o=$(e).children("img:first"),a=n.getUI(),r=$.Deferred(),c=$("#elfinder-aviary-container"),s=function(e){var s=function(){var e={jp:"ja",zh_TW:"zh_HANT",zh_CN:"zh_HANS"};return e[n.lang]?e[n.lang]:n.lang};c.length?c.appendTo(c.parent()):(c=$('<div id="elfinder-aviary-container" class="ui-front"/>').css({position:"fixed",top:0,right:0,width:"100%",height:$(window).height(),overflow:"auto"}).hide().appendTo(a.hasClass("elfinder-fullscreen")?a:"body"),$(window).on("resize."+n.namespace,function(){c.css("height",$(window).height())}),a.on("resize."+n.namespace,function(e,t){e.preventDefault(),e.stopPropagation(),t&&t.fullscreen&&c.appendTo("on"===t.fullscreen?a:"body")}),n.bind("destroy",function(){c.remove()})),o.on("click",d).data("loading")(),t=new Aviary.Feather({apiKey:i.confObj.apiKey,onSave:function(e,i){t.showWaitIndicator(),o.on("load error",function(){o.data("loading")(!0)}).attr("crossorigin","anonymous").attr("src",i).data("loading")(),t.close()},onLoad:e||function(){},onClose:function(){$(c).hide()},appendTo:c.get(0),maxSize:2048,language:s()}),r.resolve(t)},d=function(){$(c).show(),t.launch({image:o.attr("id"),url:o.attr("src")}),o.data("loading")(!0)};return"undefined"==typeof Aviary?n.loadScript(["https://dme0ih8comzn4.cloudfront.net/imaging/v3/editor.js"],function(){s(d)},{loadType:"tag"}):(s(),d()),r},save:function(e){var t=$(e).children("img:first");"data:"!==t.attr("src").substr(0,5)&&t.attr("src",a(t,this.file.mime))}},{setup:function(e,t){t.UA.ltIE8&&(this.disabled=!0)},info:{name:"ACE Editor",iconImg:"img/edit_aceeditor.png"},load:function(e){var t=this,i=$.Deferred(),n=this.fm.options.cdns.ace,o=function(){var o,a,r,c=$(e),s=c.parent(),d=(s.parent(),e.id+"_ace"),l=(t.file.name.replace(/^.+\.([^.]+)|(.+)$/,"$1$2").toLowerCase(),{"text/x-php":"php","application/x-php":"php","text/html":"html","application/xhtml+xml":"html","text/javascript":"javascript","application/javascript":"javascript","text/css":"css","text/x-c":"c_cpp","text/x-csrc":"c_cpp","text/x-chdr":"c_cpp","text/x-c++":"c_cpp","text/x-c++src":"c_cpp","text/x-c++hdr":"c_cpp","text/x-shellscript":"sh","application/x-csh":"sh","text/x-python":"python","text/x-java":"java","text/x-java-source":"java","text/x-ruby":"ruby","text/x-perl":"perl","application/x-perl":"perl","text/x-sql":"sql","text/xml":"xml","application/docbook+xml":"xml","application/xml":"xml"});s.height(s.height()),ace.config.set("basePath",n),a=$('<div id="'+d+'" style="width:100%; height:100%;"/>').text(c.val()).insertBefore(c.hide()),c.data("ace",!0),o=ace.edit(d),o.$blockScrolling=1/0,o.setOptions({theme:"ace/theme/monokai",fontSize:"14px",wrap:!0}),ace.config.loadModule("ace/ext/modelist",function(){r=ace.require("ace/ext/modelist").getModeForPath("/"+t.file.name).name,"text"===r&&l[t.file.mime]&&(r=l[t.file.mime]),s.prev().children(".elfinder-dialog-title").append(" ("+t.file.mime+" : "+r.split(/[\/\\]/).pop()+")"),o.setOptions({mode:"ace/mode/"+r})}),ace.config.loadModule("ace/ext/language_tools",function(){ace.require("ace/ext/language_tools"),o.setOptions({enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!1})}),ace.config.loadModule("ace/ext/settings_menu",function(){ace.require("ace/ext/settings_menu").init(o)}),o.commands.addCommand({name:"saveFile",bindKey:{win:"Ctrl-s",mac:"Command-s"},exec:function(e){t.doSave()}}),o.commands.addCommand({name:"closeEditor",bindKey:{win:"Ctrl-w|Ctrl-q",mac:"Command-w|Command-q"},exec:function(e){t.doCancel()}}),o.resize(),$('<div class="ui-dialog-buttonset"/>').css("float","left").append($("<button/>").html(t.fm.i18n("TextArea")).button().on("click",function(){c.data("ace")?(c.removeData("ace"),a.hide(),c.val(o.session.getValue()).show().focus(),$(this).text("AceEditor")):(c.data("ace",!0),a.show(),o.setValue(c.hide().val(),-1),o.focus(),$(this).html(t.fm.i18n("TextArea")))})).append($("<button>Ace editor setting</button>").button({icons:{primary:"ui-icon-gear",secondary:"ui-icon-triangle-1-e"},text:!1}).on("click",function(){o.showSettingsMenu(),$("#ace_settingsmenu").css("font-size","80%").find('div[contains="setOptions"]').hide().end().parent().parent().appendTo($("#elfinder"))})).prependTo(s.next()),i.resolve(o)};return t.confObj.loader||(t.confObj.loader=$.Deferred(),t.fm.loadScript([n+"/ace.js"],function(){t.confObj.loader.resolve()},void 0,{obj:window,name:"ace"})),t.confObj.loader.done(o),i},close:function(e,t){t&&t.destroy()},save:function(e,t){t&&$(e).data("ace")&&(e.value=t.session.getValue())},focus:function(e,t){t&&$(e).data("ace")&&t.focus()},resize:function(e,t,i,n){t&&t.resize()}},{setup:function(e,t){t.UA.ltIE10&&(this.disabled=!0)},info:{name:"CodeMirror",iconImg:"img/edit_codemirror.png"},load:function(e){var t=this.fm.options.cdns.codemirror,n=$.Deferred(),o=this,a=function(a){var r,c,s=$(e),d=s.parent();d.height(d.height()),r=a.fromTextArea(e,{lineNumbers:!0,lineWrapping:!0,extraKeys:{"Ctrl-S":function(){o.doSave()},"Ctrl-Q":function(){o.doCancel()},"Ctrl-W":function(){o.doCancel()}}}),n.resolve(r);var l,m,f,u;l||(l=a.findModeByMIME(o.file.mime)),!l&&(m=o.file.name.match(/.+\.([^.]+)$/))&&(l=a.findModeByExtension(m[1])),l&&(a.modeURL=i?"codemirror/mode/%N/%N.min":t+"/mode/%N/%N.min.js",f=l.mode,u=l.mime,r.setOption("mode",u),a.autoLoadMode(r,f),d.prev().children(".elfinder-dialog-title").append(" ("+u+" : "+f+")")),c=$(r.getWrapperElement()).css({padding:0,border:"none"}),s.data("cm",!0),c.height("100%"),$('<div class="ui-dialog-buttonset"/>').css("float","left").append($("<button/>").html(o.fm.i18n("TextArea")).button().on("click",function(){s.data("cm")?(s.removeData("cm"),c.hide(),s.val(r.getValue()).show().focus(),$(this).text("CodeMirror")):(s.data("cm",!0),c.show(),r.setValue(s.hide().val()),r.refresh(),r.focus(),$(this).html(o.fm.i18n("TextArea")))})).prependTo(d.next())};return o.confObj.loader||(o.confObj.loader=$.Deferred(),i?(require.config({packages:[{name:"codemirror",location:t,main:"codemirror.min"}],map:{codemirror:{"codemirror/lib/codemirror":"codemirror"}}}),require(["codemirror","codemirror/addon/mode/loadmode.min","codemirror/mode/meta.min"],function(e){o.confObj.loader.resolve(e)})):o.fm.loadScript([t+"/codemirror.min.js"],function(){o.fm.loadScript([t+"/addon/mode/loadmode.min.js",t+"/mode/meta.min.js"],function(){o.confObj.loader.resolve(CodeMirror)})},{loadType:"tag"}),o.fm.loadCss(t+"/codemirror.css")),o.confObj.loader.done(a),n},close:function(e,t){t&&t.toTextArea()},save:function(e,t){t&&$(e).data("cm")&&(e.value=t.getValue())},focus:function(e,t){t&&$(e).data("cm")&&t.focus()},resize:function(e,t,i,n){t&&t.refresh()}},{setup:function(e,t){t.UA.ltIE10&&(this.disabled=!0)},info:{name:"SimpleMDE",iconImg:"img/edit_simplemde.png"},exts:["md"],load:function(e){var t=this,n=$(e).parent(),o=$.Deferred(),a=this.fm.options.cdns.simplemde,r=function(t){var i,a,r=n.height(),c=n.outerHeight(!0)-r+14;e._setHeight=function(e){var t,e=e||n.height(),o=0;return n.children(".editor-toolbar,.editor-statusbar").each(function(){o+=$(this).outerHeight(!0)}),t=e-o-c,a.height(t),i.codemirror.refresh(),t},n.height(r),i=new t({element:e,autofocus:!0}),o.resolve(i),a=$(i.codemirror.getWrapperElement()),a.css("min-height","50px").children(".CodeMirror-scroll").css("min-height","50px"),e._setHeight(r)};return t.confObj.loader||(t.confObj.loader=$.Deferred(),t.fm.loadCss(a+"/simplemde.min.css"),i?require([a+"/simplemde.min.js"],function(e){t.confObj.loader.resolve(e)}):t.fm.loadScript([a+"/simplemde.min.js"],function(){t.confObj.loader.resolve(SimpleMDE)},{loadType:"tag"})),t.confObj.loader.done(r),o},close:function(e,t){t&&t.toTextArea(),t=null},save:function(e,t){t&&(e.value=t.value())},focus:function(e,t){t&&t.codemirror.focus()},resize:function(e,t,i,n){t&&e._setHeight()}},{info:{name:"CKEditor",iconImg:"img/edit_ckeditor.png"},exts:["htm","html","xhtml"],setup:function(e,t){e.extraOptions&&e.extraOptions.managerUrl&&(this.managerUrl=e.extraOptions.managerUrl)},load:function(e){var t=this,i=this.fm,n=$.Deferred(),o=function(){var o=$(e).parent(),a=o.closest(".elfinder-dialog"),r=o.height(),c=/([&?]getfile=)[^&]+/,s=t.confObj.managerUrl||window.location.href.replace(/#.*$/,""),d="ckeditor";c.test(s)?s=s.replace(c,"$1"+d):s+="?getfile="+d,o.height(r),CKEDITOR.replace(e.id,{startupFocus:!0,fullPage:!0,allowedContent:!0,filebrowserBrowseUrl:s,removePlugins:"resize",on:{instanceReady:function(o){var c=o.editor;c.resize("100%",r),a.one("beforedommove."+i.namespace,function(){c.destroy()}).one("dommove."+i.namespace,function(){t.load(e).done(function(e){t.instance=e})}),n.resolve(o.editor)}}}),CKEDITOR.on("dialogDefinition",function(e){var t=e.data.definition.dialog;t.on("show",function(e){i.getUI().append($(".cke_dialog_background_cover")).append(this.getElement().$)}),t.on("hide",function(e){$("body:first").append($(".cke_dialog_background_cover")).append(this.getElement().$)})})};return t.confObj.loader||(t.confObj.loader=$.Deferred(),$.getScript(i.options.cdns.ckeditor+"/ckeditor.js",function(){t.confObj.loader.resolve()})),t.confObj.loader.done(o),n},close:function(e,t){t&&t.destroy()},save:function(e,t){t&&(e.value=t.getData())},focus:function(e,t){t&&t.focus()},resize:function(e,t,i,n){t&&"ready"===t.status&&t.resize("100%",$(e).parent().height())}},{info:{name:"TinyMCE",iconImg:"img/edit_tinymce.png"},exts:["htm","html","xhtml"],setup:function(e,t){e.extraOptions&&e.extraOptions.managerUrl&&(this.managerUrl=e.extraOptions.managerUrl)},load:function(e){var t=this,i=this.fm,n=$.Deferred(),o=function(){var o=$(e).parent(),a=o.closest(".elfinder-dialog"),r=o.height(),c=o.outerHeight(!0)-r;o.height(r),e._setHeight=function(e){var t,i=$(this).parent(),e=e||i.height(),n=0;return i.find(".mce-container-body:first").children(".mce-toolbar,.mce-toolbar-grp,.mce-statusbar").each(function(){n+=$(this).outerHeight(!0)}),t=e-n-c,i.find(".mce-edit-area iframe:first").height(t),t},tinymce.init({selector:"#"+e.id,resize:!1,plugins:["fullpage","image","link","media","code","fullscreen"],init_instance_callback:function(o){e._setHeight(r),a.one("beforedommove."+i.namespace,function(){tinymce.execCommand("mceRemoveEditor",!1,e.id)}).one("dommove."+i.namespace,function(){t.load(e).done(function(e){t.instance=e})}),n.resolve(o)},file_picker_callback:function(e,i,n){var o=/([&?]getfile=)[^&]+/,a=t.confObj.managerUrl||window.location.href.replace(/#.*$/,""),r="tinymce";return o.test(a)?a=a.replace(o,"$1"+r):a+="?getfile="+r,tinymce.activeEditor.windowManager.open({file:a,title:"elFinder",width:900,height:450,resizable:"yes"},{oninsert:function(t,i){var o,a;o=i.convAbsUrl(t.url),a=t.name+" ("+i.formatSize(t.size)+")","file"==n.filetype&&e(o,{text:a,title:a}),"image"==n.filetype&&e(o,{alt:a}),"media"==n.filetype&&e(o)}}),!1}})};return i.getUI().hasClass("elfinder-fullscreen-native")&&i.exec("fullscreen"),t.confObj.loader||(t.confObj.loader=$.Deferred(),$.getScript(i.options.cdns.tinymce+"/tinymce.min.js",function(){setTimeout(function(){t.confObj.loader.resolve()},0)})),t.confObj.loader.done(o),n},close:function(e,t){t&&tinymce.execCommand("mceRemoveEditor",!1,e.id)},save:function(e,t){t&&t.save()},focus:function(e,t){t&&t.focus()},resize:function(e,t,i,n){t&&e._setHeight()}},{info:{name:"TextArea",useTextAreaEvent:!0},load:function(){},save:function(){}}]},window.elFinder);