(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.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; })(), initImgTag = function(id, file, content, fm) { var node = $(this).children('img:first'), spnr = $('
') .css({ position: 'absolute', top: '50%', textAlign: 'center', width: '100%', fontSize: '16pt' }) .html(fm.i18n('ntfloadimg')) .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; 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]; 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.remove(); } }, pixlrSetup = function(opts, fm) { if (!hasFlash || fm.UA.ltIE8) { this.disabled = true; } }, pixlrLoad = function(mode, base) { var fm = this.fm, node = $(base).children('img:first') .data('loading')() .data('resizeoff', function() { $(window).off('resize.'+node.attr('id')); return node; }) .on('click', function() { launch(); }), elfNode = fm.getUI(), container = $('', // 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 = $('
') .css({ position: 'absolute', top: '50%', textAlign: 'center', width: '100%', fontSize: '16pt' }) .html(fm.i18n('nowLoading') + '') .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) { if (data.zohourl) { ifm.attr('src', data.zohourl).show().height('100%'); } 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 : function(base) { var dfd = $.Deferred(), ab = 'about:blank'; base.src = ab; setTimeout(function() { var src; try { src = base.contentWindow.location.href; } catch(e) { src = null; } if (src === ab) { dfd.resolve(); } else { dfd.reject(); } }, 10); return dfd; }, // On dialog closed close : function(ta) { var fm = this.fm, xhr = $(ta).data('xhr'); if (xhr.state() === 'pending') { xhr.reject(); } else { fm.sync(fm.cwd().hash); } } }, { // Simple Text (basic textarea editor) info : { name : 'TextArea', useTextAreaEvent : true }, load : function(){}, save : function(){} } ]; }, window.elFinder));