(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, 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', ico: 'image/x-icon', dds: 'image/vnd-ms.dds', emf: 'application/x-msmetafile' }, mime2ext, getExtention = function(mime, fm, jpeg) { if (!mime2ext) { mime2ext = fm.arrayFlip(ext2mime); } var ext = mime2ext[mime] || fm.mimeTypes[mime]; if (!jpeg) { if (ext === 'jpeg') { ext = 'jpg'; } } else { if (ext === 'jpg') { ext = 'jpeg'; } } return ext; }, changeImageType = function(src, toMime) { var dfd = $.Deferred(); try { var canvas = document.createElement('canvas'), ctx = canvas.getContext('2d'), img = new Image(), conv = function() { var url = canvas.toDataURL(toMime), mime, m; if (m = url.match(/^data:([a-z0-9]+\/[a-z0-9.+-]+)/i)) { mime = m[1]; } else { mime = ''; } if (mime.toLowerCase() === toMime.toLowerCase()) { dfd.resolve(canvas.toDataURL(toMime), canvas); } else { dfd.reject(); } }; img.src = src; $(img).on('load', function() { try { canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); conv(); } catch(e) { dfd.reject(); } }).on('error', function () { dfd.reject(); }); return dfd; } catch(e) { return dfd.reject(); } }, initImgTag = function(id, file, content, fm) { var node = $(this).children('img:first').data('ext', getExtention(file.mime, fm)), spnr = $('
') .html('' + fm.i18n('ntfloadimg') + '') .hide() .appendTo(this), setup = function() { node.attr('id', id+'-img') .attr('src', url || 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; }); }, url; if (!content.match(/^data:/)) { fm.openUrl(file.hash, false, function(v) { url = v; node.attr('_src', content); setup(); }); } else { setup(); } }, 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; }, 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 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(); }; } } // 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 : '', // 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({ version: 'v3.15.3' }, 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 = self.confObj.opts.version, init = function(editor) { var $base = $(base), bParent = $base.parent(), opts = self.confObj.opts, iconsPath = opts.iconsPath, tmpContainer = $('