123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631 |
- (function(editors, elFinder) {
- if (typeof define === 'function' && define.amd) {
- define(['elfinder'], editors);
- } else if (elFinder) {
- var optEditors = elFinder.prototype._options.commandsOptions.edit.editors;
- elFinder.prototype._options.commandsOptions.edit.editors = optEditors.concat(editors(elFinder));
- }
- }(function(elFinder) {
- "use strict";
- var apps = {},
- // get query of getfile
- getfile = window.location.search.match(/getfile=([a-z]+)/),
- useRequire = elFinder.prototype.hasRequire,
- hasFlash = (function() {
- var hasFlash;
- try {
- hasFlash = !!(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
- } catch (e) {
- hasFlash = !!(typeof window.orientation === 'undefined' || (navigator && navigator.mimeTypes["application/x-shockwave-flash"]));
- }
- return hasFlash;
- })(),
- ext2mime = {
- bmp: 'image/x-ms-bmp',
- dng: 'image/x-adobe-dng',
- gif: 'image/gif',
- jpeg: 'image/jpeg',
- jpg: 'image/jpeg',
- pdf: 'application/pdf',
- png: 'image/png',
- ppm: 'image/x-portable-pixmap',
- psd: 'image/vnd.adobe.photoshop',
- pxd: 'image/x-pixlr-data',
- svg: 'image/svg+xml',
- tiff: 'image/tiff',
- webp: 'image/webp',
- xcf: 'image/x-xcf',
- sketch: 'application/x-sketch'
- },
- mime2ext,
- getExtention = function(mime, fm) {
- if (!mime2ext) {
- mime2ext = fm.arrayFlip(ext2mime);
- }
- var ext = mime2ext[mime] || fm.mimeTypes[mime];
- if (ext === 'jpeg') {
- ext = 'jpg';
- }
- return ext;
- },
- initImgTag = function(id, file, content, fm) {
- var node = $(this).children('img:first').data('ext', getExtention(file.mime, fm)),
- spnr = $('<div class="elfinder-edit-spinner elfinder-edit-image"/>')
- .html('<span class="elfinder-spinner-text">' + fm.i18n('ntfloadimg') + '</span><span class="elfinder-spinner"/>')
- .hide()
- .appendTo(this);
-
- node.attr('id', id+'-img')
- .attr('src', content)
- .css({'height':'', 'max-width':'100%', 'max-height':'100%', 'cursor':'pointer'})
- .data('loading', function(done) {
- var btns = node.closest('.elfinder-dialog').find('button,.elfinder-titlebar-button');
- btns.prop('disabled', !done)[done? 'removeClass' : 'addClass']('ui-state-disabled');
- node.css('opacity', done? '' : '0.3');
- spnr[done? 'hide' : 'show']();
- return node;
- });
- },
- imgBase64 = function(node, mime) {
- var style = node.attr('style'),
- img, canvas, ctx, data;
- try {
- // reset css for getting image size
- node.attr('style', '');
- // img node
- img = node.get(0);
- // New Canvas
- canvas = document.createElement('canvas');
- canvas.width = img.width;
- canvas.height = img.height;
- // restore css
- node.attr('style', style);
- // Draw Image
- canvas.getContext('2d').drawImage(img, 0, 0);
- // To Base64
- data = canvas.toDataURL(mime);
- } catch(e) {
- data = node.attr('src');
- }
- return data;
- },
- pixlrCallBack = function() {
- if (!hasFlash || window.parent === window) {
- return;
- }
- var pixlr = window.location.search.match(/[?&]pixlr=([^&]+)/),
- image = window.location.search.match(/[?&]image=([^&]+)/),
- p, ifm, url, node, ext;
- if (pixlr) {
- // case of redirected from pixlr.com
- p = window.parent;
- ifm = p.$('#'+pixlr[1]+'iframe').hide();
- node = p.$('#'+pixlr[1]).data('resizeoff')();
- if (image[1].substr(0, 4) === 'http') {
- url = image[1];
- ext = url.replace(/.+\.([^.]+)$/, '$1');
- if (node.data('ext') !== ext) {
- node.closest('.ui-dialog').trigger('changeType', {
- extention: ext,
- mime : ext2mime[ext]
- });
- }
- if (window.location.protocol === 'https:') {
- url = url.replace(/^http:/, 'https:');
- }
- node.on('load error', function() {
- node.data('loading')(true);
- })
- .attr('src', url)
- .data('loading')();
- } else {
- node.data('loading')(true);
- }
- ifm.trigger('destroy').remove();
- }
- },
- pixlrSetup = function(opts, fm) {
- if (!hasFlash || fm.UA.ltIE8) {
- this.disabled = true;
- }
- },
- pixlrLoad = function(mode, base) {
- var self = this,
- fm = this.fm,
- clPreventBack = fm.res('class', 'preventback'),
- node = $(base).children('img:first')
- .data('loading')()
- .data('resizeoff', function() {
- $(window).off('resize.'+node.attr('id'));
- dialog.addClass(clPreventBack);
- return node;
- })
- .on('click', function() {
- launch();
- }),
- dialog = $(base).closest('.ui-dialog'),
- elfNode = fm.getUI(),
- uiToast = fm.getUI('toast'),
- container = $('<iframe class="ui-front" allowtransparency="true">'),
- file = this.file,
- timeout = 15,
- error = function(error) {
- if (error) {
- container.trigger('destroy').remove();
- node.data('loading')(true);
- fm.error(error);
- } else {
- uiToast.appendTo(dialog.closest('.ui-dialog'));
- fm.toast({
- mode: 'info',
- msg: 'Can not launch Pixlr yet. Waiting ' + timeout + ' seconds.',
- button: {
- text: 'Abort',
- click: function() {
- container.trigger('destroy').remove();
- node.data('loading')(true);
- }
- },
- onHidden: function() {
- uiToast.children().length === 1 && uiToast.appendTo(fm.getUI());
- }
- });
- errtm = setTimeout(error, timeout * 1000);
- }
- },
- launch = function() {
- var src = 'https://pixlr.com/'+mode+'/?s=c',
- myurl = window.location.href.toString().replace(/#.*$/, ''),
- opts = {};
- errtm = setTimeout(error, timeout * 1000);
- myurl += (myurl.indexOf('?') === -1? '?' : '&') + 'pixlr='+node.attr('id');
- src += '&referrer=elFinder&locktitle=true';
- src += '&exit='+encodeURIComponent(myurl+'&image=0');
- src += '&target='+encodeURIComponent(myurl);
- src += '&title='+encodeURIComponent(file.name);
- src += '&image='+encodeURIComponent(node.attr('src'));
-
- opts.src = src;
- opts.css = {
- width: '100%',
- height: $(window).height()+'px',
- position: 'fixed',
- display: 'block',
- backgroundColor: 'transparent',
- border: 'none',
- top: 0,
- right: 0
- };
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: base,
- editorObj: void(0),
- instance: container,
- opts: opts
- });
- container
- .attr('id', node.attr('id')+'iframe')
- .attr('src', opts.src)
- .css(opts.css)
- .one('load', function() {
- errtm && clearTimeout(errtm);
- setTimeout(function() {
- if (container.is(':hidden')) {
- error('Please disable your ad blocker.');
- }
- }, 1000);
- dialog.addClass(clPreventBack);
- fm.toggleMaximize(container, true);
- fm.toFront(container);
- })
- .on('destroy', function() {
- fm.toggleMaximize(container, false);
- })
- .on('error', error)
- .appendTo(elfNode.hasClass('elfinder-fullscreen')? elfNode : 'body');
- },
- errtm;
- $(base).on('saveAsFail', launch);
- launch();
- },
- iframeClose = function(ifm) {
- var $ifm = $(ifm),
- dfd = $.Deferred().always(function() {
- $ifm.off('load', load);
- }),
- ab = 'about:blank',
- chk = function() {
- tm = setTimeout(function() {
- var src;
- try {
- src = base.contentWindow.location.href;
- } catch(e) {
- src = null;
- }
- if (src === ab) {
- dfd.resolve();
- } else if (--cnt > 0){
- chk();
- } else {
- dfd.reject();
- }
- }, 500);
- },
- load = function() {
- tm && clearTimeout(tm);
- dfd.resolve();
- },
- cnt = 20, // 500ms * 20 = 10sec wait
- tm;
- $ifm.one('load', load);
- ifm.src = ab;
- chk();
- return dfd;
- };
-
- // check callback from pixlr
- pixlrCallBack();
-
- // check getfile callback function
- if (getfile) {
- getfile = getfile[1];
- if (getfile === 'ckeditor') {
- elFinder.prototype._options.getFileCallback = function(file, fm) {
- window.opener.CKEDITOR.tools.callFunction((function() {
- var reParam = new RegExp('(?:[\?&]|&)CKEditorFuncNum=([^&]+)', 'i'),
- match = window.location.search.match(reParam);
- return (match && match.length > 1) ? match[1] : '';
- })(), fm.convAbsUrl(file.url));
- fm.destroy();
- window.close();
- };
- } else if (getfile === 'tinymce') {
- elFinder.prototype._options.getFileCallback = function(file, fm) {
- // pass selected file data to TinyMCE
- parent.tinymce.activeEditor.windowManager.getParams().oninsert(file, fm);
- // close popup window
- parent.tinymce.activeEditor.windowManager.close();
- };
- }
- }
-
- // return editors Array
- return [
- {
- // tui.image-editor - https://github.com/nhnent/tui.image-editor
- info : {
- id: 'tuiimgedit',
- name: 'TUI Image Editor',
- iconImg: 'img/editor-icons.png 0 -48',
- dataScheme: true,
- schemeContent: true,
- openMaximized: true,
- canMakeEmpty: false,
- integrate: {
- title: 'TOAST UI Image Editor',
- link: 'http://ui.toast.com/tui-image-editor/'
- }
- },
- // MIME types to accept
- mimes : ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/x-ms-bmp'],
- // HTML of this editor
- html : '<div class="elfinder-edit-imageeditor"><canvas></canvas></div>',
- // called on initialization of elFinder cmd edit (this: this editor's config object)
- setup : function(opts, fm) {
- if (fm.UA.ltIE8 || fm.UA.Mobile) {
- this.disabled = true;
- } else {
- this.opts = Object.assign({}, opts.extraOptions.tuiImgEditOpts || {}, {
- iconsPath : fm.baseUrl + 'img/tui-',
- theme : {}
- });
- if (!fm.isSameOrigin(this.opts.iconsPath)) {
- this.disabled = true;
- fm.debug('warning', 'Setting `commandOptions.edit.extraOptions.tuiImgEditOpts.iconsPath` MUST follow the same origin policy.');
- }
- }
- },
- // Initialization of editing node (this: this editors HTML node)
- init : function(id, file, content, fm) {
- this.data('url', content);
- },
- load : function(base) {
- var self = this,
- fm = this.fm,
- dfrd = $.Deferred(),
- cdns = fm.options.cdns,
- ver = 'v3.2.2',
- init = function(editor) {
- var $base = $(base),
- bParent = $base.parent(),
- opts = self.confObj.opts,
- iconsPath = opts.iconsPath,
- tmpContainer = $('<div class="tui-image-editor-container">').appendTo(bParent),
- tmpDiv = [
- $('<div class="tui-image-editor-submenu"/>').appendTo(tmpContainer),
- $('<div class="tui-image-editor-controls"/>').appendTo(tmpContainer)
- ],
- iEditor = new editor(base, {
- includeUI: {
- loadImage: {
- path: $base.data('url'),
- name: self.file.name
- },
- theme: Object.assign(opts.theme, {
- 'menu.normalIcon.path': iconsPath + 'icon-d.svg',
- 'menu.normalIcon.name': 'icon-d',
- 'menu.activeIcon.path': iconsPath + 'icon-b.svg',
- 'menu.activeIcon.name': 'icon-b',
- 'menu.disabledIcon.path': iconsPath + 'icon-a.svg',
- 'menu.disabledIcon.name': 'icon-a',
- 'menu.hoverIcon.path': iconsPath + 'icon-c.svg',
- 'menu.hoverIcon.name': 'icon-c',
- 'submenu.normalIcon.path': iconsPath + 'icon-d.svg',
- 'submenu.normalIcon.name': 'icon-d',
- 'submenu.activeIcon.path': iconsPath + 'icon-c.svg',
- 'submenu.activeIcon.name': 'icon-c'
- }),
- initMenu: 'filter',
- menuBarPosition: 'bottom'
- },
- cssMaxWidth: Math.max(300, bParent.width()),
- cssMaxHeight: Math.max(200, bParent.height() - (tmpDiv[0].height() + tmpDiv[1].height() + 3 /*margin*/)),
- usageStatistics: false
- }),
- canvas = $base.find('canvas:first').get(0),
- zoom = function(v) {
- var c = $(canvas),
- w = parseInt(c.attr('width')),
- h = parseInt(c.attr('height')),
- a = w / h,
- mw, mh, css;
- if (v === 0) {
- mw = w;
- mh = h;
- } else {
- mw = parseInt(c.css('max-width')) + Number(v);
- mh = mw / a;
- }
- css = {
- maxWidth: mw,
- maxHeight: mh
- };
- per.text(Math.round(mw / w * 100) + '%');
- if (typeof v !== 'undefined') {
- // set editor config directly for change scale
- iEditor._graphics.cssMaxWidth = mw;
- iEditor._graphics.cssMaxHeight = mh;
- // change scale
- c.css(css).next().css(css);
- c.parents('.tui-image-editor-canvas-container,tui-image-editor-canvas').css(css);
- c.closest('.tui-image-editor').css({
- width: mw,
- height: mh
- });
- // continually change more
- if (zoomMore) {
- setTimeout(function() {
- zoomMore && zoom(v);
- }, 50);
- }
- }
- },
- zup = $('<span class="ui-icon ui-icon-plusthick"/>').data('val', 10),
- zdown = $('<span class="ui-icon ui-icon-minusthick"/>').data('val', -10),
- per = $('<button/>').css('width', '4em').text('%').attr('title', '100%').data('val', 0),
- quty, qutyTm, zoomTm, zoomMore;
- tmpContainer.remove();
- $base.removeData('url').data('mime', self.file.mime);
- // jpeg quality controls
- if (self.file.mime === 'image/jpeg') {
- $base.data('quality', fm.storage('jpgQuality') || fm.option('jpgQuality'));
- quty = $('<input type="number" class="ui-corner-all elfinder-resize-quality elfinder-tabstop"/>')
- .attr('min', '1')
- .attr('max', '100')
- .attr('title', '1 - 100')
- .on('change', function() {
- var q = quty.val();
- $base.data('quality', q);
- qutyTm && cancelAnimationFrame(qutyTm);
- qutyTm = requestAnimationFrame(function() {
- canvas.toBlob(function(blob) {
- blob && quty.next('span').text(' (' + fm.formatSize(blob.size) + ')');
- }, 'image/jpeg', Math.max(Math.min(q, 100), 1) / 100);
- });
- })
- .val($base.data('quality'));
- $('<div class="ui-dialog-buttonset elfinder-edit-extras elfinder-edit-extras-quality"/>')
- .append(
- $('<span>').html(fm.i18n('quality') + ' : '), quty, $('<span/>')
- )
- .prependTo($base.parent().next());
- } else if (self.file.mime === 'image/svg+xml') {
- $base.closest('.ui-dialog').trigger('changeType', {
- extention: 'png',
- mime : 'image/png',
- keepEditor: true
- });
- }
- // zoom scale controls
- $('<div class="ui-dialog-buttonset elfinder-edit-extras"/>')
- .append(
- zdown, per, zup
- )
- .attr('title', fm.i18n('scale'))
- .on('click', 'span,button', function() {
- zoom($(this).data('val'));
- })
- .on('mousedown mouseup mouseleave', 'span', function(e) {
- zoomMore = false;
- zoomTm && clearTimeout(zoomTm);
- if (e.type === 'mousedown') {
- zoomTm = setTimeout(function() {
- zoomMore = true;
- zoom($(e.target).data('val'));
- }, 500);
- }
- })
- .prependTo($base.parent().next());
- // wait canvas ready
- setTimeout(function() {
- dfrd.resolve(iEditor);
- if (quty) {
- quty.trigger('change');
- iEditor.on('redoStackChanged undoStackChanged', function() {
- quty.trigger('change');
- });
- }
- // show initial scale
- zoom(null);
- }, 100);
- },
- loader;
- if (!self.confObj.editor) {
- loader = $.Deferred();
- fm.loadCss([
- cdns.tui + '/tui-color-picker/latest/tui-color-picker.css',
- cdns.tui + '/tui-image-editor/'+ver+'/tui-image-editor.css'
- ]);
- if (fm.hasRequire) {
- require.config({
- paths : {
- 'fabric/dist/fabric.require' : cdns.fabric16 + '/fabric.require.min',
- 'tui-code-snippet' : cdns.tui + '/tui.code-snippet/latest/tui-code-snippet.min',
- 'tui-color-picker' : cdns.tui + '/tui.code-snippet/latest/tui-color-picker.min',
- 'tui-image-editor' : cdns.tui + '/tui-image-editor/'+ver+'/tui-image-editor.min'
- }
- });
- require(['tui-image-editor'], function(ImageEditor) {
- loader.resolve(ImageEditor);
- });
- } else {
- fm.loadScript([
- cdns.fabric16 + '/fabric.min.js',
- cdns.tui + '/tui.code-snippet/latest/tui-code-snippet.min.js'
- ], function() {
- fm.loadScript([
- cdns.tui + '/tui-color-picker/latest/tui-color-picker.min.js'
- ], function() {
- fm.loadScript([
- cdns.tui + '/tui-image-editor/'+ver+'/tui-image-editor.min.js'
- ], function() {
- loader.resolve(window.tui.ImageEditor);
- }, {
- loadType: 'tag'
- });
- }, {
- loadType: 'tag'
- });
- }, {
- loadType: 'tag'
- });
- }
- loader.done(function(editor) {
- self.confObj.editor = editor;
- init(editor);
- });
- } else {
- init(self.confObj.editor);
- }
- return dfrd;
- },
- getContent : function(base) {
- var editor = this.editor,
- fm = editor.fm,
- $base = $(base),
- quality = $base.data('quality');
- if (editor.instance) {
- if ($base.data('mime') === 'image/jpeg') {
- quality = quality || fm.storage('jpgQuality') || fm.option('jpgQuality');
- quality = Math.max(0.1, Math.min(1, quality / 100));
- }
- return editor.instance.toDataURL({
- format: getExtention($base.data('mime'), fm),
- quality: quality
- });
- }
- },
- save : function(base) {
- var $base = $(base),
- quality = $base.data('quality'),
- hash = $base.data('hash'),
- file;
- this.instance.deactivateAll();
- if (typeof quality !== 'undefined') {
- this.fm.storage('jpgQuality', quality);
- }
- if (hash) {
- file = this.fm.file(hash);
- $base.data('mime', file.mime);
- }
- }
- },
- {
- // Pixlr Editor
- info : {
- id : 'pixlreditor',
- name : 'Pixlr Editor',
- iconImg : 'img/editor-icons.png 0 -128',
- urlAsContent: true,
- schemeContent: true,
- single: true,
- canMakeEmpty: true,
- integrate: {
- title: 'PIXLR EDITOR',
- link: 'https://pixlr.com/editor/'
- }
- },
- // MIME types to accept
- mimes : ['image/jpeg', 'image/png', 'image/gif', 'image/x-ms-bmp', 'image/x-pixlr-data'],
- // HTML of this editor
- html : '<div class="elfinder-edit-imageeditor"><img/></div>',
- // called on initialization of elFinder cmd edit (this: this editor's config object)
- setup : function(opts, fm) {
- pixlrSetup.call(this, opts, fm);
- },
- // Initialization of editing node (this: this editors HTML node)
- init : function(id, file, url, fm) {
- initImgTag.call(this, id, file, file.size > 0? fm.convAbsUrl(url) : '', fm);
- },
- // Get data uri scheme (this: this editors HTML node)
- getContent : function() {
- return $(this).children('img:first').attr('src');
- },
- load : function(base) {
- pixlrLoad.call(this, 'editor', base);
- },
- save : function(base) {},
- close : function(base) {}
- },
- {
- // Pixlr Express
- info : {
- id: 'pixlrexpress',
- name : 'Pixlr Express',
- iconImg : 'img/editor-icons.png 0 -112',
- urlAsContent: true,
- schemeContent: true,
- single: true,
- canMakeEmpty: false,
- integrate: {
- title: 'PIXLR EXPRESS',
- link: 'https://pixlr.com/express/'
- }
- },
- // MIME types to accept
- mimes : ['image/jpeg', 'image/png', 'image/gif'],
- // HTML of this editor
- html : '<div class="elfinder-edit-imageeditor"><img/></div>',
- // called on initialization of elFinder cmd edit (this: this editor's config object)
- setup : function(opts, fm) {
- pixlrSetup.call(this, opts, fm);
- },
- // Initialization of editing node (this: this editors HTML node)
- init : function(id, file, url, fm) {
- initImgTag.call(this, id, file, file.size > 0? fm.convAbsUrl(url) : '', fm);
- },
- // Get data uri scheme (this: this editors HTML node)
- getContent : function() {
- return $(this).children('img:first').attr('src');
- },
- load : function(base) {
- pixlrLoad.call(this, 'express', base);
- },
- save : function(base) {},
- close : function(base) {}
- },
- {
- // Photopea advanced image editor
- info : {
- id : 'photopea',
- name : 'Photopea',
- iconImg : 'img/editor-icons.png 0 -160',
- single: true,
- urlAsContent: true,
- arrayBufferContent: true,
- openMaximized: true,
- canMakeEmpty: true,
- integrate: {
- title: 'Photopea',
- link: 'https://www.photopea.com/learn/'
- }
- },
- mimes : ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/x-ms-bmp', 'image/tiff', 'image/x-adobe-dng', 'image/webp', 'image/x-xcf', 'image/vnd.adobe.photoshop', 'application/pdf', 'image/x-portable-pixmap', 'image/x-sketch'],
- html : '<iframe style="width:100%;height:100%;border:none;"></iframe>',
- // setup on elFinder bootup
- setup : function(opts, fm) {
- if (fm.UA.IE || fm.UA.Mobile) {
- this.disabled = true;
- }
- },
- // Initialization of editing node (this: this editors HTML node)
- init : function(id, file, dum, fm) {
- var orig = 'https://www.photopea.com',
- ifm = $(this).hide()
- //.css('box-sizing', 'border-box')
- .on('load', function() {
- //spnr.remove();
- ifm.show();
- })
- .on('error', function() {
- spnr.remove();
- ifm.show();
- }),
- editor = this.editor,
- confObj = editor.confObj,
- spnr = $('<div class="elfinder-edit-spinner elfinder-edit-photopea"/>')
- .html('<span class="elfinder-spinner-text">' + fm.i18n('nowLoading') + '</span><span class="elfinder-spinner"/>')
- .appendTo(ifm.parent()),
- getType = function(mime) {
- var ext = getExtention(mime, fm),
- extmime = ext2mime[ext];
- if (!confObj.mimesFlip[extmime]) {
- ext = '';
- } else if (ext === 'jpeg') {
- ext = 'jpg';
- }
- if (!ext || ext === 'xcf' || ext === 'dng' || ext === 'sketch') {
- ext = 'psd';
- extmime = ext2mime[ext];
- ifm.closest('.ui-dialog').trigger('changeType', {
- extention: ext,
- mime : extmime,
- keepEditor: true
- });
- }
- return ext;
- },
- mime = file.mime,
- liveMsg, type, quty;
-
- if (!confObj.mimesFlip) {
- confObj.mimesFlip = fm.arrayFlip(confObj.mimes, true);
- }
- if (!confObj.liveMsg) {
- confObj.liveMsg = function(ifm, spnr, file) {
- var url = fm.openUrl(file.hash);
- if (!fm.isSameOrigin(url)) {
- url = fm.openUrl(file.hash, true);
- }
- var wnd = ifm.get(0).contentWindow,
- phase = 0,
- data = null,
- dfdIni = $.Deferred().done(function() {
- spnr.remove();
- phase = 1;
- wnd.postMessage(data, '*');
- }),
- dfdGet;
- this.load = function() {
- return fm.request({
- data : {cmd : 'get'},
- options : {
- url: url,
- type: 'get',
- cache : true,
- dataType : 'binary',
- responseType :'arraybuffer',
- processData: false
- }
- })
- .done(function(d) {
- data = d;
- });
- };
- this.receive = function(e) {
- var ev = e.originalEvent,
- state;
- if (ev.origin === orig && ev.source === wnd) {
- if (ev.data === 'done') {
- if (phase === 0) {
- dfdIni.resolve();
- } else if (phase === 1) {
- phase = 2;
- ifm.trigger('contentsloaded');
- } else {
- if (dfdGet && dfdGet.state() === 'pending') {
- dfdGet.reject('errDataEmpty');
- }
- }
- } else {
- if (dfdGet && dfdGet.state() === 'pending') {
- if (typeof ev.data === 'object') {
- dfdGet.resolve('data:' + mime + ';base64,' + fm.arrayBufferToBase64(ev.data));
- } else {
- dfdGet.reject('errDataEmpty');
- }
- }
- }
- }
- };
- this.getContent = function() {
- var type, q;
- if (phase > 1) {
- dfdGet && dfdGet.state() === 'pending' && dfdGet.reject();
- dfdGet = null;
- dfdGet = $.Deferred();
- if (phase === 2) {
- phase = 3;
- dfdGet.resolve('data:' + mime + ';base64,' + fm.arrayBufferToBase64(data));
- data = null;
- return dfdGet;
- }
- if (ifm.data('mime')) {
- mime = ifm.data('mime');
- type = getType(mime);
- }
- if (q = ifm.data('quality')) {
- type += ':' + (q / 100);
- }
- wnd.postMessage('app.activeDocument.saveToOE("' + type + '")', orig);
- return dfdGet;
- }
- };
- };
- }
- ifm.parent().css('padding', 0);
- type = getType(file.mime);
- liveMsg = editor.liveMsg = new confObj.liveMsg(ifm, spnr, file);
- $(window).on('message.' + fm.namespace, liveMsg.receive);
- liveMsg.load().done(function() {
- var d = JSON.stringify({
- files : [],
- environment : {
- lang: fm.lang.replace(/_/g, '-')
- }
- });
- ifm.attr('src', orig + '/#' + encodeURI(d));
- }).fail(function(err) {
- err && fm.error(err);
- editor.initFail = true;
- });
- // jpeg quality controls
- if (file.mime === 'image/jpeg' || file.mime === 'image/webp') {
- ifm.data('quality', fm.storage('jpgQuality') || fm.option('jpgQuality'));
- quty = $('<input type="number" class="ui-corner-all elfinder-resize-quality elfinder-tabstop"/>')
- .attr('min', '1')
- .attr('max', '100')
- .attr('title', '1 - 100')
- .on('change', function() {
- var q = quty.val();
- ifm.data('quality', q);
- })
- .val(ifm.data('quality'));
- $('<div class="ui-dialog-buttonset elfinder-edit-extras elfinder-edit-extras-quality"/>')
- .append(
- $('<span>').html(fm.i18n('quality') + ' : '), quty, $('<span/>')
- )
- .prependTo(ifm.parent().next());
- }
- },
- load : function(base) {
- var dfd = $.Deferred(),
- self = this,
- fm = this.fm,
- $base = $(base);
- if (self.initFail) {
- dfd.reject();
- } else {
- $base.on('contentsloaded', function() {
- dfd.resolve(self.liveMsg);
- });
- }
- return dfd;
- },
- getContent : function() {
- return this.editor.liveMsg? this.editor.liveMsg.getContent() : void(0);
- },
- save : function(base, liveMsg) {
- var $base = $(base),
- quality = $base.data('quality'),
- hash = $base.data('hash'),
- file;
- if (typeof quality !== 'undefined') {
- this.fm.storage('jpgQuality', quality);
- }
- if (hash) {
- file = this.fm.file(hash);
- $base.data('mime', file.mime);
- } else {
- $base.removeData('mime');
- }
- },
- // On dialog closed
- close : function(base, liveMsg) {
- $(base).attr('src', '');
- liveMsg && $(window).off('message.' + this.fm.namespace, liveMsg.receive);
- }
- },
- {
- // Adobe Creative SDK Creative Tools Image Editor UI
- // MIME types to accept
- info : {
- id : 'creativecloud',
- name : 'Creative Cloud',
- iconImg : 'img/editor-icons.png 0 -192',
- dataScheme: true,
- schemeContent: true,
- single: true,
- canMakeEmpty: false,
- integrate: {
- title: 'Adobe Creative Cloud',
- link: 'https://www.adobe.io/apis/creativecloud.html'
- }
- },
- mimes : ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/x-ms-bmp'],
- // HTML of this editor
- html : '<div class="elfinder-edit-imageeditor"><img/></div>',
- // called on initialization of elFinder cmd edit (this: this editor's config object)
- setup : function(opts, fm) {
- if (fm.UA.ltIE8 || !opts.extraOptions || !opts.extraOptions.creativeCloudApiKey) {
- this.disabled = true;
- } else {
- this.apiKey = opts.extraOptions.creativeCloudApiKey;
- }
- },
- // Initialization of editing node (this: this editors HTML node)
- init : function(id, file, content, fm) {
- initImgTag.call(this, id, file, content, fm);
- },
- // Get data uri scheme (this: this editors HTML node)
- getContent : function() {
- return $(this).children('img:first').attr('src');
- },
- // Launch Aviary Feather editor when dialog open
- load : function(base) {
- var self = this,
- fm = this.fm,
- node = $(base).children('img:first'),
- dialog = $(base).closest('.ui-dialog'),
- elfNode = fm.getUI(),
- dfrd = $.Deferred(),
- container = $('#elfinder-aviary-container'),
- init = function(onload) {
- var getLang = function() {
- var langMap = {
- 'zh_TW' : 'zh_HANT',
- 'zh_CN' : 'zh_HANS'
- };
- return langMap[fm.lang]? langMap[fm.lang] : fm.lang;
- }, opts;
-
- if (!container.length) {
- container = $('<div id="elfinder-aviary-container" class="ui-front"/>').css({
- position: 'fixed',
- top: 0,
- right: 0,
- width: '100%',
- height: $(window).height(),
- overflow: 'auto'
- }).hide().appendTo(elfNode.hasClass('elfinder-fullscreen')? elfNode : 'body');
- // bind switch fullscreen event
- elfNode.on('resize.'+fm.namespace, function(e, data) {
- e.preventDefault();
- e.stopPropagation();
- data && data.fullscreen && container.appendTo(data.fullscreen === 'on'? elfNode : 'body');
- });
- fm.bind('destroy', function() {
- container.remove();
- });
- } else {
- // always moves to last
- container.appendTo(container.parent());
- }
- node.on('click', launch).data('loading')();
- opts = {
- apiKey: self.confObj.apiKey,
- onSave: function(imageID, newURL) {
- var ext;
- featherEditor.showWaitIndicator();
- ext = newURL.replace(/.+\.([^.]+)$/, '$1');
- if (node.data('ext') !== ext) {
- node.closest('.ui-dialog').trigger('changeType', {
- extention: ext,
- mime : ext2mime[ext]
- });
- }
- node.on('load error', function() {
- node.data('loading')(true);
- })
- .attr('crossorigin', 'anonymous')
- .attr('src', newURL)
- .data('loading')();
- featherEditor.close();
- },
- onLoad: onload || function(){},
- onClose: function() {
- dialog.removeClass(fm.res('class', 'preventback'));
- fm.toggleMaximize(container, false);
- $(container).hide();
- },
- appendTo: container.get(0),
- maxSize: 2048,
- language: getLang()
- };
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: base,
- editorObj: Aviary,
- instance: void(0),
- opts: opts
- });
- featherEditor = new Aviary.Feather(opts);
- // return editor instance
- dfrd.resolve(featherEditor);
- $(base).on('saveAsFail', launch);
- },
- launch = function() {
- dialog.addClass(fm.res('class', 'preventback'));
- fm.toggleMaximize(container, true);
- fm.toFront(container);
- $(container).show();
- featherEditor.launch({
- image: node.attr('id'),
- url: node.attr('src')
- });
- node.data('loading')(true);
- },
- featherEditor, extraOpts;
-
- // load script then init
- if (typeof Aviary === 'undefined') {
- fm.loadScript(['https://dme0ih8comzn4.cloudfront.net/imaging/v3/editor.js'], function() {
- init(launch);
- }, {loadType: 'tag'});
- } else {
- init();
- launch();
- }
- return dfrd;
- },
- // Convert content url to data uri scheme to save content
- save : function(base) {
- var node = $(base).children('img:first');
- if (node.attr('src').substr(0, 5) !== 'data:') {
- node.attr('src', imgBase64(node, this.file.mime));
- }
- }
- },
- {
- // ACE Editor
- // called on initialization of elFinder cmd edit (this: this editor's config object)
- setup : function(opts, fm) {
- if (fm.UA.ltIE8 || !fm.options.cdns.ace) {
- this.disabled = true;
- }
- },
- // `mimes` is not set for support everything kind of text file
- info : {
- id : 'aceeditor',
- name : 'ACE Editor',
- iconImg : 'img/editor-icons.png 0 -96'
- },
- load : function(textarea) {
- var self = this,
- fm = this.fm,
- dfrd = $.Deferred(),
- cdn = fm.options.cdns.ace,
- start = function() {
- var editor, editorBase, mode,
- ta = $(textarea),
- taBase = ta.parent(),
- dialog = taBase.parent(),
- id = textarea.id + '_ace',
- ext = self.file.name.replace(/^.+\.([^.]+)|(.+)$/, '$1$2').toLowerCase(),
- // MIME/mode map
- mimeMode = {
- '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'
- };
- // set base height
- taBase.height(taBase.height());
- // set basePath of ace
- ace.config.set('basePath', cdn);
- // Base node of Ace editor
- editorBase = $('<div id="'+id+'" style="width:100%; height:100%;"/>').text(ta.val()).insertBefore(ta.hide());
- // Editor flag
- ta.data('ace', true);
- // Aceeditor instance
- editor = ace.edit(id);
- // Ace editor configure
- editor.$blockScrolling = Infinity;
- editor.setOptions({
- theme: 'ace/theme/monokai',
- fontSize: '14px',
- wrap: true,
- });
- ace.config.loadModule('ace/ext/modelist', function() {
- // detect mode
- mode = ace.require('ace/ext/modelist').getModeForPath('/' + self.file.name).name;
- if (mode === 'text') {
- if (mimeMode[self.file.mime]) {
- mode = mimeMode[self.file.mime];
- }
- }
- // show MIME:mode in title bar
- taBase.prev().children('.elfinder-dialog-title').append(' (' + self.file.mime + ' : ' + mode.split(/[\/\\]/).pop() + ')');
- editor.setOptions({
- mode: 'ace/mode/' + mode
- });
- if (dfrd.state() === 'resolved') {
- dialog.trigger('resize');
- }
- });
- ace.config.loadModule('ace/ext/language_tools', function() {
- ace.require('ace/ext/language_tools');
- editor.setOptions({
- enableBasicAutocompletion: true,
- enableSnippets: true,
- enableLiveAutocompletion: false
- });
- });
- ace.config.loadModule('ace/ext/settings_menu', function() {
- ace.require('ace/ext/settings_menu').init(editor);
- });
-
- // Short cuts
- editor.commands.addCommand({
- name : "saveFile",
- bindKey: {
- win : 'Ctrl-s',
- mac : 'Command-s'
- },
- exec: function(editor) {
- self.doSave();
- }
- });
- editor.commands.addCommand({
- name : "closeEditor",
- bindKey: {
- win : 'Ctrl-w|Ctrl-q',
- mac : 'Command-w|Command-q'
- },
- exec: function(editor) {
- self.doCancel();
- }
- });
- editor.resize();
- // TextArea button and Setting button
- $('<div class="ui-dialog-buttonset"/>').css('float', 'left')
- .append(
- $('<button/>').html(self.fm.i18n('TextArea'))
- .button()
- .on('click', function(){
- if (ta.data('ace')) {
- ta.removeData('ace');
- editorBase.hide();
- ta.val(editor.session.getValue()).show().trigger('focus');
- $(this).text('AceEditor');
- } else {
- ta.data('ace', true);
- editorBase.show();
- editor.setValue(ta.hide().val(), -1);
- editor.focus();
- $(this).html(self.fm.i18n('TextArea'));
- }
- })
- )
- .append(
- $('<button>Ace editor setting</button>')
- .button({
- icons: {
- primary: 'ui-icon-gear',
- secondary: 'ui-icon-triangle-1-e'
- },
- text: false
- })
- .on('click', function(){
- editor.showSettingsMenu();
- $('#ace_settingsmenu')
- .css('font-size', '80%')
- .find('div[contains="setOptions"]').hide().end()
- .parent().parent().appendTo($('#elfinder'));
- })
- )
- .prependTo(taBase.next());
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: textarea,
- editorObj: ace,
- instance: editor,
- opts: {}
- });
-
- //dialog.trigger('resize');
- dfrd.resolve(editor);
- };
- // check ace & start
- if (!self.confObj.loader) {
- self.confObj.loader = $.Deferred();
- self.fm.loadScript([ cdn+'/ace.js' ], function() {
- self.confObj.loader.resolve();
- }, void 0, {obj: window, name: 'ace'});
- }
- self.confObj.loader.done(start);
- return dfrd;
- },
- close : function(textarea, instance) {
- instance && instance.destroy();
- },
- save : function(textarea, instance) {
- instance && $(textarea).data('ace') && (textarea.value = instance.session.getValue());
- },
- focus : function(textarea, instance) {
- instance && $(textarea).data('ace') && instance.focus();
- },
- resize : function(textarea, instance, e, data) {
- instance && instance.resize();
- }
- },
- {
- // CodeMirror
- // called on initialization of elFinder cmd edit (this: this editor's config object)
- setup : function(opts, fm) {
- if (fm.UA.ltIE10 || !fm.options.cdns.codemirror) {
- this.disabled = true;
- }
- },
- // `mimes` is not set for support everything kind of text file
- info : {
- id : 'codemirror',
- name : 'CodeMirror',
- iconImg : 'img/editor-icons.png 0 -176'
- },
- load : function(textarea) {
- var fm = this.fm,
- cmUrl = fm.options.cdns.codemirror,
- dfrd = $.Deferred(),
- self = this,
- start = function(CodeMirror) {
- var ta = $(textarea),
- base = ta.parent(),
- editor, editorBase, opts;
-
- // set base height
- base.height(base.height());
-
- // CodeMirror configure options
- opts = {
- lineNumbers: true,
- lineWrapping: true,
- extraKeys : {
- 'Ctrl-S': function() { self.doSave(); },
- 'Ctrl-Q': function() { self.doCancel(); },
- 'Ctrl-W': function() { self.doCancel(); }
- }
- };
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: textarea,
- editorObj: CodeMirror,
- instance: void(0),
- opts: opts
- });
- // CodeMirror configure
- editor = CodeMirror.fromTextArea(textarea, opts);
-
- // return editor instance
- dfrd.resolve(editor);
-
- // Auto mode set
- var info, m, mode, spec;
- if (! info) {
- info = CodeMirror.findModeByMIME(self.file.mime);
- }
- if (! info && (m = self.file.name.match(/.+\.([^.]+)$/))) {
- info = CodeMirror.findModeByExtension(m[1]);
- }
- if (info) {
- CodeMirror.modeURL = useRequire? 'codemirror/mode/%N/%N.min' : cmUrl + '/mode/%N/%N.min.js';
- mode = info.mode;
- spec = info.mime;
- editor.setOption('mode', spec);
- CodeMirror.autoLoadMode(editor, mode);
- // show MIME:mode in title bar
- base.prev().children('.elfinder-dialog-title').append(' (' + spec + ' : ' + mode + ')');
- }
-
- // editor base node
- editorBase = $(editor.getWrapperElement()).css({
- // fix CSS conflict to SimpleMDE
- padding: 0,
- border: 'none'
- });
- ta.data('cm', true);
-
- // fit height to base
- editorBase.height('100%');
-
- // TextArea button and Setting button
- $('<div class="ui-dialog-buttonset"/>').css('float', 'left')
- .append(
- $('<button/>').html(self.fm.i18n('TextArea'))
- .button()
- .on('click', function(){
- if (ta.data('cm')) {
- ta.removeData('cm');
- editorBase.hide();
- ta.val(editor.getValue()).show().trigger('focus');
- $(this).text('CodeMirror');
- } else {
- ta.data('cm', true);
- editorBase.show();
- editor.setValue(ta.hide().val());
- editor.refresh();
- editor.focus();
- $(this).html(self.fm.i18n('TextArea'));
- }
- })
- )
- .prependTo(base.next());
- };
- // load script then start
- if (!self.confObj.loader) {
- self.confObj.loader = $.Deferred();
- if (useRequire) {
- require.config({
- packages: [{
- name: 'codemirror',
- location: cmUrl,
- main: 'codemirror.min'
- }],
- map: {
- 'codemirror': {
- 'codemirror/lib/codemirror': 'codemirror'
- }
- }
- });
- require([
- 'codemirror',
- 'codemirror/addon/mode/loadmode.min',
- 'codemirror/mode/meta.min'
- ], function(CodeMirror) {
- self.confObj.loader.resolve(CodeMirror);
- });
- } else {
- self.fm.loadScript([
- cmUrl + '/codemirror.min.js'
- ], function() {
- self.fm.loadScript([
- cmUrl + '/addon/mode/loadmode.min.js',
- cmUrl + '/mode/meta.min.js'
- ], function() {
- self.confObj.loader.resolve(CodeMirror);
- });
- }, {loadType: 'tag'});
- }
- self.fm.loadCss(cmUrl + '/codemirror.css');
- }
- self.confObj.loader.done(start);
- return dfrd;
- },
- close : function(textarea, instance) {
- instance && instance.toTextArea();
- },
- save : function(textarea, instance) {
- instance && $(textarea).data('cm') && (textarea.value = instance.getValue());
- },
- focus : function(textarea, instance) {
- instance && $(textarea).data('cm') && instance.focus();
- },
- resize : function(textarea, instance, e, data) {
- instance && instance.refresh();
- }
- },
- {
- // SimpleMDE
- // called on initialization of elFinder cmd edit (this: this editor's config object)
- setup : function(opts, fm) {
- if (fm.UA.ltIE10 || !fm.options.cdns.simplemde) {
- this.disabled = true;
- }
- },
- info : {
- id : 'simplemde',
- name : 'SimpleMDE',
- iconImg : 'img/editor-icons.png 0 -80'
- },
- exts : ['md'],
- load : function(textarea) {
- var self = this,
- fm = this.fm,
- base = $(textarea).parent(),
- dfrd = $.Deferred(),
- cdn = fm.options.cdns.simplemde,
- start = function(SimpleMDE) {
- var h = base.height(),
- delta = base.outerHeight(true) - h + 14,
- editor, editorBase, opts;
-
- // fit height function
- textarea._setHeight = function(height) {
- var h = height || base.height(),
- ctrH = 0,
- areaH;
- base.children('.editor-toolbar,.editor-statusbar').each(function() {
- ctrH += $(this).outerHeight(true);
- });
- areaH = h - ctrH - delta;
- editorBase.height(areaH);
- editor.codemirror.refresh();
- return areaH;
- };
-
- // set base height
- base.height(h);
-
- opts = {
- element: textarea,
- autofocus: true
- };
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: textarea,
- editorObj: SimpleMDE,
- instance: void(0),
- opts: opts
- });
- // make editor
- editor = new SimpleMDE(opts);
- dfrd.resolve(editor);
-
- // editor base node
- editorBase = $(editor.codemirror.getWrapperElement());
-
- // fit height to base
- editorBase.css('min-height', '50px')
- .children('.CodeMirror-scroll').css('min-height', '50px');
- textarea._setHeight(h);
- };
- // check SimpleMDE & start
- if (!self.confObj.loader) {
- self.confObj.loader = $.Deferred();
- self.fm.loadCss(cdn+'/simplemde.min.css');
- if (useRequire) {
- require([
- cdn+'/simplemde.min.js'
- ], function(SimpleMDE) {
- self.confObj.loader.resolve(SimpleMDE);
- });
- } else {
- self.fm.loadScript([cdn+'/simplemde.min.js'], function() {
- self.confObj.loader.resolve(SimpleMDE);
- }, {loadType: 'tag'});
- }
- }
- self.confObj.loader.done(start);
- return dfrd;
- },
- close : function(textarea, instance) {
- instance && instance.toTextArea();
- instance = null;
- },
- save : function(textarea, instance) {
- instance && (textarea.value = instance.value());
- },
- focus : function(textarea, instance) {
- instance && instance.codemirror.focus();
- },
- resize : function(textarea, instance, e, data) {
- instance && textarea._setHeight();
- }
- },
- {
- // CKEditor for html file
- info : {
- id : 'ckeditor',
- name : 'CKEditor',
- iconImg : 'img/editor-icons.png 0 0'
- },
- exts : ['htm', 'html', 'xhtml'],
- setup : function(opts, fm) {
- if (!fm.options.cdns.ckeditor) {
- this.disabled = true;
- } else {
- if (opts.extraOptions && opts.extraOptions.managerUrl) {
- this.managerUrl = opts.extraOptions.managerUrl;
- }
- }
- },
- load : function(textarea) {
- var self = this,
- fm = this.fm,
- dfrd = $.Deferred(),
- init = function() {
- var base = $(textarea).parent(),
- dlg = base.closest('.elfinder-dialog'),
- h = base.height(),
- reg = /([&?]getfile=)[^&]+/,
- loc = self.confObj.managerUrl || window.location.href.replace(/#.*$/, ''),
- name = 'ckeditor',
- opts;
-
- // make manager location
- if (reg.test(loc)) {
- loc = loc.replace(reg, '$1' + name);
- } else {
- loc += '?getfile=' + name;
- }
- // set base height
- base.height(h);
- // CKEditor configure options
- opts = {
- startupFocus : true,
- fullPage: true,
- allowedContent: true,
- filebrowserBrowseUrl : loc,
- toolbarCanCollapse: true,
- toolbarStartupExpanded: !fm.UA.Mobile,
- removePlugins: 'resize',
- extraPlugins: 'colorbutton,justify,docprops',
- on: {
- 'instanceReady' : function(e) {
- var editor = e.editor;
- editor.resize('100%', h);
- // re-build on dom move
- dlg.one('beforedommove.'+fm.namespace, function() {
- editor.destroy();
- }).one('dommove.'+fm.namespace, function() {
- self.load(textarea).done(function(editor) {
- self.instance = editor;
- });
- });
- // return editor instance
- dfrd.resolve(e.editor);
- }
- }
- };
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: textarea,
- editorObj: CKEDITOR,
- instance: void(0),
- opts: opts
- });
- // CKEditor configure
- CKEDITOR.replace(textarea.id, opts);
- CKEDITOR.on('dialogDefinition', function(e) {
- var dlg = e.data.definition.dialog;
- dlg.on('show', function(e) {
- fm.getUI().append($('.cke_dialog_background_cover')).append(this.getElement().$);
- });
- dlg.on('hide', function(e) {
- $('body:first').append($('.cke_dialog_background_cover')).append(this.getElement().$);
- });
- });
- };
- if (!self.confObj.loader) {
- self.confObj.loader = $.Deferred();
- window.CKEDITOR_BASEPATH = fm.options.cdns.ckeditor + '/';
- $.getScript(fm.options.cdns.ckeditor + '/ckeditor.js', function() {
- self.confObj.loader.resolve();
- });
- }
- self.confObj.loader.done(init);
- return dfrd;
- },
- close : function(textarea, instance) {
- instance && instance.destroy();
- },
- save : function(textarea, instance) {
- instance && (textarea.value = instance.getData());
- },
- focus : function(textarea, instance) {
- instance && instance.focus();
- },
- resize : function(textarea, instance, e, data) {
- var self;
- if (instance) {
- if (instance.status === 'ready') {
- instance.resize('100%', $(textarea).parent().height());
- }
- }
- }
- },
- {
- // CKEditor5 balloon mode for html file
- info : {
- id : 'ckeditor5',
- name : 'CKEditor5',
- iconImg : 'img/editor-icons.png 0 -16'
- },
- exts : ['htm', 'html', 'xhtml'],
- html : '<div class="edit-editor-ckeditor5"></div>',
- setup : function(opts, fm) {
- var confObj = this;
- // check cdn and ES6 support
- if (!fm.options.cdns.ckeditor5 || typeof window.Symbol !== 'function' || typeof Symbol() !== 'symbol') {
- this.disabled = true;
- } else {
- if (opts.extraOptions && opts.extraOptions.ckeditor5Mode) {
- this.ckeditor5Mode = opts.extraOptions.ckeditor5Mode;
- }
- }
- fm.bind('destroy', function() {
- confObj.editor = null;
- });
- },
- // Prepare on before show dialog
- prepare : function(base, dialogOpts, file) {
- $(base).height(base.editor.fm.getUI().height() - 100);
- },
- init : function(id, file, data, fm) {
- var m = data.match(/^([\s\S]*<body[^>]*>)([\s\S]+)(<\/body>[\s\S]*)$/i),
- header = '',
- body = '',
- footer ='';
- this.css({
- width: '100%',
- height: '100%',
- 'box-sizing': 'border-box'
- });
- if (m) {
- header = m[1];
- body = m[2];
- footer = m[3];
- } else {
- body = data;
- }
- this.data('data', {
- header: header,
- body: body,
- footer: footer
- });
- },
- load : function(editnode) {
- var self = this,
- fm = this.fm,
- dfrd = $.Deferred(),
- mode = self.confObj.ckeditor5Mode || 'balloon',
- lang = (function() {
- var l = fm.lang.toLowerCase().replace('_', '-');
- if (l.substr(0, 2) === 'zh' && l !== 'zh-cn') {
- l = 'zh';
- }
- return l;
- })(),
- init = function(cEditor) {
- var base = $(editnode).parent(),
- opts;
-
- // set base height
- base.height(fm.getUI().height() - 100);
- // CKEditor5 configure options
- opts = {
- toolbar: ['heading', '|', 'bold', 'italic', 'link', 'imageUpload', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo' ],
- language: lang
- };
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: editnode,
- editorObj: cEditor,
- instance: void(0),
- opts: opts
- });
- cEditor
- .create(editnode, opts)
- .then(function(editor) {
- var fileRepo = editor.plugins.get('FileRepository');
- fileRepo.createUploadAdapter = function(loader) {
- return new uploder(loader);
- };
- editor.setData($(editnode).data('data').body);
- // move .ck-body to elFinder node for fullscreen mode
- fm.getUI().append($('body > div.ck-body'));
- $('div.ck-balloon-panel').css({
- 'z-index': fm.getMaximizeCss().zIndex + 1
- });
- dfrd.resolve(editor);
- /*fm.log({
- plugins: cEditor.build.plugins.map(function(p) { return p.pluginName; }),
- toolbars: Array.from(editor.ui.componentFactory.names())
- });*/
- })
- ['catch'](function(error) { // ['cache'] instead .cache for fix error on ie8
- fm.error(error);
- });
- },
- uploder = function(loader) {
- this.upload = function() {
- return new Promise(function(resolve, reject) {
- fm.exec('upload', {files: [loader.file]}, void(0), fm.cwd().hash)
- .done(function(data){
- if (data.added && data.added.length) {
- fm.url(data.added[0].hash, { async: true }).done(function(url) {
- resolve({
- 'default': fm.convAbsUrl(url)
- });
- }).fail(function() {
- reject('errFileNotFound');
- });
- } else {
- reject(fm.i18n(data.error? data.error : 'errUpload'));
- }
- })
- .fail(function(err) {
- var error = fm.parseError(err);
- reject(fm.i18n(error? (error === 'userabort'? 'errAbort' : error) : 'errUploadNoFiles'));
- })
- .progress(function(data) {
- loader.uploadTotal = data.total;
- loader.uploaded = data.progress;
- });
- });
- };
- this.abort = function() {
- fm.getUI().trigger('uploadabort');
- };
- }, loader;
- if (!self.confObj.editor) {
- loader = $.Deferred();
- self.fm.loadScript([
- fm.options.cdns.ckeditor5 + '/' + mode + '/ckeditor.js'
- ], function(editor) {
- if (!editor) {
- editor = window.BalloonEditor || window.InlineEditor || window.ClassicEditor;
- }
- if (fm.lang !== 'en') {
- self.fm.loadScript([
- fm.options.cdns.ckeditor5 + '/' + mode + '/translations/' + lang + '.js'
- ], function(obj) {
- loader.resolve(editor);
- }, {
- tryRequire: true,
- loadType: 'tag',
- error: function(obj) {
- lang = 'en';
- loader.resolve(editor);
- }
- });
- } else {
- loader.resolve(editor);
- }
- }, {
- tryRequire: true,
- loadType: 'tag'
- });
- loader.done(function(editor) {
- self.confObj.editor = editor;
- init(editor);
- });
- } else {
- init(self.confObj.editor);
- }
- return dfrd;
- },
- getContent : function() {
- var data = $(this).data('data');
- return data.header + data.body + data.footer;
- },
- close : function(editnode, instance) {
- instance && instance.destroy();
- },
- save : function(editnode, instance) {
- var elm = $(editnode),
- data = elm.data('data');
- if (instance) {
- data.body = instance.getData();
- elm.data('data', data);
- }
- },
- focus : function(editnode, instance) {
- $(editnode).trigger('focus');
- }
- },
- {
- // TinyMCE for html file
- info : {
- id : 'tinymce',
- name : 'TinyMCE',
- iconImg : 'img/editor-icons.png 0 -64'
- },
- exts : ['htm', 'html', 'xhtml'],
- setup : function(opts, fm) {
- if (!fm.options.cdns.tinymce) {
- this.disabled = true;
- } else {
- if (opts.extraOptions && opts.extraOptions.managerUrl) {
- this.managerUrl = opts.extraOptions.managerUrl;
- }
- }
- },
- load : function(textarea) {
- var self = this,
- fm = this.fm,
- dfrd = $.Deferred(),
- init = function() {
- var base = $(textarea).show().parent(),
- dlg = base.closest('.elfinder-dialog'),
- h = base.height(),
- delta = base.outerHeight(true) - h,
- opts;
- // set base height
- base.height(h);
- // fit height function
- textarea._setHeight = function(height) {
- var base = $(this).parent(),
- h = height || base.innerHeight(),
- ctrH = 0,
- areaH;
- base.find('.mce-container-body:first').children('.mce-top-part,.mce-statusbar').each(function() {
- ctrH += $(this).outerHeight(true);
- });
- areaH = h - ctrH - delta;
- base.find('.mce-edit-area iframe:first').height(areaH);
- return areaH;
- };
- // TinyMCE configure options
- opts = {
- selector: '#' + textarea.id,
- resize: false,
- plugins: [
- 'fullpage', // require for getting full HTML
- 'image', 'link', 'media',
- 'code', 'fullscreen'
- ],
- init_instance_callback : function(editor) {
- // fit height on init
- textarea._setHeight(h);
- // re-build on dom move
- dlg.one('beforedommove.'+fm.namespace, function() {
- tinymce.execCommand('mceRemoveEditor', false, textarea.id);
- }).one('dommove.'+fm.namespace, function() {
- self.load(textarea).done(function(editor) {
- self.instance = editor;
- });
- });
- // return editor instance
- dfrd.resolve(editor);
- },
- file_picker_callback : function (callback, value, meta) {
- var reg = /([&?]getfile=)[^&]+/,
- loc = self.confObj.managerUrl || window.location.href.replace(/#.*$/, ''),
- name = 'tinymce';
-
- // make manager location
- if (reg.test(loc)) {
- loc = loc.replace(reg, '$1' + name);
- } else {
- loc += '?getfile=' + name;
- }
- // launch TinyMCE
- tinymce.activeEditor.windowManager.open({
- file: loc,
- title: 'elFinder',
- width: 900,
- height: 450,
- resizable: 'yes'
- }, {
- oninsert: function (file, elf) {
- var url, reg, info;
- // URL normalization
- url = elf.convAbsUrl(file.url);
-
- // Make file info
- info = file.name + ' (' + elf.formatSize(file.size) + ')';
- // Provide file and text for the link dialog
- if (meta.filetype == 'file') {
- callback(url, {text: info, title: info});
- }
- // Provide image and alt text for the image dialog
- if (meta.filetype == 'image') {
- callback(url, {alt: info});
- }
- // Provide alternative source and posted for the media dialog
- if (meta.filetype == 'media') {
- callback(url);
- }
- }
- });
- return false;
- }
- };
- // trigger event 'editEditorPrepare'
- self.trigger('Prepare', {
- node: textarea,
- editorObj: tinymce,
- instance: void(0),
- opts: opts
- });
- // TinyMCE configure
- tinymce.init(opts);
- };
-
- if (!self.confObj.loader) {
- self.confObj.loader = $.Deferred();
- $.getScript(fm.options.cdns.tinymce + '/tinymce.min.js', function() {
- setTimeout(function() {
- self.confObj.loader.resolve();
- }, 0);
- });
- }
- self.confObj.loader.done(init);
- return dfrd;
- },
- close : function(textarea, instance) {
- instance && tinymce.execCommand('mceRemoveEditor', false, textarea.id);
- },
- save : function(textarea, instance) {
- instance && instance.save();
- },
- focus : function(textarea, instance) {
- instance && instance.focus();
- },
- resize : function(textarea, instance, e, data) {
- // fit height to base node on dialog resize
- instance && textarea._setHeight();
- }
- },
- {
- info : {
- id : 'zohoeditor',
- name : 'Zoho Editor',
- iconImg : 'img/editor-icons.png 0 -32',
- cmdCheck : 'ZohoOffice',
- preventGet: true,
- hideButtons: true,
- syncInterval : 15000,
- canMakeEmpty: true,
- integrate: {
- title: 'Zoho Office API',
- link: 'https://www.zoho.com/officeapi/'
- }
- },
- mimes : [
- 'application/msword',
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- //'application/pdf',
- 'application/vnd.oasis.opendocument.text',
- 'application/rtf',
- 'text/html',
- 'application/vnd.ms-excel',
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- 'application/vnd.oasis.opendocument.spreadsheet',
- 'application/vnd.sun.xml.calc',
- 'text/csv',
- 'text/tab-separated-values',
- 'application/vnd.ms-powerpoint',
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
- 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
- 'application/vnd.oasis.opendocument.presentation',
- 'application/vnd.sun.xml.impress'
- ],
- html : '<iframe style="width:100%;max-height:100%;border:none;"></iframe>',
- // setup on elFinder bootup
- setup : function(opts, fm) {
- if (fm.UA.Mobile || fm.UA.ltIE8) {
- this.disabled = true;
- }
- },
- // Prepare on before show dialog
- prepare : function(base, dialogOpts, file) {
- var elfNode = base.editor.fm.getUI();
- $(base).height(elfNode.height());
- dialogOpts.width = Math.max(dialogOpts.width || 0, elfNode.width() * 0.8);
- },
- // Initialization of editing node (this: this editors HTML node)
- init : function(id, file, dum, fm) {
- var ta = this,
- ifm = $(this).hide(),
- spnr = $('<div class="elfinder-edit-spinner elfinder-edit-zohoeditor"/>')
- .html('<span class="elfinder-spinner-text">' + fm.i18n('nowLoading') + '</span><span class="elfinder-spinner"/>')
- .appendTo(ifm.parent()),
- cdata = function() {
- var data = '';
- $.each(fm.customData, function(key, val) {
- data += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(val);
- });
- return data;
- };
-
- $(ta).data('xhr', fm.request({
- data: {
- cmd: 'editor',
- name: 'ZohoOffice',
- method: 'init',
- 'args[target]': file.hash,
- 'args[lang]' : fm.lang,
- 'args[cdata]' : cdata
- },
- preventDefault : true
- }).done(function(data) {
- var opts;
- if (data.zohourl) {
- opts = {
- css: {
- height: '100%'
- }
- };
- // trigger event 'editEditorPrepare'
- ta.editor.trigger('Prepare', {
- node: ta,
- editorObj: void(0),
- instance: ifm,
- opts: opts
- });
- ifm.attr('src', data.zohourl).show().css(opts.css);
- } else {
- data.error && fm.error(data.error);
- ta.elfinderdialog('destroy');
- }
- }).fail(function(error) {
- error && fm.error(error);
- ta.elfinderdialog('destroy');
- }).always(function() {
- spnr.remove();
- }));
- },
- load : function() {},
- getContent : function() {},
- save : function() {},
- // Before dialog close
- beforeclose : iframeClose,
- // On dialog closed
- close : function(ta) {
- var fm = this.fm,
- xhr = $(ta).data('xhr');
- if (xhr.state() === 'pending') {
- xhr.reject();
- }
- }
- },
- {
- // Zip Archive with FlySystem
- info : {
- id : 'ziparchive',
- name : 'btnMount',
- iconImg : 'img/toolbar.png 0 -416',
- cmdCheck : 'ZipArchive',
- edit : function(file, editor) {
- var fm = this,
- dfrd = $.Deferred();
- fm.request({
- data:{
- cmd: 'netmount',
- protocol: 'ziparchive',
- host: file.hash,
- path: file.phash
- },
- notify : {type : 'netmount', cnt : 1, hideCnt : true}
- }).done(function(data) {
- var pdir;
- if (data.added && data.added.length) {
- if (data.added[0].phash) {
- if (pdir = fm.file(data.added[0].phash)) {
- if (! pdir.dirs) {
- pdir.dirs = 1;
- fm.change({ changed: [ pdir ] });
- }
- }
- }
- fm.one('netmountdone', function() {
- fm.exec('open', data.added[0].hash);
- fm.one('opendone', function() {
- data.toast && fm.toast(data.toast);
- });
- });
- }
- dfrd.resolve();
- })
- .fail(function(error) {
- dfrd.reject(error);
- });
- return dfrd;
- }
- },
- mimes : ['application/zip'],
- load : function() {},
- save : function(){}
- },
- {
- // Simple Text (basic textarea editor)
- info : {
- id : 'textarea',
- name : 'TextArea',
- useTextAreaEvent : true
- },
- load : function(textarea) {
- // trigger event 'editEditorPrepare'
- this.trigger('Prepare', {
- node: textarea,
- editorObj: void(0),
- instance: void(0),
- opts: {}
- });
- textarea.setSelectionRange && textarea.setSelectionRange(0, 0);
- $(textarea).trigger('focus').show();
- },
- save : function(){}
- },
- {
- // File converter with online-convert.com
- info : {
- id : 'onlineconvert',
- name : 'Online Convert',
- iconImg : 'img/editor-icons.png 0 -144',
- cmdCheck : 'OnlineConvert',
- preventGet: true,
- hideButtons: true,
- single: true,
- converter: true,
- canMakeEmpty: false,
- integrate: {
- title: 'ONLINE-CONVERT.COM',
- link: 'https://online-convert.com'
- }
- },
- mimes : ['*'],
- html : '<iframe style="width:100%;max-height:100%;border:none;"></iframe>',
- // setup on elFinder bootup
- setup : function(opts, fm) {
- var mOpts = opts.extraOptions.onlineConvert || {maxSize:100,showLink:true};
- if (mOpts.maxSize) {
- this.info.maxSize = mOpts.maxSize * 1048576;
- }
- this.set = Object.assign({
- url : 'https://%s.online-convert.com%s?external_url=',
- conv : {
- Archive: {'7Z':{}, 'BZ2':{ext:'bz'}, 'GZ':{}, 'ZIP':{}},
- Audio: {'MP3':{}, 'OGG':{ext:'oga'}, 'WAV':{}, 'WMA':{}, 'AAC':{}, 'AIFF':{ext:'aif'}, 'FLAC':{}, 'M4A':{}, 'MMF':{}, 'OPUS':{ext:'oga'}},
- Document: {'DOC':{}, 'DOCX':{}, 'HTML':{}, 'ODT':{}, 'PDF':{}, 'PPT':{}, 'PPTX':{}, 'RTF':{}, 'SWF':{}, 'TXT':{}},
- eBook: {'AZW3':{ext:'azw'}, 'ePub':{}, 'FB2':{ext:'xml'}, 'LIT':{}, 'LRF':{}, 'MOBI':{}, 'PDB':{}, 'PDF':{},'PDF-eBook':{ext:'pdf'}, 'TCR':{}},
- Hash: {'Adler32':{}, 'Apache-htpasswd':{}, 'Blowfish':{}, 'CRC32':{}, 'CRC32B':{}, 'Gost':{}, 'Haval128':{},'MD4':{}, 'MD5':{}, 'RIPEMD128':{}, 'RIPEMD160':{}, 'SHA1':{}, 'SHA256':{}, 'SHA384':{}, 'SHA512':{}, 'Snefru':{}, 'Std-DES':{}, 'Tiger128':{}, 'Tiger128-calculator':{}, 'Tiger128-converter':{}, 'Tiger160':{}, 'Tiger192':{}, 'Whirlpool':{}},
- Image: {'BMP':{}, 'EPS':{ext:'ai'}, 'GIF':{}, 'EXR':{}, 'ICO':{}, 'JPG':{}, 'PNG':{}, 'SVG':{}, 'TGA':{}, 'TIFF':{ext:'tif'}, 'WBMP':{}, 'WebP':{}},
- Video: {'3G2':{}, '3GP':{}, 'AVI':{}, 'FLV':{}, 'HLS':{ext:'m3u8'}, 'MKV':{}, 'MOV':{}, 'MP4':{}, 'MPEG-1':{ext:'mpeg'}, 'MPEG-2':{ext:'mpeg'}, 'OGG':{ext:'ogv'}, 'OGV':{}, 'WebM':{}, 'WMV':{}, 'Android':{link:'/convert-video-for-%s',ext:'mp4'}, 'Blackberry':{link:'/convert-video-for-%s',ext:'mp4'}, 'DPG':{link:'/convert-video-for-%s',ext:'avi'}, 'iPad':{link:'/convert-video-for-%s',ext:'mp4'}, 'iPhone':{link:'/convert-video-for-%s',ext:'mp4'}, 'iPod':{link:'/convert-video-for-%s',ext:'mp4'}, 'Nintendo-3DS':{link:'/convert-video-for-%s',ext:'avi'}, 'Nintendo-DS':{link:'/convert-video-for-%s',ext:'avi'}, 'PS3':{link:'/convert-video-for-%s',ext:'mp4'}, 'Wii':{link:'/convert-video-for-%s',ext:'avi'}, 'Xbox':{link:'/convert-video-for-%s',ext:'wmv'}}
- },
- catExts : {
- Hash: 'txt'
- },
- link : '<div class="elfinder-edit-onlineconvert-link"><a href="https://www.online-convert.com" target="_blank"><span class="elfinder-button-icon"></span>ONLINE-CONVERT.COM</a></div>',
- toastWidth : 280,
- useTabs : ($.fn.tabs && !fm.UA.iOS)? true : false // Can't work on iOS, I don't know why.
- }, mOpts);
- },
- // Prepare on before show dialog
- prepare : function(base, dialogOpts, file) {
- var elfNode = base.editor.fm.getUI();
- $(base).height(elfNode.height());
- dialogOpts.width = Math.max(dialogOpts.width || 0, elfNode.width() * 0.8);
- },
- // Initialization of editing node (this: this editors HTML node)
- init : function(id, file, dum, fm) {
- var ta = this,
- confObj = ta.editor.confObj,
- set = confObj.set,
- uiToast = fm.getUI('toast'),
- idxs = {},
- allowZip = fm.uploadMimeCheck('application/zip', file.phash),
- getExt = function(cat, con) {
- var c;
- if (set.catExts[cat]) {
- return set.catExts[cat];
- }
- if (set.conv[cat] && (c = set.conv[cat][con])) {
- return (c.ext || con).toLowerCase();
- }
- return con.toLowerCase();
- },
- setOptions = function(cat, done) {
- var type, dfdInit, dfd;
- if (typeof confObj.api === 'undefined') {
- dfdInit = fm.request({
- data: {
- cmd: 'editor',
- name: 'OnlineConvert',
- method: 'init'
- },
- preventDefault : true
- });
- } else {
- dfdInit = $.Deferred().resolve({api: confObj.api});
- }
- cat = cat.toLowerCase();
- dfdInit.done(function(data) {
- confObj.api = data.api;
- if (confObj.api) {
- if (cat) {
- type = '?category=' + cat;
- } else {
- type = '';
- cat = 'all';
- }
- if (!confObj.conversions) {
- confObj.conversions = {};
- }
- if (!confObj.conversions[cat]) {
- dfd = $.getJSON('https://api2.online-convert.com/conversions' + type);
- } else {
- dfd = $.Deferred().resolve(confObj.conversions[cat]);
- }
- dfd.done(function(d) {
- confObj.conversions[cat] = d;
- $.each(d, function(i, o) {
- btns[set.useTabs? 'children' : 'find']('.onlineconvert-category-' + o.category).children('.onlineconvert-' + o.target).trigger('makeoption', o);
- });
- done && done();
- });
- }
- });
- },
- btns = (function() {
- var btns = $('<div/>').on('click', 'button', function() {
- var b = $(this),
- opts = b.data('opts') || null,
- cat = b.closest('.onlineconvert-category').data('cname'),
- con = b.data('conv');
- if (confObj.api === true) {
- api({
- category: cat,
- convert: con,
- options: opts
- });
- } else {
- open(cat, con);
- }
- }).on('change', function(e) {
- var t = $(e.target),
- p = t.parent(),
- b = t.closest('.elfinder-edit-onlineconvert-button').children('button:first'),
- o = b.data('opts') || {},
- v = p.data('type') === 'boolean'? t.is(':checked') : t.val();
- e.stopPropagation();
- if (v) {
- if (p.data('type') === 'integer') {
- v = parseInt(v);
- }
- if (p.data('pattern')) {
- var reg = new RegExp(p.data('pattern'));
- if (!reg.test(v)) {
- requestAnimationFrame(function() {
- fm.error('"' + fm.escape(v) + '" is not match to "/' + fm.escape(p.data('pattern')) + '/"');
- });
- v = null;
- }
- }
- }
- if (v) {
- o[t.parent().data('optkey')] = v;
- } else {
- delete o[p.data('optkey')];
- }
- b.data('opts', o);
- }),
- ul = $('<ul/>'),
- oform = function(n, o) {
- var f = $('<p/>').data('optkey', n).data('type', o.type),
- checked = '',
- disabled = '',
- nozip = false,
- opts, btn, elm;
- if (o.description) {
- f.attr('title', fm.i18n(o.description));
- }
- if (o.pattern) {
- f.data('pattern', o.pattern);
- }
- f.append($('<span/>').text(fm.i18n(n) + ' : '));
- if (o.type === 'boolean') {
- if (o['default'] || (nozip = (n === 'allow_multiple_outputs' && !allowZip))) {
- checked = ' checked';
- if (nozip) {
- disabled = ' disabled';
- }
- btn = this.children('button:first');
- opts = btn.data('opts') || {};
- opts[n] = true;
- btn.data('opts', opts);
- }
- f.append($('<input type="checkbox" value="true"'+checked+disabled+'/>'));
- } else if (o['enum']){
- elm = $('<select/>').append($('<option value=""/>').text('Select...'));
- $.each(o['enum'], function(i, v) {
- elm.append($('<option value="'+v+'"/>').text(v));
- });
- f.append(elm);
- } else {
- f.append($('<input type="text" value=""/>'));
- }
- return f;
- },
- makeOption = function(o) {
- var elm = this,
- b = $('<span class="elfinder-button-icon elfinder-button-icon-preference"/>').on('click', function() {
- f.toggle();
- }),
- f = $('<div class="elfinder-edit-onlinconvert-options"/>').hide();
- if (o.options) {
- $.each(o.options, function(k, v) {
- k !== 'download_password' && f.append(oform.call(elm, k, v));
- });
- }
- elm.append(b, f);
- },
- ts = (+new Date()),
- i = 0;
-
- if (!confObj.ext2mime) {
- confObj.ext2mime = fm.arrayFlip(fm.mimeTypes);
- }
- $.each(set.conv, function(t, c) {
- var cname = t.toLowerCase(),
- id = 'elfinder-edit-onlineconvert-' + cname + ts,
- type = $('<div id="' + id + '" class="onlineconvert-category onlineconvert-category-'+cname+'"/>').data('cname', t),
- cext;
- $.each(c, function(n, o) {
- var nl = n.toLowerCase(),
- ext = getExt(t, n);
- if (!confObj.ext2mime[ext]) {
- if (cname === 'audio' || cname === 'image' || cname === 'video') {
- confObj.ext2mime[ext] = cname + '/x-' + nl;
- } else {
- confObj.ext2mime[ext] = 'application/octet-stream';
- }
- }
- if (fm.uploadMimeCheck(confObj.ext2mime[ext], file.phash)) {
- type.append($('<div class="elfinder-edit-onlineconvert-button onlineconvert-'+nl+'"/>').on('makeoption', function(e, data) {
- var elm = $(this);
- if (!elm.children('.elfinder-button-icon-preference').length) {
- makeOption.call(elm, data);
- }
- }).append($('<button/>').text(n).data('conv', n)));
- }
- });
- if (type.children().length) {
- ul.append($('<li/>').append($('<a/>').attr('href', '#' + id).text(t)));
- btns.append(type);
- idxs[cname] = i++;
- }
- });
- if (set.useTabs) {
- btns.prepend(ul).tabs({
- beforeActivate: function(e, ui) {
- setOptions(ui.newPanel.data('cname'));
- }
- });
- } else {
- $.each(set.conv, function(t) {
- var tl = t.toLowerCase();
- btns.append($('<fieldset class="onlineconvert-fieldset-' + tl + '"/>').append($('<legend/>').text(t)).append(btns.children('.onlineconvert-category-' + tl)));
- });
- }
- return btns;
- })(),
- ifm = $(this).hide(),
- select = $('<div/>')
- .append(
- btns,
- $('<div class="elfinder-edit-onlineconvert-bottom-btn"/>').append(
- $('<button/>')
- .addClass(fm.UA.iOS? 'elfinder-button-ios-multiline' : '')
- .html(fm.i18n('convertOn', 'Online-Convert.com'))
- .on('click', function() {
- open();
- })
- ),
- (set.showLink? $(set.link) : null)
- )
- .appendTo(ifm.parent().css({overflow: 'auto'})),
- spnr = $('<div class="elfinder-edit-spinner elfinder-edit-onlineconvert"/>')
- .hide()
- .html('<span class="elfinder-spinner-text">' + fm.i18n('nowLoading') + '</span><span class="elfinder-spinner"/>')
- .appendTo(ifm.parent()),
- _url = null,
- url = function() {
- if (_url) {
- return $.Deferred().resolve(_url);
- } else {
- spnr.show();
- return fm.url(file.hash, {
- async: true,
- temporary: true
- }).done(function(url) {
- _url = url;
- }).fail(function(error) {
- error && fm.error(error);
- ta.elfinderdialog('destroy');
- }).always(function() {
- spnr.hide();
- });
- }
- },
- api = function(opts) {
- $(ta).data('dfrd', url().done(function(url) {
- select.fadeOut();
- setStatus({info: 'Start conversion request.'});
- fm.request({
- data: {
- cmd: 'editor',
- name: 'OnlineConvert',
- method: 'api',
- 'args[category]' : opts.category.toLowerCase(),
- 'args[convert]' : opts.convert.toLowerCase(),
- 'args[options]' : JSON.stringify(opts.options),
- 'args[source]' : fm.convAbsUrl(url),
- 'args[filename]' : fm.splitFileExtention(file.name)[0] + '.' + getExt(opts.category, opts.convert),
- 'args[mime]' : file.mime
- },
- preventDefault : true
- }).done(function(data) {
- checkRes(data.apires, opts.category, opts.convert);
- }).fail(function(error) {
- error && fm.error(error);
- ta.elfinderdialog('destroy');
- });
- }));
- },
- checkRes = function(res, cat, con) {
- var status, err = [];
- if (res && res.id) {
- status = res.status;
- if (status.code === 'failed') {
- spnr.hide();
- if (res.errors && res.errors.length) {
- $.each(res.errors, function(i, o) {
- o.message && err.push(o.message);
- });
- }
- fm.error(err.length? err : status.info);
- select.fadeIn();
- } else if (status.code === 'completed') {
- upload(res);
- } else {
- setStatus(status);
- setTimeout(function() {
- polling(res.id);
- }, 1000);
- }
- } else {
- uiToast.appendTo(ta.closest('.ui-dialog'));
- if (res.message) {
- fm.toast({
- msg: fm.i18n(res.message),
- mode: 'error',
- timeOut: 5000,
- width: set.toastWidth,
- onHidden: function() {
- uiToast.children().length === 1 && uiToast.appendTo(fm.getUI());
- }
- });
- }
- fm.toast({
- msg: fm.i18n('editorConvNoApi'),
- mode: 'warning',
- timeOut: 3000,
- width: set.toastWidth,
- onHidden: function() {
- uiToast.children().length === 1 && uiToast.appendTo(fm.getUI());
- open(cat, con);
- }
- });
- }
- },
- setStatus = function(status) {
- spnr.show().children('.elfinder-spinner-text').text(status.info);
- },
- polling = function(jobid) {
- fm.request({
- data: {
- cmd: 'editor',
- name: 'OnlineConvert',
- method: 'api',
- 'args[jobid]': jobid
- },
- preventDefault : true
- }).done(function(data) {
- checkRes(data.apires);
- }).fail(function(error) {
- error && fm.error(error);
- ta.elfinderdialog('destroy');
- });
- },
- upload = function(res) {
- var output = res.output,
- id = res.id,
- url = '';
- spnr.hide();
- if (output && output.length) {
- ta.elfinderdialog('destroy');
- $.each(output, function(i, o) {
- if (o.uri) {
- url += o.uri + '\n';
- }
- });
- fm.upload({
- target: file.phash,
- files: [url],
- type: 'text',
- extraData: {
- contentSaveId: 'OnlineConvert-' + res.id
- }
- });
- }
- },
- open = function(cat, con) {
- var link;
- if (cat && con) {
- if (set.conv[cat] && set.conv[cat][con] && set.conv[cat][con].link) {
- link = set.conv[cat][con].link.replace('%s', con);
- } else {
- link = cat === 'hash'? ('/' + con + '-generator') : ('/convert-to-' + con);
- }
- link = set.url.replace('%s', cat).replace('%s', link);
- } else {
- link = set.url.replace('%s', mode + '-conversion').replace('%s', '');
- }
- spnr.hide();
- select.hide();
- ifm.parent().css({overflow: fm.UA.iOS? 'auto' : 'hidden'});
- $(ta).data('dfrd', url().done(function(url) {
- var opts;
- if (url) {
- opts = {
- css: {
- height: '100%'
- }
- };
- // trigger event 'editEditorPrepare'
- ta.editor.trigger('Prepare', {
- node: ta,
- editorObj: void(0),
- instance: ifm,
- opts: opts
- });
- url = link + encodeURIComponent(fm.convAbsUrl(url));
- ifm.attr('src', url).show().css(opts.css)
- .one('load', function() {
- uiToast.appendTo(ta.closest('.ui-dialog'));
- fm.toast({
- msg: fm.i18n('editorConvNeedUpload'),
- mode: 'info',
- timeOut: 10000,
- width: set.toastWidth,
- onHidden: function() {
- uiToast.children().length === 1 && uiToast.appendTo(fm.getUI());
- },
- button: {
- text: 'btnYes'
- }
- });
- });
- } else {
- data.error && fm.error(data.error);
- ta.elfinderdialog('destroy');
- }
- }));
- },
- mode = 'document',
- cl, m;
- ifm.parent().addClass('overflow-scrolling-touch');
- if (m = file.mime.match(/^(audio|image|video)/)) {
- mode = m[1];
- }
- if (set.useTabs) {
- if (idxs[mode]) {
- btns.tabs('option', 'active', idxs[mode]);
- }
- } else {
- cl = Object.keys(set.conv).length;
- $.each(set.conv, function(t) {
- if (t.toLowerCase() === mode) {
- setOptions(t, function() {
- $.each(set.conv, function(t0) {
- t0.toLowerCase() !== mode && setOptions(t0);
- });
- });
- return false;
- }
- cl--;
- });
- if (!cl) {
- $.each(set.conv, function(t) {
- setOptions(t);
- });
- }
- ifm.parent().scrollTop(btns.children('.onlineconvert-fieldset-' + mode).offset().top);
- }
- },
- load : function() {},
- getContent : function() {},
- save : function() {},
- // Before dialog close
- beforeclose : iframeClose,
- // On dialog closed
- close : function(ta) {
- var fm = this.fm,
- dfrd = $(ta).data('dfrd');
- if (dfrd && dfrd.state() === 'pending') {
- dfrd.reject();
- }
- }
- }
- ];
- }, window.elFinder));
|