editors.default.js
8 months ago
editors.default.min.js
8 months ago
quicklook.googledocs.js
8 months ago
quicklook.googledocs.min.js
8 months ago
editors.default.js
2645 lines
| 1 | (function ($) { |
| 2 | (function(editors, elFinder) { |
| 3 | if (typeof define === 'function' && define.amd) { |
| 4 | define(['elfinder'], editors); |
| 5 | } else if (elFinder) { |
| 6 | var optEditors = elFinder.prototype._options.commandsOptions.edit.editors; |
| 7 | elFinder.prototype._options.commandsOptions.edit.editors = optEditors.concat(editors(elFinder)); |
| 8 | } |
| 9 | }(function(elFinder) { |
| 10 | "use strict"; |
| 11 | var apps = {}, |
| 12 | // get query of getfile |
| 13 | getfile = window.location.search.match(/getfile=([a-z]+)/), |
| 14 | useRequire = elFinder.prototype.hasRequire, |
| 15 | ext2mime = { |
| 16 | bmp: 'image/x-ms-bmp', |
| 17 | dng: 'image/x-adobe-dng', |
| 18 | gif: 'image/gif', |
| 19 | jpeg: 'image/jpeg', |
| 20 | jpg: 'image/jpeg', |
| 21 | pdf: 'application/pdf', |
| 22 | png: 'image/png', |
| 23 | ppm: 'image/x-portable-pixmap', |
| 24 | psd: 'image/vnd.adobe.photoshop', |
| 25 | pxd: 'image/x-pixlr-data', |
| 26 | svg: 'image/svg+xml', |
| 27 | tiff: 'image/tiff', |
| 28 | webp: 'image/webp', |
| 29 | xcf: 'image/x-xcf', |
| 30 | sketch: 'application/x-sketch', |
| 31 | ico: 'image/x-icon', |
| 32 | dds: 'image/vnd-ms.dds', |
| 33 | emf: 'application/x-msmetafile' |
| 34 | }, |
| 35 | mime2ext, |
| 36 | getExtention = function(mime, fm, jpeg) { |
| 37 | if (!mime2ext) { |
| 38 | mime2ext = fm.arrayFlip(ext2mime); |
| 39 | } |
| 40 | var ext = mime2ext[mime] || fm.mimeTypes[mime]; |
| 41 | if (!jpeg) { |
| 42 | if (ext === 'jpeg') { |
| 43 | ext = 'jpg'; |
| 44 | } |
| 45 | } else { |
| 46 | if (ext === 'jpg') { |
| 47 | ext = 'jpeg'; |
| 48 | } |
| 49 | } |
| 50 | return ext; |
| 51 | }, |
| 52 | changeImageType = function(src, toMime) { |
| 53 | var dfd = $.Deferred(); |
| 54 | try { |
| 55 | var canvas = document.createElement('canvas'), |
| 56 | ctx = canvas.getContext('2d'), |
| 57 | img = new Image(), |
| 58 | conv = function() { |
| 59 | var url = canvas.toDataURL(toMime), |
| 60 | mime, m; |
| 61 | if (m = url.match(/^data:([a-z0-9]+\/[a-z0-9.+-]+)/i)) { |
| 62 | mime = m[1]; |
| 63 | } else { |
| 64 | mime = ''; |
| 65 | } |
| 66 | if (mime.toLowerCase() === toMime.toLowerCase()) { |
| 67 | dfd.resolve(canvas.toDataURL(toMime), canvas); |
| 68 | } else { |
| 69 | dfd.reject(); |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | img.src = src; |
| 74 | $(img).on('load', function() { |
| 75 | try { |
| 76 | canvas.width = img.width; |
| 77 | canvas.height = img.height; |
| 78 | ctx.drawImage(img, 0, 0); |
| 79 | conv(); |
| 80 | } catch(e) { |
| 81 | dfd.reject(); |
| 82 | } |
| 83 | }).on('error', function () { |
| 84 | dfd.reject(); |
| 85 | }); |
| 86 | return dfd; |
| 87 | } catch(e) { |
| 88 | return dfd.reject(); |
| 89 | } |
| 90 | }, |
| 91 | initImgTag = function(id, file, content, fm) { |
| 92 | var node = $(this).children('img:first').data('ext', getExtention(file.mime, fm)), |
| 93 | spnr = $('<div class="elfinder-edit-spinner elfinder-edit-image"></div>') |
| 94 | .html('<span class="elfinder-spinner-text">' + fm.i18n('ntfloadimg') + '</span><span class="elfinder-spinner"></span>') |
| 95 | .hide() |
| 96 | .appendTo(this), |
| 97 | setup = function() { |
| 98 | node.attr('id', id+'-img') |
| 99 | .attr('src', url || content) |
| 100 | .css({'height':'', 'max-width':'100%', 'max-height':'100%', 'cursor':'pointer'}) |
| 101 | .data('loading', function(done) { |
| 102 | var btns = node.closest('.elfinder-dialog').find('button,.elfinder-titlebar-button'); |
| 103 | btns.prop('disabled', !done)[done? 'removeClass' : 'addClass']('ui-state-disabled'); |
| 104 | node.css('opacity', done? '' : '0.3'); |
| 105 | spnr[done? 'hide' : 'show'](); |
| 106 | return node; |
| 107 | }); |
| 108 | }, |
| 109 | url; |
| 110 | |
| 111 | if (!content.match(/^data:/)) { |
| 112 | fm.openUrl(file.hash, false, function(v) { |
| 113 | url = v; |
| 114 | node.attr('_src', content); |
| 115 | setup(); |
| 116 | }); |
| 117 | } else { |
| 118 | setup(); |
| 119 | } |
| 120 | }, |
| 121 | imgBase64 = function(node, mime) { |
| 122 | var style = node.attr('style'), |
| 123 | img, canvas, ctx, data; |
| 124 | try { |
| 125 | // reset css for getting image size |
| 126 | node.attr('style', ''); |
| 127 | // img node |
| 128 | img = node.get(0); |
| 129 | // New Canvas |
| 130 | canvas = document.createElement('canvas'); |
| 131 | canvas.width = img.width; |
| 132 | canvas.height = img.height; |
| 133 | // restore css |
| 134 | node.attr('style', style); |
| 135 | // Draw Image |
| 136 | canvas.getContext('2d').drawImage(img, 0, 0); |
| 137 | // To Base64 |
| 138 | data = canvas.toDataURL(mime); |
| 139 | } catch(e) { |
| 140 | data = node.attr('src'); |
| 141 | } |
| 142 | return data; |
| 143 | }, |
| 144 | iframeClose = function(ifm) { |
| 145 | var $ifm = $(ifm), |
| 146 | dfd = $.Deferred().always(function() { |
| 147 | $ifm.off('load', load); |
| 148 | }), |
| 149 | ab = 'about:blank', |
| 150 | chk = function() { |
| 151 | tm = setTimeout(function() { |
| 152 | var src; |
| 153 | try { |
| 154 | src = base.contentWindow.location.href; |
| 155 | } catch(e) { |
| 156 | src = null; |
| 157 | } |
| 158 | if (src === ab) { |
| 159 | dfd.resolve(); |
| 160 | } else if (--cnt > 0){ |
| 161 | chk(); |
| 162 | } else { |
| 163 | dfd.reject(); |
| 164 | } |
| 165 | }, 500); |
| 166 | }, |
| 167 | load = function() { |
| 168 | tm && clearTimeout(tm); |
| 169 | dfd.resolve(); |
| 170 | }, |
| 171 | cnt = 20, // 500ms * 20 = 10sec wait |
| 172 | tm; |
| 173 | $ifm.one('load', load); |
| 174 | ifm.src = ab; |
| 175 | chk(); |
| 176 | return dfd; |
| 177 | }; |
| 178 | |
| 179 | // check getfile callback function |
| 180 | if (getfile) { |
| 181 | getfile = getfile[1]; |
| 182 | if (getfile === 'ckeditor') { |
| 183 | elFinder.prototype._options.getFileCallback = function(file, fm) { |
| 184 | window.opener.CKEDITOR.tools.callFunction((function() { |
| 185 | var reParam = new RegExp('(?:[?&]|&)CKEditorFuncNum=([^&]+)', 'i'), |
| 186 | match = window.location.search.match(reParam); |
| 187 | return (match && match.length > 1) ? match[1] : ''; |
| 188 | })(), fm.convAbsUrl(file.url)); |
| 189 | fm.destroy(); |
| 190 | window.close(); |
| 191 | }; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // return editors Array |
| 196 | return [ |
| 197 | { |
| 198 | // tui.image-editor - https://github.com/nhnent/tui.image-editor |
| 199 | info : { |
| 200 | id: 'tuiimgedit', |
| 201 | name: 'TUI Image Editor', |
| 202 | iconImg: 'img/editor-icons.png 0 -48', |
| 203 | dataScheme: true, |
| 204 | schemeContent: true, |
| 205 | openMaximized: true, |
| 206 | canMakeEmpty: false, |
| 207 | integrate: { |
| 208 | title: 'TOAST UI Image Editor', |
| 209 | link: 'http://ui.toast.com/tui-image-editor/' |
| 210 | } |
| 211 | }, |
| 212 | // MIME types to accept |
| 213 | mimes : ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/x-ms-bmp'], |
| 214 | // HTML of this editor |
| 215 | html : '<div class="elfinder-edit-imageeditor"><canvas></canvas></div>', |
| 216 | // called on initialization of elFinder cmd edit (this: this editor's config object) |
| 217 | setup : function(opts, fm) { |
| 218 | if (fm.UA.ltIE8 || fm.UA.Mobile) { |
| 219 | this.disabled = true; |
| 220 | } else { |
| 221 | this.opts = Object.assign({ |
| 222 | version: 'v3.15.3' |
| 223 | }, opts.extraOptions.tuiImgEditOpts || {}, { |
| 224 | iconsPath : fm.baseUrl + 'img/tui-', |
| 225 | theme : {} |
| 226 | }); |
| 227 | if (!fm.isSameOrigin(this.opts.iconsPath)) { |
| 228 | this.disabled = true; |
| 229 | fm.debug('warning', 'Setting `commandOptions.edit.extraOptions.tuiImgEditOpts.iconsPath` MUST follow the same origin policy.'); |
| 230 | } |
| 231 | } |
| 232 | }, |
| 233 | // Initialization of editing node (this: this editors HTML node) |
| 234 | init : function(id, file, content, fm) { |
| 235 | this.data('url', content); |
| 236 | }, |
| 237 | load : function(base) { |
| 238 | var self = this, |
| 239 | fm = this.fm, |
| 240 | dfrd = $.Deferred(), |
| 241 | cdns = fm.options.cdns, |
| 242 | ver = self.confObj.opts.version, |
| 243 | init = function(editor) { |
| 244 | var $base = $(base), |
| 245 | bParent = $base.parent(), |
| 246 | opts = self.confObj.opts, |
| 247 | iconsPath = opts.iconsPath, |
| 248 | tmpContainer = $('<div class="tui-image-editor-container">').appendTo(bParent), |
| 249 | tmpDiv = [ |
| 250 | $('<div class="tui-image-editor-submenu"></div>').appendTo(tmpContainer), |
| 251 | $('<div class="tui-image-editor-controls"></div>').appendTo(tmpContainer) |
| 252 | ], |
| 253 | iEditor = new editor(base, { |
| 254 | includeUI: { |
| 255 | loadImage: { |
| 256 | path: $base.data('url'), |
| 257 | name: self.file.name |
| 258 | }, |
| 259 | theme: opts.theme, |
| 260 | initMenu: 'filter', |
| 261 | menuBarPosition: 'bottom' |
| 262 | }, |
| 263 | cssMaxWidth: Math.max(300, bParent.width()), |
| 264 | cssMaxHeight: Math.max(200, bParent.height() - (tmpDiv[0].height() + tmpDiv[1].height() + 3 /*margin*/)), |
| 265 | usageStatistics: false |
| 266 | }), |
| 267 | canvas = $base.find('canvas:first').get(0), |
| 268 | zoom = function(v) { |
| 269 | if (typeof v !== 'undefined') { |
| 270 | var c = $(canvas), |
| 271 | w = parseInt(c.attr('width')), |
| 272 | h = parseInt(c.attr('height')), |
| 273 | a = w / h, |
| 274 | z, mw, mh; |
| 275 | if (v === 0) { |
| 276 | mw = w; |
| 277 | mh = h; |
| 278 | } else { |
| 279 | mw = parseInt(c.css('max-width')) + Number(v); |
| 280 | mh = mw / a; |
| 281 | if (mw > w && mh > h) { |
| 282 | mw = w; |
| 283 | mh = h; |
| 284 | } |
| 285 | } |
| 286 | z = Math.round(mw / w * 100); |
| 287 | // Control zoom button of TUI Image Editor |
| 288 | if (z < 100) { |
| 289 | iEditor.resetZoom(); |
| 290 | iEditor.stopDrawingMode(); |
| 291 | tuiZoomCtrls.hide(); |
| 292 | } else { |
| 293 | tuiZoomCtrls.show(); |
| 294 | } |
| 295 | per.text(z + '%'); |
| 296 | iEditor.resizeCanvasDimension({width: mw, height: mh}); |
| 297 | // continually change more |
| 298 | if (zoomMore) { |
| 299 | setTimeout(function() { |
| 300 | zoomMore && zoom(v); |
| 301 | }, 50); |
| 302 | } |
| 303 | } |
| 304 | }, |
| 305 | zup = $('<span class="ui-icon ui-icon-plusthick"></span>').data('val', 10), |
| 306 | zdown = $('<span class="ui-icon ui-icon-minusthick"></span>').data('val', -10), |
| 307 | per = $('<button></button>').css('width', '4em').text('%').attr('title', '100%').data('val', 0), |
| 308 | tuiZoomCtrls, |
| 309 | quty, qutyTm, zoomTm, zoomMore; |
| 310 | |
| 311 | tmpContainer.remove(); |
| 312 | $base.removeData('url').data('mime', self.file.mime); |
| 313 | // jpeg quality controls |
| 314 | if (self.file.mime === 'image/jpeg') { |
| 315 | $base.data('quality', fm.storage('jpgQuality') || fm.option('jpgQuality')); |
| 316 | quty = $('<input type="number" class="ui-corner-all elfinder-resize-quality elfinder-tabstop"/>') |
| 317 | .attr('min', '1') |
| 318 | .attr('max', '100') |
| 319 | .attr('title', '1 - 100') |
| 320 | .on('change', function() { |
| 321 | var q = quty.val(); |
| 322 | $base.data('quality', q); |
| 323 | qutyTm && cancelAnimationFrame(qutyTm); |
| 324 | qutyTm = requestAnimationFrame(function() { |
| 325 | canvas.toBlob(function(blob) { |
| 326 | blob && quty.next('span').text(' (' + fm.formatSize(blob.size) + ')'); |
| 327 | }, 'image/jpeg', Math.max(Math.min(q, 100), 1) / 100); |
| 328 | }); |
| 329 | }) |
| 330 | .val($base.data('quality')); |
| 331 | $('<div class="ui-dialog-buttonset elfinder-edit-extras elfinder-edit-extras-quality"></div>') |
| 332 | .append( |
| 333 | $('<span>').html(fm.i18n('quality') + ' : '), quty, $('<span></span>') |
| 334 | ) |
| 335 | .prependTo($base.parent().next()); |
| 336 | } else if (self.file.mime === 'image/svg+xml') { |
| 337 | $base.closest('.ui-dialog').trigger('changeType', { |
| 338 | extention: 'png', |
| 339 | mime : 'image/png', |
| 340 | keepEditor: true |
| 341 | }); |
| 342 | } |
| 343 | // zoom scale controls |
| 344 | $('<div class="ui-dialog-buttonset elfinder-edit-extras"></div>') |
| 345 | .append( |
| 346 | zdown, per, zup |
| 347 | ) |
| 348 | .attr('title', fm.i18n('scale')) |
| 349 | .on('click', 'span,button', function() { |
| 350 | zoom($(this).data('val')); |
| 351 | }) |
| 352 | .on('mousedown mouseup mouseleave', 'span', function(e) { |
| 353 | zoomMore = false; |
| 354 | zoomTm && clearTimeout(zoomTm); |
| 355 | if (e.type === 'mousedown') { |
| 356 | zoomTm = setTimeout(function() { |
| 357 | zoomMore = true; |
| 358 | zoom($(e.target).data('val')); |
| 359 | }, 500); |
| 360 | } |
| 361 | }) |
| 362 | .prependTo($base.parent().next()); |
| 363 | |
| 364 | // wait canvas ready |
| 365 | setTimeout(function() { |
| 366 | dfrd.resolve(iEditor); |
| 367 | if (quty) { |
| 368 | quty.trigger('change'); |
| 369 | iEditor.on('redoStackChanged undoStackChanged', function() { |
| 370 | quty.trigger('change'); |
| 371 | }); |
| 372 | } |
| 373 | // ZOOM controls of TUI Image Editor |
| 374 | tuiZoomCtrls = $base.find('.tie-btn-zoomIn,.tie-btn-zoomOut,.tie-btn-hand'); |
| 375 | // show initial scale |
| 376 | zoom(null); |
| 377 | }, 100); |
| 378 | |
| 379 | // show color slider (maybe TUI-Image-Editor's bug) |
| 380 | // see https://github.com/nhn/tui.image-editor/issues/153 |
| 381 | $base.find('.tui-colorpicker-palette-container').on('click', '.tui-colorpicker-palette-preview', function() { |
| 382 | $(this).closest('.color-picker-control').height('auto').find('.tui-colorpicker-slider-container').toggle(); |
| 383 | }); |
| 384 | $base.on('click', function() { |
| 385 | $base.find('.tui-colorpicker-slider-container').hide(); |
| 386 | }); |
| 387 | }, |
| 388 | loader; |
| 389 | |
| 390 | if (!self.confObj.editor) { |
| 391 | loader = $.Deferred(); |
| 392 | fm.loadCss([ |
| 393 | cdns.tui + '/tui-color-picker/latest/tui-color-picker.css', |
| 394 | cdns.tui + '/tui-image-editor/'+ver+'/tui-image-editor.css' |
| 395 | ]); |
| 396 | if (fm.hasRequire) { |
| 397 | require.config({ |
| 398 | paths : { |
| 399 | 'fabric/dist/fabric.require' : cdns.fabric + '/fabric.require.min', // for fabric < 2.0.1 |
| 400 | 'fabric' : cdns.fabric + '/fabric.min', // for fabric >= 2.0.1 |
| 401 | 'tui-code-snippet' : cdns.tui + '/tui.code-snippet/latest/tui-code-snippet.min', |
| 402 | 'tui-color-picker' : cdns.tui + '/tui-color-picker/latest/tui-color-picker.min', |
| 403 | 'tui-image-editor' : cdns.tui + '/tui-image-editor/'+ver+'/tui-image-editor.min' |
| 404 | } |
| 405 | }); |
| 406 | require(['tui-image-editor'], function(ImageEditor) { |
| 407 | loader.resolve(ImageEditor); |
| 408 | }); |
| 409 | } else { |
| 410 | fm.loadScript([ |
| 411 | cdns.fabric + '/fabric.min.js', |
| 412 | cdns.tui + '/tui.code-snippet/latest/tui-code-snippet.min.js' |
| 413 | ], function() { |
| 414 | fm.loadScript([ |
| 415 | cdns.tui + '/tui-color-picker/latest/tui-color-picker.min.js' |
| 416 | ], function() { |
| 417 | fm.loadScript([ |
| 418 | cdns.tui + '/tui-image-editor/'+ver+'/tui-image-editor.min.js' |
| 419 | ], function() { |
| 420 | loader.resolve(window.tui.ImageEditor); |
| 421 | }, { |
| 422 | loadType: 'tag' |
| 423 | }); |
| 424 | }, { |
| 425 | loadType: 'tag' |
| 426 | }); |
| 427 | }, { |
| 428 | loadType: 'tag' |
| 429 | }); |
| 430 | } |
| 431 | loader.done(function(editor) { |
| 432 | self.confObj.editor = editor; |
| 433 | init(editor); |
| 434 | }); |
| 435 | } else { |
| 436 | init(self.confObj.editor); |
| 437 | } |
| 438 | return dfrd; |
| 439 | }, |
| 440 | getContent : function(base) { |
| 441 | var editor = this.editor, |
| 442 | fm = editor.fm, |
| 443 | $base = $(base), |
| 444 | quality = $base.data('quality'); |
| 445 | if (editor.instance) { |
| 446 | if ($base.data('mime') === 'image/jpeg') { |
| 447 | quality = quality || fm.storage('jpgQuality') || fm.option('jpgQuality'); |
| 448 | quality = Math.max(0.1, Math.min(1, quality / 100)); |
| 449 | } |
| 450 | return editor.instance.toDataURL({ |
| 451 | format: getExtention($base.data('mime'), fm, true), |
| 452 | quality: quality |
| 453 | }); |
| 454 | } |
| 455 | }, |
| 456 | save : function(base) { |
| 457 | var $base = $(base), |
| 458 | quality = $base.data('quality'), |
| 459 | hash = $base.data('hash'), |
| 460 | file; |
| 461 | this.instance.deactivateAll(); |
| 462 | if (typeof quality !== 'undefined') { |
| 463 | this.fm.storage('jpgQuality', quality); |
| 464 | } |
| 465 | if (hash) { |
| 466 | file = this.fm.file(hash); |
| 467 | $base.data('mime', file.mime); |
| 468 | } |
| 469 | } |
| 470 | }, |
| 471 | { |
| 472 | // Photopea advanced image editor |
| 473 | info : { |
| 474 | id : 'photopea', |
| 475 | name : 'Photopea', |
| 476 | iconImg : 'img/editor-icons.png 0 -160', |
| 477 | single: true, |
| 478 | noContent: true, |
| 479 | arrayBufferContent: true, |
| 480 | openMaximized: true, |
| 481 | // Disable file types that cannot be saved on Photopea. |
| 482 | canMakeEmpty: ['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', 'image/x-icon', 'image/vnd-ms.dds', /*'application/x-msmetafile'*/], |
| 483 | integrate: { |
| 484 | title: 'Photopea', |
| 485 | link: 'https://www.photopea.com/learn/' |
| 486 | } |
| 487 | }, |
| 488 | 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', 'image/x-icon', 'image/vnd-ms.dds', 'application/x-msmetafile'], |
| 489 | html : '<iframe style="width:100%;height:100%;border:none;"></iframe>', |
| 490 | // setup on elFinder bootup |
| 491 | setup : function(opts, fm) { |
| 492 | if (fm.UA.IE || fm.UA.Mobile) { |
| 493 | this.disabled = true; |
| 494 | } |
| 495 | }, |
| 496 | // Initialization of editing node (this: this editors HTML node) |
| 497 | init : function(id, file, dum, fm) { |
| 498 | var orig = 'https://www.photopea.com', |
| 499 | ifm = $(this).hide() |
| 500 | //.css('box-sizing', 'border-box') |
| 501 | .on('load', function() { |
| 502 | //spnr.remove(); |
| 503 | ifm.show(); |
| 504 | }) |
| 505 | .on('error', function() { |
| 506 | spnr.remove(); |
| 507 | ifm.show(); |
| 508 | }), |
| 509 | editor = this.editor, |
| 510 | confObj = editor.confObj, |
| 511 | spnr = $('<div class="elfinder-edit-spinner elfinder-edit-photopea"></div>') |
| 512 | .html('<span class="elfinder-spinner-text">' + fm.i18n('nowLoading') + '</span><span class="elfinder-spinner"></span>') |
| 513 | .appendTo(ifm.parent()), |
| 514 | saveMimes = fm.arrayFlip(confObj.info.canMakeEmpty), |
| 515 | getType = function(mime) { |
| 516 | var ext = getExtention(mime, fm), |
| 517 | extmime = ext2mime[ext]; |
| 518 | |
| 519 | if (!confObj.mimesFlip[extmime]) { |
| 520 | ext = ''; |
| 521 | } else if (ext === 'jpeg') { |
| 522 | ext = 'jpg'; |
| 523 | } |
| 524 | if (!ext || !saveMimes[extmime]) { |
| 525 | ext = 'psd'; |
| 526 | extmime = ext2mime[ext]; |
| 527 | ifm.closest('.ui-dialog').trigger('changeType', { |
| 528 | extention: ext, |
| 529 | mime : extmime, |
| 530 | keepEditor: true |
| 531 | }); |
| 532 | } |
| 533 | return ext; |
| 534 | }, |
| 535 | mime = file.mime, |
| 536 | liveMsg, type, quty; |
| 537 | |
| 538 | if (!confObj.mimesFlip) { |
| 539 | confObj.mimesFlip = fm.arrayFlip(confObj.mimes, true); |
| 540 | } |
| 541 | if (!confObj.liveMsg) { |
| 542 | confObj.liveMsg = function(ifm, spnr, file) { |
| 543 | var wnd = ifm.get(0).contentWindow, |
| 544 | phase = 0, |
| 545 | data = null, |
| 546 | dfdIni = $.Deferred().done(function() { |
| 547 | spnr.remove(); |
| 548 | phase = 1; |
| 549 | wnd.postMessage(data, orig); |
| 550 | }), |
| 551 | dfdGet; |
| 552 | |
| 553 | this.load = function() { |
| 554 | return fm.getContents(file.hash, 'arraybuffer').done(function(d) { |
| 555 | data = d; |
| 556 | }); |
| 557 | }; |
| 558 | |
| 559 | this.receive = function(e) { |
| 560 | var ev = e.originalEvent, |
| 561 | state; |
| 562 | if (ev.origin === orig && ev.source === wnd) { |
| 563 | if (ev.data === 'done') { |
| 564 | if (phase === 0) { |
| 565 | dfdIni.resolve(); |
| 566 | } else if (phase === 1) { |
| 567 | phase = 2; |
| 568 | ifm.trigger('contentsloaded'); |
| 569 | } else { |
| 570 | if (dfdGet && dfdGet.state() === 'pending') { |
| 571 | dfdGet.reject('errDataEmpty'); |
| 572 | } |
| 573 | } |
| 574 | } else if (ev.data === 'Save') { |
| 575 | editor.doSave(); |
| 576 | } else { |
| 577 | if (dfdGet && dfdGet.state() === 'pending') { |
| 578 | if (typeof ev.data === 'object') { |
| 579 | dfdGet.resolve('data:' + mime + ';base64,' + fm.arrayBufferToBase64(ev.data)); |
| 580 | } else { |
| 581 | dfdGet.reject('errDataEmpty'); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | }; |
| 587 | |
| 588 | this.getContent = function() { |
| 589 | var type, q; |
| 590 | if (phase > 1) { |
| 591 | dfdGet && dfdGet.state() === 'pending' && dfdGet.reject(); |
| 592 | dfdGet = null; |
| 593 | dfdGet = $.Deferred(); |
| 594 | if (phase === 2) { |
| 595 | phase = 3; |
| 596 | dfdGet.resolve('data:' + mime + ';base64,' + fm.arrayBufferToBase64(data)); |
| 597 | data = null; |
| 598 | return dfdGet; |
| 599 | } |
| 600 | if (ifm.data('mime')) { |
| 601 | mime = ifm.data('mime'); |
| 602 | type = getType(mime); |
| 603 | } |
| 604 | if (q = ifm.data('quality')) { |
| 605 | type += ':' + (q / 100); |
| 606 | } |
| 607 | wnd.postMessage('app.activeDocument.saveToOE("' + type + '")', orig); |
| 608 | return dfdGet; |
| 609 | } |
| 610 | }; |
| 611 | }; |
| 612 | } |
| 613 | |
| 614 | ifm.parent().css('padding', 0); |
| 615 | type = getType(file.mime); |
| 616 | liveMsg = editor.liveMsg = new confObj.liveMsg(ifm, spnr, file); |
| 617 | $(window).on('message.' + fm.namespace, liveMsg.receive); |
| 618 | liveMsg.load().done(function() { |
| 619 | var d = JSON.stringify({ |
| 620 | files : [], |
| 621 | environment : { |
| 622 | lang: fm.lang.replace(/_/g, '-'), |
| 623 | customIO: {"save": "app.echoToOE(\"Save\");"} |
| 624 | } |
| 625 | }); |
| 626 | ifm.attr('src', orig + '/#' + encodeURI(d)); |
| 627 | }).fail(function(err) { |
| 628 | err && fm.error(err); |
| 629 | editor.initFail = true; |
| 630 | }); |
| 631 | |
| 632 | // jpeg quality controls |
| 633 | if (file.mime === 'image/jpeg' || file.mime === 'image/webp') { |
| 634 | ifm.data('quality', fm.storage('jpgQuality') || fm.option('jpgQuality')); |
| 635 | quty = $('<input type="number" class="ui-corner-all elfinder-resize-quality elfinder-tabstop"/>') |
| 636 | .attr('min', '1') |
| 637 | .attr('max', '100') |
| 638 | .attr('title', '1 - 100') |
| 639 | .on('change', function() { |
| 640 | var q = quty.val(); |
| 641 | ifm.data('quality', q); |
| 642 | }) |
| 643 | .val(ifm.data('quality')); |
| 644 | $('<div class="ui-dialog-buttonset elfinder-edit-extras elfinder-edit-extras-quality"></div>') |
| 645 | .append( |
| 646 | $('<span>').html(fm.i18n('quality') + ' : '), quty, $('<span></span>') |
| 647 | ) |
| 648 | .prependTo(ifm.parent().next()); |
| 649 | } |
| 650 | }, |
| 651 | load : function(base) { |
| 652 | var dfd = $.Deferred(), |
| 653 | self = this, |
| 654 | fm = this.fm, |
| 655 | $base = $(base); |
| 656 | if (self.initFail) { |
| 657 | dfd.reject(); |
| 658 | } else { |
| 659 | $base.on('contentsloaded', function() { |
| 660 | dfd.resolve(self.liveMsg); |
| 661 | }); |
| 662 | } |
| 663 | return dfd; |
| 664 | }, |
| 665 | getContent : function() { |
| 666 | return this.editor.liveMsg? this.editor.liveMsg.getContent() : void(0); |
| 667 | }, |
| 668 | save : function(base, liveMsg) { |
| 669 | var $base = $(base), |
| 670 | quality = $base.data('quality'), |
| 671 | hash = $base.data('hash'), |
| 672 | file; |
| 673 | if (typeof quality !== 'undefined') { |
| 674 | this.fm.storage('jpgQuality', quality); |
| 675 | } |
| 676 | if (hash) { |
| 677 | file = this.fm.file(hash); |
| 678 | $base.data('mime', file.mime); |
| 679 | } else { |
| 680 | $base.removeData('mime'); |
| 681 | } |
| 682 | }, |
| 683 | // On dialog closed |
| 684 | close : function(base, liveMsg) { |
| 685 | $(base).attr('src', ''); |
| 686 | liveMsg && $(window).off('message.' + this.fm.namespace, liveMsg.receive); |
| 687 | } |
| 688 | }, |
| 689 | { |
| 690 | // Pixo is cross-platform image editor |
| 691 | info : { |
| 692 | id : 'pixo', |
| 693 | name : 'Pixo Editor', |
| 694 | iconImg : 'img/editor-icons.png 0 -208', |
| 695 | dataScheme: true, |
| 696 | schemeContent: true, |
| 697 | single: true, |
| 698 | canMakeEmpty: false, |
| 699 | integrate: { |
| 700 | title: 'Pixo Editor', |
| 701 | link: 'https://pixoeditor.com/privacy-policy/' |
| 702 | } |
| 703 | }, |
| 704 | // MIME types to accept |
| 705 | mimes : ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/x-ms-bmp'], |
| 706 | // HTML of this editor |
| 707 | html : '<div class="elfinder-edit-imageeditor"><img/></div>', |
| 708 | // called on initialization of elFinder cmd edit (this: this editor's config object) |
| 709 | setup : function(opts, fm) { |
| 710 | if (fm.UA.ltIE8 || !opts.extraOptions || !opts.extraOptions.pixo || !opts.extraOptions.pixo.apikey) { |
| 711 | this.disabled = true; |
| 712 | } else { |
| 713 | this.editorOpts = opts.extraOptions.pixo; |
| 714 | } |
| 715 | }, |
| 716 | // Initialization of editing node (this: this editors HTML node) |
| 717 | init : function(id, file, content, fm) { |
| 718 | initImgTag.call(this, id, file, content, fm); |
| 719 | }, |
| 720 | // Get data uri scheme (this: this editors HTML node) |
| 721 | getContent : function() { |
| 722 | return $(this).children('img:first').attr('src'); |
| 723 | }, |
| 724 | // Launch Pixo editor when dialog open |
| 725 | load : function(base) { |
| 726 | var self = this, |
| 727 | fm = this.fm, |
| 728 | $base = $(base), |
| 729 | node = $base.children('img:first'), |
| 730 | dialog = $base.closest('.ui-dialog'), |
| 731 | elfNode = fm.getUI(), |
| 732 | dfrd = $.Deferred(), |
| 733 | container = $('#elfinder-pixo-container'), |
| 734 | init = function(onload) { |
| 735 | var opts; |
| 736 | |
| 737 | if (!container.length) { |
| 738 | container = $('<div id="elfinder-pixo-container" class="ui-front"></div>').css({ |
| 739 | position: 'fixed', |
| 740 | top: 0, |
| 741 | right: 0, |
| 742 | width: '100%', |
| 743 | height: $(window).height(), |
| 744 | overflow: 'hidden' |
| 745 | }).hide().appendTo(elfNode.hasClass('elfinder-fullscreen')? elfNode : 'body'); |
| 746 | // bind switch fullscreen event |
| 747 | elfNode.on('resize.'+fm.namespace, function(e, data) { |
| 748 | e.preventDefault(); |
| 749 | e.stopPropagation(); |
| 750 | data && data.fullscreen && container.appendTo(data.fullscreen === 'on'? elfNode : 'body'); |
| 751 | }); |
| 752 | fm.bind('destroy', function() { |
| 753 | editor && editor.cancelEditing(); |
| 754 | container.remove(); |
| 755 | }); |
| 756 | } else { |
| 757 | // always moves to last |
| 758 | container.appendTo(container.parent()); |
| 759 | } |
| 760 | node.on('click', launch); |
| 761 | // Constructor options |
| 762 | opts = Object.assign({ |
| 763 | type: 'child', |
| 764 | parent: container.get(0), |
| 765 | output: {format: 'png'}, |
| 766 | onSave: function(arg) { |
| 767 | // Check current file.hash, all callbacks are called on multiple instances |
| 768 | var mime = arg.toBlob().type, |
| 769 | ext = getExtention(mime, fm), |
| 770 | draw = function(url) { |
| 771 | node.one('load error', function() { |
| 772 | node.data('loading') && node.data('loading')(true); |
| 773 | }) |
| 774 | .attr('crossorigin', 'anonymous') |
| 775 | .attr('src', url); |
| 776 | }, |
| 777 | url = arg.toDataURL(); |
| 778 | node.data('loading')(); |
| 779 | delete base._canvas; |
| 780 | if (node.data('ext') !== ext) { |
| 781 | changeImageType(url, self.file.mime).done(function(res, cv) { |
| 782 | if (cv) { |
| 783 | base._canvas = canvas = cv; |
| 784 | quty.trigger('change'); |
| 785 | qBase && qBase.show(); |
| 786 | } |
| 787 | draw(res); |
| 788 | }).fail(function() { |
| 789 | dialog.trigger('changeType', { |
| 790 | extention: ext, |
| 791 | mime : mime |
| 792 | }); |
| 793 | draw(url); |
| 794 | }); |
| 795 | } else { |
| 796 | draw(url); |
| 797 | } |
| 798 | }, |
| 799 | onClose: function() { |
| 800 | dialog.removeClass(fm.res('class', 'preventback')); |
| 801 | fm.toggleMaximize(container, false); |
| 802 | container.hide(); |
| 803 | fm.toFront(dialog); |
| 804 | } |
| 805 | }, self.confObj.editorOpts); |
| 806 | // trigger event 'editEditorPrepare' |
| 807 | self.trigger('Prepare', { |
| 808 | node: base, |
| 809 | editorObj: Pixo, |
| 810 | instance: void(0), |
| 811 | opts: opts |
| 812 | }); |
| 813 | // make editor instance |
| 814 | editor = new Pixo.Bridge(opts); |
| 815 | dfrd.resolve(editor); |
| 816 | $base.on('saveAsFail', launch); |
| 817 | if (onload) { |
| 818 | onload(); |
| 819 | } |
| 820 | }, |
| 821 | launch = function() { |
| 822 | dialog.addClass(fm.res('class', 'preventback')); |
| 823 | fm.toggleMaximize(container, true); |
| 824 | fm.toFront(container); |
| 825 | container.show().data('curhash', self.file.hash); |
| 826 | editor.edit(node.get(0)); |
| 827 | node.data('loading')(true); |
| 828 | }, |
| 829 | qBase, quty, qutyTm, canvas, editor; |
| 830 | |
| 831 | node.data('loading')(); |
| 832 | |
| 833 | // jpeg quality controls |
| 834 | if (self.file.mime === 'image/jpeg') { |
| 835 | quty = $('<input type="number" class="ui-corner-all elfinder-resize-quality elfinder-tabstop"/>') |
| 836 | .attr('min', '1') |
| 837 | .attr('max', '100') |
| 838 | .attr('title', '1 - 100') |
| 839 | .on('change', function() { |
| 840 | var q = quty.val(); |
| 841 | qutyTm && cancelAnimationFrame(qutyTm); |
| 842 | qutyTm = requestAnimationFrame(function() { |
| 843 | if (canvas) { |
| 844 | canvas.toBlob(function(blob) { |
| 845 | blob && quty.next('span').text(' (' + fm.formatSize(blob.size) + ')'); |
| 846 | }, 'image/jpeg', Math.max(Math.min(q, 100), 1) / 100); |
| 847 | } |
| 848 | }); |
| 849 | }) |
| 850 | .val(fm.storage('jpgQuality') || fm.option('jpgQuality')); |
| 851 | qBase = $('<div class="ui-dialog-buttonset elfinder-edit-extras elfinder-edit-extras-quality"></div>') |
| 852 | .hide() |
| 853 | .append( |
| 854 | $('<span>').html(fm.i18n('quality') + ' : '), quty, $('<span></span>') |
| 855 | ) |
| 856 | .prependTo($base.parent().next()); |
| 857 | $base.data('quty', quty); |
| 858 | } |
| 859 | |
| 860 | // load script then init |
| 861 | if (typeof Pixo === 'undefined') { |
| 862 | fm.loadScript(['https://pixoeditor.com:8443/editor/scripts/bridge.m.js'], function() { |
| 863 | init(launch); |
| 864 | }, {loadType: 'tag'}); |
| 865 | } else { |
| 866 | init(); |
| 867 | launch(); |
| 868 | } |
| 869 | return dfrd; |
| 870 | }, |
| 871 | // Convert content url to data uri scheme to save content |
| 872 | save : function(base) { |
| 873 | var self = this, |
| 874 | $base = $(base), |
| 875 | node = $base.children('img:first'), |
| 876 | q; |
| 877 | if (base._canvas) { |
| 878 | if ($base.data('quty')) { |
| 879 | q = $base.data('quty').val(); |
| 880 | q && this.fm.storage('jpgQuality', q); |
| 881 | } |
| 882 | node.attr('src', base._canvas.toDataURL(self.file.mime, q? Math.max(Math.min(q, 100), 1) / 100 : void(0))); |
| 883 | } else if (node.attr('src').substr(0, 5) !== 'data:') { |
| 884 | node.attr('src', imgBase64(node, this.file.mime)); |
| 885 | } |
| 886 | }, |
| 887 | close : function(base, editor) { |
| 888 | editor && editor.destroy(); |
| 889 | } |
| 890 | }, |
| 891 | { |
| 892 | // ACE Editor |
| 893 | // called on initialization of elFinder cmd edit (this: this editor's config object) |
| 894 | setup : function(opts, fm) { |
| 895 | if (fm.UA.ltIE8 || !fm.options.cdns.ace) { |
| 896 | this.disabled = true; |
| 897 | } |
| 898 | }, |
| 899 | // `mimes` is not set for support everything kind of text file |
| 900 | info : { |
| 901 | id : 'aceeditor', |
| 902 | name : 'ACE Editor', |
| 903 | iconImg : 'img/editor-icons.png 0 -96' |
| 904 | }, |
| 905 | load : function(textarea) { |
| 906 | var self = this, |
| 907 | fm = this.fm, |
| 908 | dfrd = $.Deferred(), |
| 909 | cdn = fm.options.cdns.ace, |
| 910 | start = function() { |
| 911 | var editor, editorBase, mode, |
| 912 | ta = $(textarea), |
| 913 | taBase = ta.parent(), |
| 914 | dialog = taBase.parent(), |
| 915 | id = textarea.id + '_ace', |
| 916 | ext = self.file.name.replace(/^.+\.([^.]+)|(.+)$/, '$1$2').toLowerCase(), |
| 917 | // MIME/mode map |
| 918 | mimeMode = { |
| 919 | 'text/x-php' : 'php', |
| 920 | 'application/x-php' : 'php', |
| 921 | 'text/html' : 'html', |
| 922 | 'application/xhtml+xml' : 'html', |
| 923 | 'text/javascript' : 'javascript', |
| 924 | 'application/javascript' : 'javascript', |
| 925 | 'text/css' : 'css', |
| 926 | 'text/x-c' : 'c_cpp', |
| 927 | 'text/x-csrc' : 'c_cpp', |
| 928 | 'text/x-chdr' : 'c_cpp', |
| 929 | 'text/x-c++' : 'c_cpp', |
| 930 | 'text/x-c++src' : 'c_cpp', |
| 931 | 'text/x-c++hdr' : 'c_cpp', |
| 932 | 'text/x-shellscript' : 'sh', |
| 933 | 'application/x-csh' : 'sh', |
| 934 | 'text/x-python' : 'python', |
| 935 | 'text/x-java' : 'java', |
| 936 | 'text/x-java-source' : 'java', |
| 937 | 'text/x-ruby' : 'ruby', |
| 938 | 'text/x-perl' : 'perl', |
| 939 | 'application/x-perl' : 'perl', |
| 940 | 'text/x-sql' : 'sql', |
| 941 | 'text/xml' : 'xml', |
| 942 | 'application/docbook+xml' : 'xml', |
| 943 | 'application/xml' : 'xml' |
| 944 | }; |
| 945 | |
| 946 | // set base height |
| 947 | taBase.height(taBase.height()); |
| 948 | |
| 949 | // set basePath of ace |
| 950 | ace.config.set('basePath', cdn); |
| 951 | |
| 952 | // Base node of Ace editor |
| 953 | editorBase = $('<div id="'+id+'" style="width:100%; height:100%;"></div>').text(ta.val()).insertBefore(ta.hide()); |
| 954 | |
| 955 | // Editor flag |
| 956 | ta.data('ace', true); |
| 957 | |
| 958 | // Aceeditor instance |
| 959 | editor = ace.edit(id); |
| 960 | |
| 961 | // Ace editor configure |
| 962 | editor.$blockScrolling = Infinity; |
| 963 | editor.setOptions({ |
| 964 | theme: 'ace/theme/monokai', |
| 965 | fontSize: '14px', |
| 966 | wrap: true, |
| 967 | }); |
| 968 | ace.config.loadModule('ace/ext/modelist', function() { |
| 969 | // detect mode |
| 970 | mode = ace.require('ace/ext/modelist').getModeForPath('/' + self.file.name).name; |
| 971 | if (mode === 'text') { |
| 972 | if (mimeMode[self.file.mime]) { |
| 973 | mode = mimeMode[self.file.mime]; |
| 974 | } |
| 975 | } |
| 976 | // show MIME:mode in title bar |
| 977 | taBase.prev().children('.elfinder-dialog-title').append(' (' + self.file.mime + ' : ' + mode.split(/[\/\\]/).pop() + ')'); |
| 978 | editor.setOptions({ |
| 979 | mode: 'ace/mode/' + mode |
| 980 | }); |
| 981 | if (dfrd.state() === 'resolved') { |
| 982 | dialog.trigger('resize'); |
| 983 | } |
| 984 | }); |
| 985 | ace.config.loadModule('ace/ext/language_tools', function() { |
| 986 | ace.require('ace/ext/language_tools'); |
| 987 | editor.setOptions({ |
| 988 | enableBasicAutocompletion: true, |
| 989 | enableSnippets: true, |
| 990 | enableLiveAutocompletion: false |
| 991 | }); |
| 992 | }); |
| 993 | ace.config.loadModule('ace/ext/settings_menu', function() { |
| 994 | ace.require('ace/ext/settings_menu').init(editor); |
| 995 | }); |
| 996 | |
| 997 | // Short cuts |
| 998 | editor.commands.addCommand({ |
| 999 | name : "saveFile", |
| 1000 | bindKey: { |
| 1001 | win : 'Ctrl-s', |
| 1002 | mac : 'Command-s' |
| 1003 | }, |
| 1004 | exec: function(editor) { |
| 1005 | self.doSave(); |
| 1006 | } |
| 1007 | }); |
| 1008 | editor.commands.addCommand({ |
| 1009 | name : "closeEditor", |
| 1010 | bindKey: { |
| 1011 | win : 'Ctrl-w|Ctrl-q', |
| 1012 | mac : 'Command-w|Command-q' |
| 1013 | }, |
| 1014 | exec: function(editor) { |
| 1015 | self.doCancel(); |
| 1016 | } |
| 1017 | }); |
| 1018 | |
| 1019 | editor.resize(); |
| 1020 | |
| 1021 | // TextArea button and Setting button |
| 1022 | $('<div class="ui-dialog-buttonset"></div>').css('float', 'left') |
| 1023 | .append( |
| 1024 | $('<button></button>').html(self.fm.i18n('TextArea')) |
| 1025 | .button() |
| 1026 | .on('click', function(){ |
| 1027 | if (ta.data('ace')) { |
| 1028 | ta.removeData('ace'); |
| 1029 | editorBase.hide(); |
| 1030 | ta.val(editor.session.getValue()).show().trigger('focus'); |
| 1031 | $(this).text('AceEditor'); |
| 1032 | } else { |
| 1033 | ta.data('ace', true); |
| 1034 | editorBase.show(); |
| 1035 | editor.setValue(ta.hide().val(), -1); |
| 1036 | editor.focus(); |
| 1037 | $(this).html(self.fm.i18n('TextArea')); |
| 1038 | } |
| 1039 | }) |
| 1040 | ) |
| 1041 | .append( |
| 1042 | $('<button>Ace editor setting</button>') |
| 1043 | .button({ |
| 1044 | icons: { |
| 1045 | primary: 'ui-icon-gear', |
| 1046 | secondary: 'ui-icon-triangle-1-e' |
| 1047 | }, |
| 1048 | text: false |
| 1049 | }) |
| 1050 | .on('click', function(){ |
| 1051 | editor.showSettingsMenu(); |
| 1052 | $('#ace_settingsmenu') |
| 1053 | .css('font-size', '80%') |
| 1054 | .find('div[contains="setOptions"]').hide().end() |
| 1055 | .parent().appendTo($('#elfinder')); |
| 1056 | }) |
| 1057 | ) |
| 1058 | .prependTo(taBase.next()); |
| 1059 | |
| 1060 | // trigger event 'editEditorPrepare' |
| 1061 | self.trigger('Prepare', { |
| 1062 | node: textarea, |
| 1063 | editorObj: ace, |
| 1064 | instance: editor, |
| 1065 | opts: {} |
| 1066 | }); |
| 1067 | |
| 1068 | //dialog.trigger('resize'); |
| 1069 | dfrd.resolve(editor); |
| 1070 | }; |
| 1071 | |
| 1072 | // check ace & start |
| 1073 | if (!self.confObj.loader) { |
| 1074 | self.confObj.loader = $.Deferred(); |
| 1075 | self.fm.loadScript([ cdn+'/ace.js' ], function() { |
| 1076 | self.confObj.loader.resolve(); |
| 1077 | }, void 0, {obj: window, name: 'ace'}); |
| 1078 | } |
| 1079 | self.confObj.loader.done(start); |
| 1080 | |
| 1081 | return dfrd; |
| 1082 | }, |
| 1083 | close : function(textarea, instance) { |
| 1084 | instance && instance.destroy(); |
| 1085 | }, |
| 1086 | save : function(textarea, instance) { |
| 1087 | instance && $(textarea).data('ace') && (textarea.value = instance.session.getValue()); |
| 1088 | }, |
| 1089 | focus : function(textarea, instance) { |
| 1090 | instance && $(textarea).data('ace') && instance.focus(); |
| 1091 | }, |
| 1092 | resize : function(textarea, instance, e, data) { |
| 1093 | instance && instance.resize(); |
| 1094 | } |
| 1095 | }, |
| 1096 | { |
| 1097 | // CodeMirror |
| 1098 | // called on initialization of elFinder cmd edit (this: this editor's config object) |
| 1099 | setup : function(opts, fm) { |
| 1100 | if (fm.UA.ltIE10 || !fm.options.cdns.codemirror) { |
| 1101 | this.disabled = true; |
| 1102 | } |
| 1103 | }, |
| 1104 | // `mimes` is not set for support everything kind of text file |
| 1105 | info : { |
| 1106 | id : 'codemirror', |
| 1107 | name : 'CodeMirror', |
| 1108 | iconImg : 'img/editor-icons.png 0 -176' |
| 1109 | }, |
| 1110 | load : function(textarea) { |
| 1111 | var fm = this.fm, |
| 1112 | cmUrl = fm.convAbsUrl(fm.options.cdns.codemirror), |
| 1113 | dfrd = $.Deferred(), |
| 1114 | self = this, |
| 1115 | start = function(CodeMirror) { |
| 1116 | var ta = $(textarea), |
| 1117 | base = ta.parent(), |
| 1118 | editor, editorBase, opts; |
| 1119 | |
| 1120 | // set base height |
| 1121 | base.height(base.height()); |
| 1122 | |
| 1123 | // CodeMirror configure options |
| 1124 | opts = { |
| 1125 | lineNumbers: true, |
| 1126 | lineWrapping: true, |
| 1127 | extraKeys : { |
| 1128 | 'Ctrl-S': function() { self.doSave(); }, |
| 1129 | 'Ctrl-Q': function() { self.doCancel(); }, |
| 1130 | 'Ctrl-W': function() { self.doCancel(); } |
| 1131 | } |
| 1132 | }; |
| 1133 | |
| 1134 | // trigger event 'editEditorPrepare' |
| 1135 | self.trigger('Prepare', { |
| 1136 | node: textarea, |
| 1137 | editorObj: CodeMirror, |
| 1138 | instance: void(0), |
| 1139 | opts: opts |
| 1140 | }); |
| 1141 | |
| 1142 | // CodeMirror configure |
| 1143 | editor = CodeMirror.fromTextArea(textarea, opts); |
| 1144 | |
| 1145 | // return editor instance |
| 1146 | dfrd.resolve(editor); |
| 1147 | |
| 1148 | // Auto mode set |
| 1149 | var info, m, mode, spec; |
| 1150 | if (! info) { |
| 1151 | info = CodeMirror.findModeByMIME(self.file.mime); |
| 1152 | } |
| 1153 | if (! info && (m = self.file.name.match(/.+\.([^.]+)$/))) { |
| 1154 | info = CodeMirror.findModeByExtension(m[1]); |
| 1155 | } |
| 1156 | if (info) { |
| 1157 | CodeMirror.modeURL = useRequire? 'codemirror/mode/%N/%N.min' : cmUrl + '/mode/%N/%N.min.js'; |
| 1158 | mode = info.mode; |
| 1159 | spec = info.mime; |
| 1160 | editor.setOption('mode', spec); |
| 1161 | CodeMirror.autoLoadMode(editor, mode); |
| 1162 | // show MIME:mode in title bar |
| 1163 | base.prev().children('.elfinder-dialog-title').append(' (' + spec + (mode != 'null'? ' : ' + mode : '') + ')'); |
| 1164 | } |
| 1165 | |
| 1166 | // editor base node |
| 1167 | editorBase = $(editor.getWrapperElement()).css({ |
| 1168 | // fix CSS conflict to SimpleMDE |
| 1169 | padding: 0, |
| 1170 | border: 'none' |
| 1171 | }); |
| 1172 | ta.data('cm', true); |
| 1173 | |
| 1174 | // fit height to base |
| 1175 | editorBase.height('100%'); |
| 1176 | |
| 1177 | // TextArea button and Setting button |
| 1178 | $('<div class="ui-dialog-buttonset"></div>').css('float', 'left') |
| 1179 | .append( |
| 1180 | $('<button></button>').html(self.fm.i18n('TextArea')) |
| 1181 | .button() |
| 1182 | .on('click', function(){ |
| 1183 | if (ta.data('cm')) { |
| 1184 | ta.removeData('cm'); |
| 1185 | editorBase.hide(); |
| 1186 | ta.val(editor.getValue()).show().trigger('focus'); |
| 1187 | $(this).text('CodeMirror'); |
| 1188 | } else { |
| 1189 | ta.data('cm', true); |
| 1190 | editorBase.show(); |
| 1191 | editor.setValue(ta.hide().val()); |
| 1192 | editor.refresh(); |
| 1193 | editor.focus(); |
| 1194 | $(this).html(self.fm.i18n('TextArea')); |
| 1195 | } |
| 1196 | }) |
| 1197 | ) |
| 1198 | .prependTo(base.next()); |
| 1199 | }; |
| 1200 | // load script then start |
| 1201 | if (!self.confObj.loader) { |
| 1202 | self.confObj.loader = $.Deferred(); |
| 1203 | if (useRequire) { |
| 1204 | require.config({ |
| 1205 | packages: [{ |
| 1206 | name: 'codemirror', |
| 1207 | location: cmUrl, |
| 1208 | main: 'codemirror.min' |
| 1209 | }], |
| 1210 | map: { |
| 1211 | 'codemirror': { |
| 1212 | 'codemirror/lib/codemirror': 'codemirror' |
| 1213 | } |
| 1214 | } |
| 1215 | }); |
| 1216 | require([ |
| 1217 | 'codemirror', |
| 1218 | 'codemirror/addon/mode/loadmode.min', |
| 1219 | 'codemirror/mode/meta.min' |
| 1220 | ], function(CodeMirror) { |
| 1221 | self.confObj.loader.resolve(CodeMirror); |
| 1222 | }); |
| 1223 | } else { |
| 1224 | self.fm.loadScript([ |
| 1225 | cmUrl + '/codemirror.min.js' |
| 1226 | ], function() { |
| 1227 | self.fm.loadScript([ |
| 1228 | cmUrl + '/addon/mode/loadmode.min.js', |
| 1229 | cmUrl + '/mode/meta.min.js' |
| 1230 | ], function() { |
| 1231 | self.confObj.loader.resolve(CodeMirror); |
| 1232 | }); |
| 1233 | }, {loadType: 'tag'}); |
| 1234 | } |
| 1235 | self.fm.loadCss(cmUrl + '/codemirror.css'); |
| 1236 | } |
| 1237 | self.confObj.loader.done(start); |
| 1238 | return dfrd; |
| 1239 | }, |
| 1240 | close : function(textarea, instance) { |
| 1241 | instance && instance.toTextArea(); |
| 1242 | }, |
| 1243 | save : function(textarea, instance) { |
| 1244 | instance && $(textarea).data('cm') && (textarea.value = instance.getValue()); |
| 1245 | }, |
| 1246 | focus : function(textarea, instance) { |
| 1247 | instance && $(textarea).data('cm') && instance.focus(); |
| 1248 | }, |
| 1249 | resize : function(textarea, instance, e, data) { |
| 1250 | instance && instance.refresh(); |
| 1251 | } |
| 1252 | }, |
| 1253 | { |
| 1254 | // SimpleMDE |
| 1255 | // called on initialization of elFinder cmd edit (this: this editor's config object) |
| 1256 | setup : function(opts, fm) { |
| 1257 | if (fm.UA.ltIE10 || !fm.options.cdns.simplemde) { |
| 1258 | this.disabled = true; |
| 1259 | } |
| 1260 | }, |
| 1261 | info : { |
| 1262 | id : 'simplemde', |
| 1263 | name : 'SimpleMDE', |
| 1264 | iconImg : 'img/editor-icons.png 0 -80' |
| 1265 | }, |
| 1266 | exts : ['md'], |
| 1267 | load : function(textarea) { |
| 1268 | var self = this, |
| 1269 | fm = this.fm, |
| 1270 | base = $(textarea).parent(), |
| 1271 | dfrd = $.Deferred(), |
| 1272 | cdn = fm.options.cdns.simplemde, |
| 1273 | start = function(SimpleMDE) { |
| 1274 | var h = base.height(), |
| 1275 | delta = base.outerHeight(true) - h + 14, |
| 1276 | editor, editorBase, opts; |
| 1277 | |
| 1278 | // fit height function |
| 1279 | textarea._setHeight = function(height) { |
| 1280 | var h = height || base.height(), |
| 1281 | ctrH = 0, |
| 1282 | areaH; |
| 1283 | base.children('.editor-toolbar,.editor-statusbar').each(function() { |
| 1284 | ctrH += $(this).outerHeight(true); |
| 1285 | }); |
| 1286 | areaH = h - ctrH - delta; |
| 1287 | editorBase.height(areaH); |
| 1288 | editor.codemirror.refresh(); |
| 1289 | return areaH; |
| 1290 | }; |
| 1291 | |
| 1292 | // set base height |
| 1293 | base.height(h); |
| 1294 | |
| 1295 | opts = { |
| 1296 | element: textarea, |
| 1297 | autofocus: true |
| 1298 | }; |
| 1299 | |
| 1300 | // trigger event 'editEditorPrepare' |
| 1301 | self.trigger('Prepare', { |
| 1302 | node: textarea, |
| 1303 | editorObj: SimpleMDE, |
| 1304 | instance: void(0), |
| 1305 | opts: opts |
| 1306 | }); |
| 1307 | |
| 1308 | // make editor |
| 1309 | editor = new SimpleMDE(opts); |
| 1310 | dfrd.resolve(editor); |
| 1311 | |
| 1312 | // editor base node |
| 1313 | editorBase = $(editor.codemirror.getWrapperElement()); |
| 1314 | |
| 1315 | // fit height to base |
| 1316 | editorBase.css('min-height', '50px') |
| 1317 | .children('.CodeMirror-scroll').css('min-height', '50px'); |
| 1318 | textarea._setHeight(h); |
| 1319 | }; |
| 1320 | |
| 1321 | // check SimpleMDE & start |
| 1322 | if (!self.confObj.loader) { |
| 1323 | self.confObj.loader = $.Deferred(); |
| 1324 | self.fm.loadCss(cdn+'/simplemde.min.css'); |
| 1325 | if (useRequire) { |
| 1326 | require([ |
| 1327 | cdn+'/simplemde.min.js' |
| 1328 | ], function(SimpleMDE) { |
| 1329 | self.confObj.loader.resolve(SimpleMDE); |
| 1330 | }); |
| 1331 | } else { |
| 1332 | self.fm.loadScript([cdn+'/simplemde.min.js'], function() { |
| 1333 | self.confObj.loader.resolve(SimpleMDE); |
| 1334 | }, {loadType: 'tag'}); |
| 1335 | } |
| 1336 | } |
| 1337 | self.confObj.loader.done(start); |
| 1338 | |
| 1339 | return dfrd; |
| 1340 | }, |
| 1341 | close : function(textarea, instance) { |
| 1342 | instance && instance.toTextArea(); |
| 1343 | instance = null; |
| 1344 | }, |
| 1345 | save : function(textarea, instance) { |
| 1346 | instance && (textarea.value = instance.value()); |
| 1347 | }, |
| 1348 | focus : function(textarea, instance) { |
| 1349 | instance && instance.codemirror.focus(); |
| 1350 | }, |
| 1351 | resize : function(textarea, instance, e, data) { |
| 1352 | instance && textarea._setHeight(); |
| 1353 | } |
| 1354 | }, |
| 1355 | { |
| 1356 | // CKEditor for html file |
| 1357 | info : { |
| 1358 | id : 'ckeditor', |
| 1359 | name : 'CKEditor', |
| 1360 | iconImg : 'img/editor-icons.png 0 0' |
| 1361 | }, |
| 1362 | exts : ['htm', 'html', 'xhtml'], |
| 1363 | setup : function(opts, fm) { |
| 1364 | var confObj = this; |
| 1365 | if (!fm.options.cdns.ckeditor) { |
| 1366 | confObj.disabled = true; |
| 1367 | } else { |
| 1368 | confObj.ckeOpts = {}; |
| 1369 | if (opts.extraOptions) { |
| 1370 | confObj.ckeOpts = Object.assign({}, opts.extraOptions.ckeditor || {}); |
| 1371 | if (opts.extraOptions.managerUrl) { |
| 1372 | confObj.managerUrl = opts.extraOptions.managerUrl; |
| 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | }, |
| 1377 | load : function(textarea) { |
| 1378 | var self = this, |
| 1379 | fm = this.fm, |
| 1380 | dfrd = $.Deferred(), |
| 1381 | init = function() { |
| 1382 | var base = $(textarea).parent(), |
| 1383 | dlg = base.closest('.elfinder-dialog'), |
| 1384 | h = base.height(), |
| 1385 | reg = /([&?]getfile=)[^&]+/, |
| 1386 | loc = self.confObj.managerUrl || window.location.href.replace(/#.*$/, ''), |
| 1387 | name = 'ckeditor', |
| 1388 | opts; |
| 1389 | |
| 1390 | // make manager location |
| 1391 | if (reg.test(loc)) { |
| 1392 | loc = loc.replace(reg, '$1' + name); |
| 1393 | } else { |
| 1394 | loc += '?getfile=' + name; |
| 1395 | } |
| 1396 | // set base height |
| 1397 | base.height(h); |
| 1398 | |
| 1399 | // CKEditor configure options |
| 1400 | opts = { |
| 1401 | startupFocus : true, |
| 1402 | fullPage: true, |
| 1403 | allowedContent: true, |
| 1404 | filebrowserBrowseUrl : loc, |
| 1405 | toolbarCanCollapse: true, |
| 1406 | toolbarStartupExpanded: !fm.UA.Mobile, |
| 1407 | removePlugins: 'resize', |
| 1408 | extraPlugins: 'colorbutton,justify,docprops', |
| 1409 | on: { |
| 1410 | 'instanceReady' : function(e) { |
| 1411 | var editor = e.editor; |
| 1412 | editor.resize('100%', h); |
| 1413 | // re-build on dom move |
| 1414 | dlg.one('beforedommove.'+fm.namespace, function() { |
| 1415 | editor.destroy(); |
| 1416 | }).one('dommove.'+fm.namespace, function() { |
| 1417 | self.load(textarea).done(function(editor) { |
| 1418 | self.instance = editor; |
| 1419 | }); |
| 1420 | }); |
| 1421 | // return editor instance |
| 1422 | dfrd.resolve(e.editor); |
| 1423 | } |
| 1424 | } |
| 1425 | }; |
| 1426 | |
| 1427 | // trigger event 'editEditorPrepare' |
| 1428 | self.trigger('Prepare', { |
| 1429 | node: textarea, |
| 1430 | editorObj: CKEDITOR, |
| 1431 | instance: void(0), |
| 1432 | opts: opts |
| 1433 | }); |
| 1434 | |
| 1435 | // CKEditor configure |
| 1436 | CKEDITOR.replace(textarea.id, Object.assign(opts, self.confObj.ckeOpts)); |
| 1437 | CKEDITOR.on('dialogDefinition', function(e) { |
| 1438 | var dlg = e.data.definition.dialog; |
| 1439 | dlg.on('show', function(e) { |
| 1440 | fm.getUI().append($('.cke_dialog_background_cover')).append(this.getElement().$); |
| 1441 | }); |
| 1442 | dlg.on('hide', function(e) { |
| 1443 | $('body:first').append($('.cke_dialog_background_cover')).append(this.getElement().$); |
| 1444 | }); |
| 1445 | }); |
| 1446 | }; |
| 1447 | |
| 1448 | if (!self.confObj.loader) { |
| 1449 | self.confObj.loader = $.Deferred(); |
| 1450 | window.CKEDITOR_BASEPATH = fm.options.cdns.ckeditor + '/'; |
| 1451 | $.getScript(fm.options.cdns.ckeditor + '/ckeditor.js', function() { |
| 1452 | self.confObj.loader.resolve(); |
| 1453 | }); |
| 1454 | } |
| 1455 | self.confObj.loader.done(init); |
| 1456 | return dfrd; |
| 1457 | }, |
| 1458 | close : function(textarea, instance) { |
| 1459 | instance && instance.destroy(); |
| 1460 | }, |
| 1461 | save : function(textarea, instance) { |
| 1462 | instance && (textarea.value = instance.getData()); |
| 1463 | }, |
| 1464 | focus : function(textarea, instance) { |
| 1465 | instance && instance.focus(); |
| 1466 | }, |
| 1467 | resize : function(textarea, instance, e, data) { |
| 1468 | var self; |
| 1469 | if (instance) { |
| 1470 | if (instance.status === 'ready') { |
| 1471 | instance.resize('100%', $(textarea).parent().height()); |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | }, |
| 1476 | { |
| 1477 | // CKEditor5 balloon mode for html file |
| 1478 | info : { |
| 1479 | id : 'ckeditor5', |
| 1480 | name : 'CKEditor5', |
| 1481 | iconImg : 'img/editor-icons.png 0 -16' |
| 1482 | }, |
| 1483 | exts : ['htm', 'html', 'xhtml'], |
| 1484 | html : '<div class="edit-editor-ckeditor5"></div>', |
| 1485 | setup : function(opts, fm) { |
| 1486 | var confObj = this; |
| 1487 | // check cdn and ES6 support |
| 1488 | if (!fm.options.cdns.ckeditor5 || typeof window.Symbol !== 'function' || typeof Symbol() !== 'symbol') { |
| 1489 | confObj.disabled = true; |
| 1490 | } else { |
| 1491 | confObj.ckeOpts = {}; |
| 1492 | if (opts.extraOptions) { |
| 1493 | // @deprecated option extraOptions.ckeditor5Mode |
| 1494 | if (opts.extraOptions.ckeditor5Mode) { |
| 1495 | confObj.ckeditor5Mode = opts.extraOptions.ckeditor5Mode; |
| 1496 | } |
| 1497 | confObj.ckeOpts = Object.assign({}, opts.extraOptions.ckeditor5 || {}); |
| 1498 | if (confObj.ckeOpts.mode) { |
| 1499 | confObj.ckeditor5Mode = confObj.ckeOpts.mode; |
| 1500 | delete confObj.ckeOpts.mode; |
| 1501 | } |
| 1502 | if (opts.extraOptions.managerUrl) { |
| 1503 | confObj.managerUrl = opts.extraOptions.managerUrl; |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | fm.bind('destroy', function() { |
| 1508 | confObj.editor = null; |
| 1509 | }); |
| 1510 | }, |
| 1511 | // Prepare on before show dialog |
| 1512 | prepare : function(base, dialogOpts, file) { |
| 1513 | $(base).height(base.editor.fm.getUI().height() - 100); |
| 1514 | }, |
| 1515 | init : function(id, file, data, fm) { |
| 1516 | var m = data.match(/^([\s\S]*<body[^>]*>)([\s\S]+)(<\/body>[\s\S]*)$/i), |
| 1517 | header = '', |
| 1518 | body = '', |
| 1519 | footer =''; |
| 1520 | this.css({ |
| 1521 | width: '100%', |
| 1522 | height: '100%', |
| 1523 | 'box-sizing': 'border-box' |
| 1524 | }); |
| 1525 | if (m) { |
| 1526 | header = m[1]; |
| 1527 | body = m[2]; |
| 1528 | footer = m[3]; |
| 1529 | } else { |
| 1530 | body = data; |
| 1531 | } |
| 1532 | this.data('data', { |
| 1533 | header: header, |
| 1534 | body: body, |
| 1535 | footer: footer |
| 1536 | }); |
| 1537 | this._setupSelEncoding(data); |
| 1538 | }, |
| 1539 | load : function(editnode) { |
| 1540 | var self = this, |
| 1541 | fm = this.fm, |
| 1542 | dfrd = $.Deferred(), |
| 1543 | mode = self.confObj.ckeditor5Mode || 'decoupled-document', |
| 1544 | lang = (function() { |
| 1545 | var l = fm.lang.toLowerCase().replace('_', '-'); |
| 1546 | if (l.substr(0, 2) === 'zh' && l !== 'zh-cn') { |
| 1547 | l = 'zh'; |
| 1548 | } |
| 1549 | return l; |
| 1550 | })(), |
| 1551 | init = function(cEditor) { |
| 1552 | var base = $(editnode).parent(), |
| 1553 | opts; |
| 1554 | |
| 1555 | // set base height |
| 1556 | base.height(fm.getUI().height() - 100); |
| 1557 | |
| 1558 | // CKEditor5 configure options |
| 1559 | opts = Object.assign({ |
| 1560 | toolbar: ["heading", "|", "fontSize", "fontFamily", "|", "bold", "italic", "underline", "strikethrough", "highlight", "|", "alignment", "|", "numberedList", "bulletedList", "blockQuote", "indent", "outdent", "|", "ckfinder", "link", "imageUpload", "insertTable", "mediaEmbed", "|", "undo", "redo"], |
| 1561 | language: lang |
| 1562 | }, self.confObj.ckeOpts); |
| 1563 | |
| 1564 | // trigger event 'editEditorPrepare' |
| 1565 | self.trigger('Prepare', { |
| 1566 | node: editnode, |
| 1567 | editorObj: cEditor, |
| 1568 | instance: void(0), |
| 1569 | opts: opts |
| 1570 | }); |
| 1571 | |
| 1572 | cEditor |
| 1573 | .create(editnode, opts) |
| 1574 | .then(function(editor) { |
| 1575 | var ckf = editor.commands.get('ckfinder'), |
| 1576 | fileRepo = editor.plugins.get('FileRepository'), |
| 1577 | prevVars = {}, isImage, insertImages; |
| 1578 | if (editor.ui.view.toolbar && (mode === 'classic' || mode === 'decoupled-document')) { |
| 1579 | $(editnode).closest('.elfinder-dialog').children('.ui-widget-header').append($(editor.ui.view.toolbar.element).css({marginRight:'-1em',marginLeft:'-1em'})); |
| 1580 | } |
| 1581 | if (mode === 'classic') { |
| 1582 | $(editnode).closest('.elfinder-edit-editor').css('overflow', 'auto'); |
| 1583 | } |
| 1584 | // Set up this elFinder instead of CKFinder |
| 1585 | if (ckf) { |
| 1586 | isImage = function(f) { |
| 1587 | return f && f.mime.match(/^image\//i); |
| 1588 | }; |
| 1589 | insertImages = function(urls) { |
| 1590 | var imgCmd = editor.commands.get('imageUpload'); |
| 1591 | if (!imgCmd.isEnabled) { |
| 1592 | var ntf = editor.plugins.get('Notification'), |
| 1593 | i18 = editor.locale.t; |
| 1594 | ntf.showWarning(i18('Could not insert image at the current position.'), { |
| 1595 | title: i18('Inserting image failed'), |
| 1596 | namespace: 'ckfinder' |
| 1597 | }); |
| 1598 | return; |
| 1599 | } |
| 1600 | editor.execute('imageInsert', { source: urls }); |
| 1601 | }; |
| 1602 | // Take over ckfinder execute() |
| 1603 | ckf.execute = function() { |
| 1604 | var dlg = base.closest('.elfinder-dialog'), |
| 1605 | gf = fm.getCommand('getfile'), |
| 1606 | rever = function() { |
| 1607 | if (prevVars.hasVar) { |
| 1608 | dlg.off('resize close', rever); |
| 1609 | gf.callback = prevVars.callback; |
| 1610 | gf.options.folders = prevVars.folders; |
| 1611 | gf.options.multiple = prevVars.multi; |
| 1612 | fm.commandMap.open = prevVars.open; |
| 1613 | prevVars.hasVar = false; |
| 1614 | } |
| 1615 | }; |
| 1616 | dlg.trigger('togleminimize').one('resize close', rever); |
| 1617 | prevVars.callback = gf.callback; |
| 1618 | prevVars.folders = gf.options.folders; |
| 1619 | prevVars.multi = gf.options.multiple; |
| 1620 | prevVars.open = fm.commandMap.open; |
| 1621 | prevVars.hasVar = true; |
| 1622 | gf.callback = function(files) { |
| 1623 | var imgs = []; |
| 1624 | if (files.length === 1 && files[0].mime === 'directory') { |
| 1625 | fm.one('open', function() { |
| 1626 | fm.commandMap.open = 'getfile'; |
| 1627 | }).getCommand('open').exec(files[0].hash); |
| 1628 | return; |
| 1629 | } |
| 1630 | fm.getUI('cwd').trigger('unselectall'); |
| 1631 | $.each(files, function(i, f) { |
| 1632 | if (isImage(f)) { |
| 1633 | imgs.push(fm.convAbsUrl(f.url)); |
| 1634 | } else { |
| 1635 | editor.execute('link', fm.convAbsUrl(f.url)); |
| 1636 | } |
| 1637 | }); |
| 1638 | if (imgs.length) { |
| 1639 | insertImages(imgs); |
| 1640 | } |
| 1641 | dlg.trigger('togleminimize'); |
| 1642 | }; |
| 1643 | gf.options.folders = true; |
| 1644 | gf.options.multiple = true; |
| 1645 | fm.commandMap.open = 'getfile'; |
| 1646 | fm.toast({ |
| 1647 | mode: 'info', |
| 1648 | msg: fm.i18n('dblclickToSelect') |
| 1649 | }); |
| 1650 | }; |
| 1651 | } |
| 1652 | // Set up image uploader |
| 1653 | fileRepo.createUploadAdapter = function(loader) { |
| 1654 | return new uploder(loader); |
| 1655 | }; |
| 1656 | editor.setData($(editnode).data('data').body); |
| 1657 | // move .ck-body to elFinder node for fullscreen mode |
| 1658 | fm.getUI().append($('body > div.ck-body')); |
| 1659 | $('div.ck-balloon-panel').css({ |
| 1660 | 'z-index': fm.getMaximizeCss().zIndex + 1 |
| 1661 | }); |
| 1662 | dfrd.resolve(editor); |
| 1663 | /*fm.log({ |
| 1664 | defaultConfig: cEditor.defaultConfig, |
| 1665 | plugins: cEditor.builtinPlugins.map(function(p) { return p.pluginName; }), |
| 1666 | toolbars: Array.from(editor.ui.componentFactory.names()) |
| 1667 | });*/ |
| 1668 | }) |
| 1669 | ['catch'](function(error) { // ['cache'] instead .cache for fix error on ie8 |
| 1670 | fm.error(error); |
| 1671 | }); |
| 1672 | }, |
| 1673 | uploder = function(loader) { |
| 1674 | var upload = function(file, resolve, reject) { |
| 1675 | fm.exec('upload', {files: [file]}, void(0), fm.cwd().hash) |
| 1676 | .done(function(data){ |
| 1677 | if (data.added && data.added.length) { |
| 1678 | fm.url(data.added[0].hash, { async: true }).done(function(url) { |
| 1679 | resolve({ |
| 1680 | 'default': fm.convAbsUrl(url) |
| 1681 | }); |
| 1682 | }).fail(function() { |
| 1683 | reject('errFileNotFound'); |
| 1684 | }); |
| 1685 | } else { |
| 1686 | reject(fm.i18n(data.error? data.error : 'errUpload')); |
| 1687 | } |
| 1688 | }) |
| 1689 | .fail(function(err) { |
| 1690 | var error = fm.parseError(err); |
| 1691 | reject(fm.i18n(error? (error === 'userabort'? 'errAbort' : error) : 'errUploadNoFiles')); |
| 1692 | }) |
| 1693 | .progress(function(data) { |
| 1694 | loader.uploadTotal = data.total; |
| 1695 | loader.uploaded = data.progress; |
| 1696 | }); |
| 1697 | }; |
| 1698 | this.upload = function() { |
| 1699 | return new Promise(function(resolve, reject) { |
| 1700 | if (loader.file instanceof Promise || (loader.file && typeof loader.file.then === 'function')) { |
| 1701 | loader.file.then(function(file) { |
| 1702 | upload(file, resolve, reject); |
| 1703 | }); |
| 1704 | } else { |
| 1705 | upload(loader.file, resolve, reject); |
| 1706 | } |
| 1707 | }); |
| 1708 | }; |
| 1709 | this.abort = function() { |
| 1710 | fm.getUI().trigger('uploadabort'); |
| 1711 | }; |
| 1712 | }, loader; |
| 1713 | |
| 1714 | if (!self.confObj.editor) { |
| 1715 | loader = $.Deferred(); |
| 1716 | self.fm.loadScript([ |
| 1717 | fm.options.cdns.ckeditor5 + '/' + mode + '/ckeditor.js' |
| 1718 | ], function(editor) { |
| 1719 | if (!editor) { |
| 1720 | editor = window.BalloonEditor || window.InlineEditor || window.ClassicEditor || window.DecoupledEditor; |
| 1721 | } |
| 1722 | if (fm.lang !== 'en') { |
| 1723 | self.fm.loadScript([ |
| 1724 | fm.options.cdns.ckeditor5 + '/' + mode + '/translations/' + lang + '.js' |
| 1725 | ], function(obj) { |
| 1726 | loader.resolve(editor); |
| 1727 | }, { |
| 1728 | tryRequire: true, |
| 1729 | loadType: 'tag', |
| 1730 | error: function(obj) { |
| 1731 | lang = 'en'; |
| 1732 | loader.resolve(editor); |
| 1733 | } |
| 1734 | }); |
| 1735 | } else { |
| 1736 | loader.resolve(editor); |
| 1737 | } |
| 1738 | }, { |
| 1739 | tryRequire: true, |
| 1740 | loadType: 'tag' |
| 1741 | }); |
| 1742 | loader.done(function(editor) { |
| 1743 | self.confObj.editor = editor; |
| 1744 | init(editor); |
| 1745 | }); |
| 1746 | } else { |
| 1747 | init(self.confObj.editor); |
| 1748 | } |
| 1749 | return dfrd; |
| 1750 | }, |
| 1751 | getContent : function() { |
| 1752 | var data = $(this).data('data'); |
| 1753 | return data.header + data.body + data.footer; |
| 1754 | }, |
| 1755 | close : function(editnode, instance) { |
| 1756 | instance && instance.destroy(); |
| 1757 | }, |
| 1758 | save : function(editnode, instance) { |
| 1759 | var elm = $(editnode), |
| 1760 | data = elm.data('data'); |
| 1761 | if (instance) { |
| 1762 | data.body = instance.getData(); |
| 1763 | elm.data('data', data); |
| 1764 | } |
| 1765 | }, |
| 1766 | focus : function(editnode, instance) { |
| 1767 | $(editnode).trigger('focus'); |
| 1768 | } |
| 1769 | }, |
| 1770 | { |
| 1771 | // TinyMCE for html file |
| 1772 | info : { |
| 1773 | id : 'tinymce', |
| 1774 | name : 'TinyMCE', |
| 1775 | iconImg : 'img/editor-icons.png 0 -64' |
| 1776 | }, |
| 1777 | exts : ['htm', 'html', 'xhtml'], |
| 1778 | setup : function(opts, fm) { |
| 1779 | var confObj = this; |
| 1780 | if (!fm.options.cdns.tinymce) { |
| 1781 | confObj.disabled = true; |
| 1782 | } else { |
| 1783 | confObj.mceOpts = {}; |
| 1784 | if (opts.extraOptions) { |
| 1785 | confObj.uploadOpts = Object.assign({}, opts.extraOptions.uploadOpts || {}); |
| 1786 | confObj.mceOpts = Object.assign({}, opts.extraOptions.tinymce || {}); |
| 1787 | } else { |
| 1788 | confObj.uploadOpts = {}; |
| 1789 | } |
| 1790 | } |
| 1791 | }, |
| 1792 | load : function(textarea) { |
| 1793 | var self = this, |
| 1794 | fm = this.fm, |
| 1795 | dfrd = $.Deferred(), |
| 1796 | init = function() { |
| 1797 | var base = $(textarea).show().parent(), |
| 1798 | dlg = base.closest('.elfinder-dialog'), |
| 1799 | h = base.height(), |
| 1800 | delta = base.outerHeight(true) - h, |
| 1801 | // hide MCE dialog and modal block |
| 1802 | hideMceDlg = function() { |
| 1803 | var mceW; |
| 1804 | if (tinymce.activeEditor.windowManager.windows) { |
| 1805 | mceW = tinymce.activeEditor.windowManager.windows[0]; |
| 1806 | mceDlg = $(mceW? mceW.getEl() : void(0)).hide(); |
| 1807 | mceCv = $('#mce-modal-block').hide(); |
| 1808 | } else { |
| 1809 | mceDlg = $('.tox-dialog-wrap').hide(); |
| 1810 | } |
| 1811 | }, |
| 1812 | // Show MCE dialog and modal block |
| 1813 | showMceDlg = function() { |
| 1814 | mceCv && mceCv.show(); |
| 1815 | mceDlg && mceDlg.show(); |
| 1816 | }, |
| 1817 | tVer = tinymce.majorVersion, |
| 1818 | opts, mceDlg, mceCv; |
| 1819 | |
| 1820 | // set base height |
| 1821 | base.height(h); |
| 1822 | // fit height function |
| 1823 | textarea._setHeight = function(height) { |
| 1824 | if (tVer < 5) { |
| 1825 | var base = $(this).parent(), |
| 1826 | h = height || base.innerHeight(), |
| 1827 | ctrH = 0, |
| 1828 | areaH; |
| 1829 | base.find('.mce-container-body:first').children('.mce-top-part,.mce-statusbar').each(function() { |
| 1830 | ctrH += $(this).outerHeight(true); |
| 1831 | }); |
| 1832 | areaH = h - ctrH - delta; |
| 1833 | base.find('.mce-edit-area iframe:first').height(areaH); |
| 1834 | } |
| 1835 | }; |
| 1836 | |
| 1837 | // TinyMCE configure options |
| 1838 | opts = { |
| 1839 | selector: '#' + textarea.id, |
| 1840 | resize: false, |
| 1841 | plugins: 'preview searchreplace autolink directionality visualblocks visualchars fullscreen image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help', |
| 1842 | toolbar: 'formatselect | bold italic strikethrough forecolor backcolor | link image media | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat', |
| 1843 | image_advtab: true, |
| 1844 | init_instance_callback : function(editor) { |
| 1845 | // fit height on init |
| 1846 | textarea._setHeight(h); |
| 1847 | // re-build on dom move |
| 1848 | dlg.one('beforedommove.'+fm.namespace, function() { |
| 1849 | tinymce.execCommand('mceRemoveEditor', false, textarea.id); |
| 1850 | }).one('dommove.'+fm.namespace, function() { |
| 1851 | self.load(textarea).done(function(editor) { |
| 1852 | self.instance = editor; |
| 1853 | }); |
| 1854 | }); |
| 1855 | // return editor instance |
| 1856 | dfrd.resolve(editor); |
| 1857 | }, |
| 1858 | file_picker_callback : function (callback, value, meta) { |
| 1859 | var gf = fm.getCommand('getfile'), |
| 1860 | revar = function() { |
| 1861 | if (prevVars.hasVar) { |
| 1862 | gf.callback = prevVars.callback; |
| 1863 | gf.options.folders = prevVars.folders; |
| 1864 | gf.options.multiple = prevVars.multi; |
| 1865 | fm.commandMap.open = prevVars.open; |
| 1866 | prevVars.hasVar = false; |
| 1867 | } |
| 1868 | dlg.off('resize close', revar); |
| 1869 | showMceDlg(); |
| 1870 | }, |
| 1871 | prevVars = {}; |
| 1872 | prevVars.callback = gf.callback; |
| 1873 | prevVars.folders = gf.options.folders; |
| 1874 | prevVars.multi = gf.options.multiple; |
| 1875 | prevVars.open = fm.commandMap.open; |
| 1876 | prevVars.hasVar = true; |
| 1877 | gf.callback = function(file) { |
| 1878 | var url, info; |
| 1879 | |
| 1880 | if (file.mime === 'directory') { |
| 1881 | fm.one('open', function() { |
| 1882 | fm.commandMap.open = 'getfile'; |
| 1883 | }).getCommand('open').exec(file.hash); |
| 1884 | return; |
| 1885 | } |
| 1886 | |
| 1887 | // URL normalization |
| 1888 | url = fm.convAbsUrl(file.url); |
| 1889 | |
| 1890 | // Make file info |
| 1891 | info = file.name + ' (' + fm.formatSize(file.size) + ')'; |
| 1892 | |
| 1893 | // Provide file and text for the link dialog |
| 1894 | if (meta.filetype == 'file') { |
| 1895 | callback(url, {text: info, title: info}); |
| 1896 | } |
| 1897 | |
| 1898 | // Provide image and alt text for the image dialog |
| 1899 | if (meta.filetype == 'image') { |
| 1900 | callback(url, {alt: info}); |
| 1901 | } |
| 1902 | |
| 1903 | // Provide alternative source and posted for the media dialog |
| 1904 | if (meta.filetype == 'media') { |
| 1905 | callback(url); |
| 1906 | } |
| 1907 | dlg.trigger('togleminimize'); |
| 1908 | }; |
| 1909 | gf.options.folders = true; |
| 1910 | gf.options.multiple = false; |
| 1911 | fm.commandMap.open = 'getfile'; |
| 1912 | |
| 1913 | hideMceDlg(); |
| 1914 | dlg.trigger('togleminimize').one('resize close', revar); |
| 1915 | fm.toast({ |
| 1916 | mode: 'info', |
| 1917 | msg: fm.i18n('dblclickToSelect') |
| 1918 | }); |
| 1919 | |
| 1920 | return false; |
| 1921 | }, |
| 1922 | images_upload_handler : function (blobInfo, success, failure) { |
| 1923 | var file = blobInfo.blob(), |
| 1924 | err = function(e) { |
| 1925 | var dlg = e.data.dialog || {}; |
| 1926 | if (dlg.hasClass('elfinder-dialog-error') || dlg.hasClass('elfinder-confirm-upload')) { |
| 1927 | hideMceDlg(); |
| 1928 | dlg.trigger('togleminimize').one('resize close', revert); |
| 1929 | fm.unbind('dialogopened', err); |
| 1930 | } |
| 1931 | }, |
| 1932 | revert = function() { |
| 1933 | dlg.off('resize close', revert); |
| 1934 | showMceDlg(); |
| 1935 | }, |
| 1936 | clipdata = true; |
| 1937 | |
| 1938 | // check file object |
| 1939 | if (file.name) { |
| 1940 | // file blob of client side file object |
| 1941 | clipdata = void(0); |
| 1942 | } |
| 1943 | fm.bind('dialogopened', err).exec('upload', Object.assign({ |
| 1944 | files: [file], |
| 1945 | clipdata: clipdata // to get unique name on connector |
| 1946 | }, self.confObj.uploadOpts), void(0), fm.cwd().hash).done(function(data) { |
| 1947 | if (data.added && data.added.length) { |
| 1948 | fm.url(data.added[0].hash, { async: true }).done(function(url) { |
| 1949 | showMceDlg(); |
| 1950 | success(fm.convAbsUrl(url)); |
| 1951 | }).fail(function() { |
| 1952 | failure(fm.i18n('errFileNotFound')); |
| 1953 | }); |
| 1954 | } else { |
| 1955 | failure(fm.i18n(data.error? data.error : 'errUpload')); |
| 1956 | } |
| 1957 | }).fail(function(err) { |
| 1958 | var error = fm.parseError(err); |
| 1959 | if (error) { |
| 1960 | if (error === 'errUnknownCmd') { |
| 1961 | error = 'errPerm'; |
| 1962 | } else if (error === 'userabort') { |
| 1963 | error = 'errAbort'; |
| 1964 | } |
| 1965 | } |
| 1966 | failure(fm.i18n(error? error : 'errUploadNoFiles')); |
| 1967 | }); |
| 1968 | } |
| 1969 | }; |
| 1970 | |
| 1971 | // TinyMCE 5 supports "height: 100%" |
| 1972 | if (tVer >= 5) { |
| 1973 | opts.height = '100%'; |
| 1974 | } |
| 1975 | |
| 1976 | // trigger event 'editEditorPrepare' |
| 1977 | self.trigger('Prepare', { |
| 1978 | node: textarea, |
| 1979 | editorObj: tinymce, |
| 1980 | instance: void(0), |
| 1981 | opts: opts |
| 1982 | }); |
| 1983 | |
| 1984 | // TinyMCE configure |
| 1985 | tinymce.init(Object.assign(opts, self.confObj.mceOpts)); |
| 1986 | }; |
| 1987 | |
| 1988 | if (!self.confObj.loader) { |
| 1989 | self.confObj.loader = $.Deferred(); |
| 1990 | self.fm.loadScript([fm.options.cdns.tinymce + (fm.options.cdns.tinymce.match(/\.js/)? '' : '/tinymce.min.js')], function() { |
| 1991 | self.confObj.loader.resolve(); |
| 1992 | }, { |
| 1993 | loadType: 'tag' |
| 1994 | }); |
| 1995 | } |
| 1996 | self.confObj.loader.done(init); |
| 1997 | return dfrd; |
| 1998 | }, |
| 1999 | close : function(textarea, instance) { |
| 2000 | instance && tinymce.execCommand('mceRemoveEditor', false, textarea.id); |
| 2001 | }, |
| 2002 | save : function(textarea, instance) { |
| 2003 | instance && instance.save(); |
| 2004 | }, |
| 2005 | focus : function(textarea, instance) { |
| 2006 | instance && instance.focus(); |
| 2007 | }, |
| 2008 | resize : function(textarea, instance, e, data) { |
| 2009 | // fit height to base node on dialog resize |
| 2010 | instance && textarea._setHeight(); |
| 2011 | } |
| 2012 | }, |
| 2013 | { |
| 2014 | info : { |
| 2015 | id : 'zohoeditor', |
| 2016 | name : 'Zoho Editor', |
| 2017 | iconImg : 'img/editor-icons.png 0 -32', |
| 2018 | cmdCheck : 'ZohoOffice', |
| 2019 | preventGet: true, |
| 2020 | hideButtons: true, |
| 2021 | syncInterval : 15000, |
| 2022 | canMakeEmpty: true, |
| 2023 | integrate: { |
| 2024 | title: 'Zoho Office API', |
| 2025 | link: 'https://www.zoho.com/officeapi/' |
| 2026 | } |
| 2027 | }, |
| 2028 | mimes : [ |
| 2029 | 'application/msword', |
| 2030 | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
| 2031 | //'application/pdf', |
| 2032 | 'application/vnd.oasis.opendocument.text', |
| 2033 | 'application/rtf', |
| 2034 | 'text/html', |
| 2035 | 'application/vnd.ms-excel', |
| 2036 | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
| 2037 | 'application/vnd.oasis.opendocument.spreadsheet', |
| 2038 | 'application/vnd.sun.xml.calc', |
| 2039 | 'text/csv', |
| 2040 | 'text/tab-separated-values', |
| 2041 | 'application/vnd.ms-powerpoint', |
| 2042 | 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
| 2043 | 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', |
| 2044 | 'application/vnd.oasis.opendocument.presentation', |
| 2045 | 'application/vnd.sun.xml.impress' |
| 2046 | ], |
| 2047 | html : '<iframe style="width:100%;max-height:100%;border:none;"></iframe>', |
| 2048 | // setup on elFinder bootup |
| 2049 | setup : function(opts, fm) { |
| 2050 | if (fm.UA.Mobile || fm.UA.ltIE8) { |
| 2051 | this.disabled = true; |
| 2052 | } |
| 2053 | }, |
| 2054 | // Prepare on before show dialog |
| 2055 | prepare : function(base, dialogOpts, file) { |
| 2056 | var elfNode = base.editor.fm.getUI(); |
| 2057 | $(base).height(elfNode.height()); |
| 2058 | dialogOpts.width = Math.max(dialogOpts.width || 0, elfNode.width() * 0.8); |
| 2059 | }, |
| 2060 | // Initialization of editing node (this: this editors HTML node) |
| 2061 | init : function(id, file, dum, fm) { |
| 2062 | var ta = this, |
| 2063 | ifm = $(this).hide(), |
| 2064 | uiToast = fm.getUI('toast'), |
| 2065 | spnr = $('<div class="elfinder-edit-spinner elfinder-edit-zohoeditor"></div>') |
| 2066 | .html('<span class="elfinder-spinner-text">' + fm.i18n('nowLoading') + '</span><span class="elfinder-spinner"></span>') |
| 2067 | .appendTo(ifm.parent()), |
| 2068 | cdata = function() { |
| 2069 | var data = ''; |
| 2070 | $.each(fm.customData, function(key, val) { |
| 2071 | data += '&' + encodeURIComponent(key) + '=' + encodeURIComponent(val); |
| 2072 | }); |
| 2073 | return data; |
| 2074 | }; |
| 2075 | |
| 2076 | $(ta).data('xhr', fm.request({ |
| 2077 | data: { |
| 2078 | cmd: 'editor', |
| 2079 | name: ta.editor.confObj.info.cmdCheck, |
| 2080 | method: 'init', |
| 2081 | 'args[target]': file.hash, |
| 2082 | 'args[lang]' : fm.lang, |
| 2083 | 'args[cdata]' : cdata() |
| 2084 | }, |
| 2085 | preventDefault : true |
| 2086 | }).done(function(data) { |
| 2087 | var opts; |
| 2088 | if (data.zohourl) { |
| 2089 | opts = { |
| 2090 | css: { |
| 2091 | height: '100%' |
| 2092 | } |
| 2093 | }; |
| 2094 | // trigger event 'editEditorPrepare' |
| 2095 | ta.editor.trigger('Prepare', { |
| 2096 | node: ta, |
| 2097 | editorObj: void(0), |
| 2098 | instance: ifm, |
| 2099 | opts: opts |
| 2100 | }); |
| 2101 | |
| 2102 | ifm.attr('src', data.zohourl).show().css(opts.css); |
| 2103 | if (data.warning) { |
| 2104 | uiToast.appendTo(ta.closest('.ui-dialog')); |
| 2105 | fm.toast({ |
| 2106 | msg: fm.i18n(data.warning), |
| 2107 | mode: 'warning', |
| 2108 | timeOut: 0, |
| 2109 | onHidden: function() { |
| 2110 | uiToast.children().length === 1 && uiToast.appendTo(fm.getUI()); |
| 2111 | }, |
| 2112 | button: { |
| 2113 | text: 'btnYes' |
| 2114 | } |
| 2115 | }); |
| 2116 | } |
| 2117 | } else { |
| 2118 | data.error && fm.error(data.error); |
| 2119 | ta.elfinderdialog('destroy'); |
| 2120 | } |
| 2121 | }).fail(function(error) { |
| 2122 | error && fm.error(error); |
| 2123 | ta.elfinderdialog('destroy'); |
| 2124 | }).always(function() { |
| 2125 | spnr.remove(); |
| 2126 | })); |
| 2127 | }, |
| 2128 | load : function() {}, |
| 2129 | getContent : function() {}, |
| 2130 | save : function() {}, |
| 2131 | // Before dialog close |
| 2132 | beforeclose : iframeClose, |
| 2133 | // On dialog closed |
| 2134 | close : function(ta) { |
| 2135 | var fm = this.fm, |
| 2136 | xhr = $(ta).data('xhr'); |
| 2137 | if (xhr.state() === 'pending') { |
| 2138 | xhr.reject(); |
| 2139 | } |
| 2140 | } |
| 2141 | }, |
| 2142 | { |
| 2143 | // Zip Archive with FlySystem |
| 2144 | info : { |
| 2145 | id : 'ziparchive', |
| 2146 | name : 'btnMount', |
| 2147 | iconImg : 'img/toolbar.png 0 -416', |
| 2148 | cmdCheck : 'ZipArchive', |
| 2149 | edit : function(file, editor) { |
| 2150 | var fm = this, |
| 2151 | dfrd = $.Deferred(); |
| 2152 | fm.request({ |
| 2153 | data:{ |
| 2154 | cmd: 'netmount', |
| 2155 | protocol: 'ziparchive', |
| 2156 | host: file.hash, |
| 2157 | path: file.phash |
| 2158 | }, |
| 2159 | preventFail: true, |
| 2160 | notify : {type : 'netmount', cnt : 1, hideCnt : true} |
| 2161 | }).done(function(data) { |
| 2162 | var pdir; |
| 2163 | if (data.added && data.added.length) { |
| 2164 | if (data.added[0].phash) { |
| 2165 | if (pdir = fm.file(data.added[0].phash)) { |
| 2166 | if (! pdir.dirs) { |
| 2167 | pdir.dirs = 1; |
| 2168 | fm.change({ changed: [ pdir ] }); |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | fm.one('netmountdone', function() { |
| 2173 | fm.exec('open', data.added[0].hash); |
| 2174 | fm.one('opendone', function() { |
| 2175 | data.toast && fm.toast(data.toast); |
| 2176 | }); |
| 2177 | }); |
| 2178 | } |
| 2179 | dfrd.resolve(); |
| 2180 | }) |
| 2181 | .fail(function(error) { |
| 2182 | dfrd.reject(error); |
| 2183 | }); |
| 2184 | return dfrd; |
| 2185 | } |
| 2186 | }, |
| 2187 | mimes : ['application/zip'], |
| 2188 | load : function() {}, |
| 2189 | save : function(){} |
| 2190 | }, |
| 2191 | { |
| 2192 | // Simple Text (basic textarea editor) |
| 2193 | info : { |
| 2194 | id : 'textarea', |
| 2195 | name : 'TextArea', |
| 2196 | useTextAreaEvent : true |
| 2197 | }, |
| 2198 | load : function(textarea) { |
| 2199 | // trigger event 'editEditorPrepare' |
| 2200 | this.trigger('Prepare', { |
| 2201 | node: textarea, |
| 2202 | editorObj: void(0), |
| 2203 | instance: void(0), |
| 2204 | opts: {} |
| 2205 | }); |
| 2206 | textarea.setSelectionRange && textarea.setSelectionRange(0, 0); |
| 2207 | $(textarea).trigger('focus').show(); |
| 2208 | }, |
| 2209 | save : function(){} |
| 2210 | }, |
| 2211 | { |
| 2212 | // File converter with online-convert.com |
| 2213 | info : { |
| 2214 | id : 'onlineconvert', |
| 2215 | name : 'Online Convert', |
| 2216 | iconImg : 'img/editor-icons.png 0 -144', |
| 2217 | cmdCheck : 'OnlineConvert', |
| 2218 | preventGet: true, |
| 2219 | hideButtons: true, |
| 2220 | single: true, |
| 2221 | converter: true, |
| 2222 | canMakeEmpty: false, |
| 2223 | integrate: { |
| 2224 | title: 'ONLINE-CONVERT.COM', |
| 2225 | link: 'https://online-convert.com' |
| 2226 | } |
| 2227 | }, |
| 2228 | mimes : ['*'], |
| 2229 | html : '<div style="width:100%;max-height:100%;"></div>', |
| 2230 | // setup on elFinder bootup |
| 2231 | setup : function(opts, fm) { |
| 2232 | var mOpts = opts.extraOptions.onlineConvert || {maxSize:100,showLink:true}; |
| 2233 | if (mOpts.maxSize) { |
| 2234 | this.info.maxSize = mOpts.maxSize * 1048576; |
| 2235 | } |
| 2236 | this.set = Object.assign({ |
| 2237 | url : 'https://%s.online-convert.com%s?external_url=', |
| 2238 | conv : { |
| 2239 | Archive: {'7Z':{}, 'BZ2':{ext:'bz'}, 'GZ':{}, 'ZIP':{}}, |
| 2240 | Audio: {'MP3':{}, 'OGG':{ext:'oga'}, 'WAV':{}, 'WMA':{}, 'AAC':{}, 'AIFF':{ext:'aif'}, 'FLAC':{}, 'M4A':{}, 'MMF':{}, 'OPUS':{ext:'oga'}}, |
| 2241 | Document: {'DOC':{}, 'DOCX':{}, 'HTML':{}, 'ODT':{}, 'PDF':{}, 'PPT':{}, 'PPTX':{}, 'RTF':{}, 'SWF':{}, 'TXT':{}}, |
| 2242 | eBook: {'AZW3':{ext:'azw'}, 'ePub':{}, 'FB2':{ext:'xml'}, 'LIT':{}, 'LRF':{}, 'MOBI':{}, 'PDB':{}, 'PDF':{},'PDF-eBook':{ext:'pdf'}, 'TCR':{}}, |
| 2243 | 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':{}}, |
| 2244 | Image: {'BMP':{}, 'EPS':{ext:'ai'}, 'GIF':{}, 'EXR':{}, 'ICO':{}, 'JPG':{}, 'PNG':{}, 'SVG':{}, 'TGA':{}, 'TIFF':{ext:'tif'}, 'WBMP':{}, 'WebP':{}}, |
| 2245 | 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'}} |
| 2246 | }, |
| 2247 | catExts : { |
| 2248 | Hash: 'txt' |
| 2249 | }, |
| 2250 | 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>', |
| 2251 | useTabs : ($.fn.tabs && !fm.UA.iOS)? true : false // Can't work on iOS, I don't know why. |
| 2252 | }, mOpts); |
| 2253 | }, |
| 2254 | // Prepare on before show dialog |
| 2255 | prepare : function(base, dialogOpts, file) { |
| 2256 | var elfNode = base.editor.fm.getUI(); |
| 2257 | $(base).height(elfNode.height()); |
| 2258 | dialogOpts.width = Math.max(dialogOpts.width || 0, elfNode.width() * 0.8); |
| 2259 | }, |
| 2260 | // Initialization of editing node (this: this editors HTML node) |
| 2261 | init : function(id, file, dum, fm) { |
| 2262 | var ta = this, |
| 2263 | confObj = ta.editor.confObj, |
| 2264 | set = confObj.set, |
| 2265 | uiToast = fm.getUI('toast'), |
| 2266 | idxs = {}, |
| 2267 | allowZip = fm.uploadMimeCheck('application/zip', file.phash), |
| 2268 | selfUrl = $('base').length? document.location.href.replace(/#.*$/, '') : '', |
| 2269 | getExt = function(cat, con) { |
| 2270 | var c; |
| 2271 | if (set.catExts[cat]) { |
| 2272 | return set.catExts[cat]; |
| 2273 | } |
| 2274 | if (set.conv[cat] && (c = set.conv[cat][con])) { |
| 2275 | return (c.ext || con).toLowerCase(); |
| 2276 | } |
| 2277 | return con.toLowerCase(); |
| 2278 | }, |
| 2279 | setOptions = function(cat, done) { |
| 2280 | var type, dfdInit, dfd; |
| 2281 | if (typeof confObj.api === 'undefined') { |
| 2282 | dfdInit = fm.request({ |
| 2283 | data: { |
| 2284 | cmd: 'editor', |
| 2285 | name: 'OnlineConvert', |
| 2286 | method: 'init' |
| 2287 | }, |
| 2288 | preventDefault : true |
| 2289 | }); |
| 2290 | } else { |
| 2291 | dfdInit = $.Deferred().resolve({api: confObj.api}); |
| 2292 | } |
| 2293 | cat = cat.toLowerCase(); |
| 2294 | dfdInit.done(function(data) { |
| 2295 | confObj.api = data.api; |
| 2296 | if (confObj.api) { |
| 2297 | if (cat) { |
| 2298 | type = '?category=' + cat; |
| 2299 | } else { |
| 2300 | type = ''; |
| 2301 | cat = 'all'; |
| 2302 | } |
| 2303 | if (!confObj.conversions) { |
| 2304 | confObj.conversions = {}; |
| 2305 | } |
| 2306 | if (!confObj.conversions[cat]) { |
| 2307 | dfd = $.getJSON('https://api2.online-convert.com/conversions' + type); |
| 2308 | } else { |
| 2309 | dfd = $.Deferred().resolve(confObj.conversions[cat]); |
| 2310 | } |
| 2311 | dfd.done(function(d) { |
| 2312 | confObj.conversions[cat] = d; |
| 2313 | $.each(d, function(i, o) { |
| 2314 | btns[set.useTabs? 'children' : 'find']('.onlineconvert-category-' + o.category).children('.onlineconvert-' + o.target).trigger('makeoption', o); |
| 2315 | }); |
| 2316 | done && done(); |
| 2317 | }); |
| 2318 | } |
| 2319 | }); |
| 2320 | }, |
| 2321 | btns = (function() { |
| 2322 | var btns = $('<div></div>').on('click', 'button', function() { |
| 2323 | var b = $(this), |
| 2324 | opts = b.data('opts') || null, |
| 2325 | cat = b.closest('.onlineconvert-category').data('cname'), |
| 2326 | con = b.data('conv'); |
| 2327 | if (confObj.api === true) { |
| 2328 | api({ |
| 2329 | category: cat, |
| 2330 | convert: con, |
| 2331 | options: opts |
| 2332 | }); |
| 2333 | } |
| 2334 | }).on('change', function(e) { |
| 2335 | var t = $(e.target), |
| 2336 | p = t.parent(), |
| 2337 | b = t.closest('.elfinder-edit-onlineconvert-button').children('button:first'), |
| 2338 | o = b.data('opts') || {}, |
| 2339 | v = p.data('type') === 'boolean'? t.is(':checked') : t.val(); |
| 2340 | e.stopPropagation(); |
| 2341 | if (v) { |
| 2342 | if (p.data('type') === 'integer') { |
| 2343 | v = parseInt(v); |
| 2344 | } |
| 2345 | if (p.data('pattern')) { |
| 2346 | var reg = new RegExp(p.data('pattern')); |
| 2347 | if (!reg.test(v)) { |
| 2348 | requestAnimationFrame(function() { |
| 2349 | fm.error('"' + fm.escape(v) + '" is not match to "/' + fm.escape(p.data('pattern')) + '/"'); |
| 2350 | }); |
| 2351 | v = null; |
| 2352 | } |
| 2353 | } |
| 2354 | } |
| 2355 | if (v) { |
| 2356 | o[t.parent().data('optkey')] = v; |
| 2357 | } else { |
| 2358 | delete o[p.data('optkey')]; |
| 2359 | } |
| 2360 | b.data('opts', o); |
| 2361 | }), |
| 2362 | ul = $('<ul></ul>'), |
| 2363 | oform = function(n, o) { |
| 2364 | var f = $('<p></p>').data('optkey', n).data('type', o.type), |
| 2365 | checked = '', |
| 2366 | disabled = '', |
| 2367 | nozip = false, |
| 2368 | opts, btn, elm; |
| 2369 | if (o.description) { |
| 2370 | f.attr('title', fm.i18n(o.description)); |
| 2371 | } |
| 2372 | if (o.pattern) { |
| 2373 | f.data('pattern', o.pattern); |
| 2374 | } |
| 2375 | f.append($('<span></span>').text(fm.i18n(n) + ' : ')); |
| 2376 | if (o.type === 'boolean') { |
| 2377 | if (o['default'] || (nozip = (n === 'allow_multiple_outputs' && !allowZip))) { |
| 2378 | checked = ' checked'; |
| 2379 | if (nozip) { |
| 2380 | disabled = ' disabled'; |
| 2381 | } |
| 2382 | btn = this.children('button:first'); |
| 2383 | opts = btn.data('opts') || {}; |
| 2384 | opts[n] = true; |
| 2385 | btn.data('opts', opts); |
| 2386 | } |
| 2387 | f.append($('<input type="checkbox" value="true"'+checked+disabled+'/>')); |
| 2388 | } else if (o['enum']){ |
| 2389 | elm = $('<select></select>').append($('<option value=""></option>').text('Select...')); |
| 2390 | $.each(o['enum'], function(i, v) { |
| 2391 | elm.append($('<option value="'+v+'"></option>').text(v)); |
| 2392 | }); |
| 2393 | f.append(elm); |
| 2394 | } else { |
| 2395 | f.append($('<input type="text" value=""/>')); |
| 2396 | } |
| 2397 | return f; |
| 2398 | }, |
| 2399 | makeOption = function(o) { |
| 2400 | var elm = this, |
| 2401 | b = $('<span class="elfinder-button-icon elfinder-button-icon-preference"></span>').on('click', function() { |
| 2402 | f.toggle(); |
| 2403 | }), |
| 2404 | f = $('<div class="elfinder-edit-onlinconvert-options"></div>').hide(); |
| 2405 | if (o.options) { |
| 2406 | $.each(o.options, function(k, v) { |
| 2407 | k !== 'download_password' && f.append(oform.call(elm, k, v)); |
| 2408 | }); |
| 2409 | } |
| 2410 | elm.append(b, f); |
| 2411 | }, |
| 2412 | ts = (+new Date()), |
| 2413 | i = 0; |
| 2414 | |
| 2415 | if (!confObj.ext2mime) { |
| 2416 | confObj.ext2mime = Object.assign(fm.arrayFlip(fm.mimeTypes), ext2mime); |
| 2417 | } |
| 2418 | $.each(set.conv, function(t, c) { |
| 2419 | var cname = t.toLowerCase(), |
| 2420 | id = 'elfinder-edit-onlineconvert-' + cname + ts, |
| 2421 | type = $('<div id="' + id + '" class="onlineconvert-category onlineconvert-category-'+cname+'"></div>').data('cname', t), |
| 2422 | cext; |
| 2423 | $.each(c, function(n, o) { |
| 2424 | var nl = n.toLowerCase(), |
| 2425 | ext = getExt(t, n); |
| 2426 | if (!confObj.ext2mime[ext]) { |
| 2427 | if (cname === 'audio' || cname === 'image' || cname === 'video') { |
| 2428 | confObj.ext2mime[ext] = cname + '/x-' + nl; |
| 2429 | } else { |
| 2430 | confObj.ext2mime[ext] = 'application/octet-stream'; |
| 2431 | } |
| 2432 | } |
| 2433 | if (fm.uploadMimeCheck(confObj.ext2mime[ext], file.phash)) { |
| 2434 | type.append($('<div class="elfinder-edit-onlineconvert-button onlineconvert-'+nl+'"></div>').on('makeoption', function(e, data) { |
| 2435 | var elm = $(this); |
| 2436 | if (!elm.children('.elfinder-button-icon-preference').length) { |
| 2437 | makeOption.call(elm, data); |
| 2438 | } |
| 2439 | }).append($('<button></button>').text(n).data('conv', n))); |
| 2440 | } |
| 2441 | }); |
| 2442 | if (type.children().length) { |
| 2443 | ul.append($('<li></li>').append($('<a></a>').attr('href', selfUrl + '#' + id).text(t))); |
| 2444 | btns.append(type); |
| 2445 | idxs[cname] = i++; |
| 2446 | } |
| 2447 | }); |
| 2448 | if (set.useTabs) { |
| 2449 | btns.prepend(ul).tabs({ |
| 2450 | beforeActivate: function(e, ui) { |
| 2451 | setOptions(ui.newPanel.data('cname')); |
| 2452 | } |
| 2453 | }); |
| 2454 | } else { |
| 2455 | $.each(set.conv, function(t) { |
| 2456 | var tl = t.toLowerCase(); |
| 2457 | btns.append($('<fieldset class="onlineconvert-fieldset-' + tl + '"></fieldset>').append($('<legend></legend>').text(t)).append(btns.children('.onlineconvert-category-' + tl))); |
| 2458 | }); |
| 2459 | } |
| 2460 | return btns; |
| 2461 | })(), |
| 2462 | select = $(this) |
| 2463 | .append( |
| 2464 | btns, |
| 2465 | (set.showLink? $(set.link) : null) |
| 2466 | ), |
| 2467 | spnr = $('<div class="elfinder-edit-spinner elfinder-edit-onlineconvert"></div>') |
| 2468 | .hide() |
| 2469 | .html('<span class="elfinder-spinner-text">' + fm.i18n('nowLoading') + '</span><span class="elfinder-spinner"></span>') |
| 2470 | .appendTo(select.parent()), |
| 2471 | prog = $('<div class="elfinder-quicklook-info-progress"></div>').appendTo(spnr), |
| 2472 | _url = null, |
| 2473 | url = function() { |
| 2474 | var onetime; |
| 2475 | if (_url) { |
| 2476 | return $.Deferred().resolve(_url); |
| 2477 | } else { |
| 2478 | spnr.show(); |
| 2479 | return fm.forExternalUrl(file.hash, { progressBar: prog }).done(function(url) { |
| 2480 | _url = url; |
| 2481 | }).fail(function(error) { |
| 2482 | error && fm.error(error); |
| 2483 | ta.elfinderdialog('destroy'); |
| 2484 | }).always(function() { |
| 2485 | spnr.hide(); |
| 2486 | }); |
| 2487 | } |
| 2488 | }, |
| 2489 | api = function(opts) { |
| 2490 | $(ta).data('dfrd', url().done(function(url) { |
| 2491 | select.fadeOut(); |
| 2492 | setStatus({info: 'Start conversion request.'}); |
| 2493 | fm.request({ |
| 2494 | data: { |
| 2495 | cmd: 'editor', |
| 2496 | name: 'OnlineConvert', |
| 2497 | method: 'api', |
| 2498 | 'args[category]' : opts.category.toLowerCase(), |
| 2499 | 'args[convert]' : opts.convert.toLowerCase(), |
| 2500 | 'args[options]' : JSON.stringify(opts.options), |
| 2501 | 'args[source]' : fm.convAbsUrl(url), |
| 2502 | 'args[filename]' : fm.splitFileExtention(file.name)[0] + '.' + getExt(opts.category, opts.convert), |
| 2503 | 'args[mime]' : file.mime |
| 2504 | }, |
| 2505 | preventDefault : true |
| 2506 | }).done(function(data) { |
| 2507 | checkRes(data.apires, opts.category, opts.convert); |
| 2508 | }).fail(function(error) { |
| 2509 | error && fm.error(error); |
| 2510 | ta.elfinderdialog('destroy'); |
| 2511 | }); |
| 2512 | })); |
| 2513 | }, |
| 2514 | checkRes = function(res, cat, con) { |
| 2515 | var status, err = []; |
| 2516 | if (res && res.id) { |
| 2517 | status = res.status; |
| 2518 | if (status.code === 'failed') { |
| 2519 | spnr.hide(); |
| 2520 | if (res.errors && res.errors.length) { |
| 2521 | $.each(res.errors, function(i, o) { |
| 2522 | o.message && err.push(o.message); |
| 2523 | }); |
| 2524 | } |
| 2525 | fm.error(err.length? err : status.info); |
| 2526 | select.fadeIn(); |
| 2527 | } else if (status.code === 'completed') { |
| 2528 | upload(res); |
| 2529 | } else { |
| 2530 | setStatus(status); |
| 2531 | setTimeout(function() { |
| 2532 | polling(res.id); |
| 2533 | }, 1000); |
| 2534 | } |
| 2535 | } else { |
| 2536 | uiToast.appendTo(ta.closest('.ui-dialog')); |
| 2537 | if (res.message) { |
| 2538 | fm.toast({ |
| 2539 | msg: fm.i18n(res.message), |
| 2540 | mode: 'error', |
| 2541 | timeOut: 5000, |
| 2542 | onHidden: function() { |
| 2543 | uiToast.children().length === 1 && uiToast.appendTo(fm.getUI()); |
| 2544 | } |
| 2545 | }); |
| 2546 | } |
| 2547 | fm.toast({ |
| 2548 | msg: fm.i18n('editorConvNoApi'), |
| 2549 | mode: 'error', |
| 2550 | timeOut: 3000, |
| 2551 | onHidden: function() { |
| 2552 | uiToast.children().length === 1 && uiToast.appendTo(fm.getUI()); |
| 2553 | } |
| 2554 | }); |
| 2555 | spnr.hide(); |
| 2556 | select.show(); |
| 2557 | } |
| 2558 | }, |
| 2559 | setStatus = function(status) { |
| 2560 | spnr.show().children('.elfinder-spinner-text').text(status.info); |
| 2561 | }, |
| 2562 | polling = function(jobid) { |
| 2563 | fm.request({ |
| 2564 | data: { |
| 2565 | cmd: 'editor', |
| 2566 | name: 'OnlineConvert', |
| 2567 | method: 'api', |
| 2568 | 'args[jobid]': jobid |
| 2569 | }, |
| 2570 | preventDefault : true |
| 2571 | }).done(function(data) { |
| 2572 | checkRes(data.apires); |
| 2573 | }).fail(function(error) { |
| 2574 | error && fm.error(error); |
| 2575 | ta.elfinderdialog('destroy'); |
| 2576 | }); |
| 2577 | }, |
| 2578 | upload = function(res) { |
| 2579 | var output = res.output, |
| 2580 | id = res.id, |
| 2581 | url = ''; |
| 2582 | spnr.hide(); |
| 2583 | if (output && output.length) { |
| 2584 | ta.elfinderdialog('destroy'); |
| 2585 | $.each(output, function(i, o) { |
| 2586 | if (o.uri) { |
| 2587 | url += o.uri + '\n'; |
| 2588 | } |
| 2589 | }); |
| 2590 | fm.upload({ |
| 2591 | target: file.phash, |
| 2592 | files: [url], |
| 2593 | type: 'text', |
| 2594 | extraData: { |
| 2595 | contentSaveId: 'OnlineConvert-' + res.id |
| 2596 | } |
| 2597 | }); |
| 2598 | } |
| 2599 | }, |
| 2600 | mode = 'document', |
| 2601 | cl, m; |
| 2602 | select.parent().css({overflow: 'auto'}).addClass('overflow-scrolling-touch'); |
| 2603 | if (m = file.mime.match(/^(audio|image|video)/)) { |
| 2604 | mode = m[1]; |
| 2605 | } |
| 2606 | if (set.useTabs) { |
| 2607 | if (idxs[mode]) { |
| 2608 | btns.tabs('option', 'active', idxs[mode]); |
| 2609 | } |
| 2610 | } else { |
| 2611 | cl = Object.keys(set.conv).length; |
| 2612 | $.each(set.conv, function(t) { |
| 2613 | if (t.toLowerCase() === mode) { |
| 2614 | setOptions(t, function() { |
| 2615 | $.each(set.conv, function(t0) { |
| 2616 | t0.toLowerCase() !== mode && setOptions(t0); |
| 2617 | }); |
| 2618 | }); |
| 2619 | return false; |
| 2620 | } |
| 2621 | cl--; |
| 2622 | }); |
| 2623 | if (!cl) { |
| 2624 | $.each(set.conv, function(t) { |
| 2625 | setOptions(t); |
| 2626 | }); |
| 2627 | } |
| 2628 | select.parent().scrollTop(btns.children('.onlineconvert-fieldset-' + mode).offset().top); |
| 2629 | } |
| 2630 | }, |
| 2631 | load : function() {}, |
| 2632 | getContent : function() {}, |
| 2633 | save : function() {}, |
| 2634 | // On dialog closed |
| 2635 | close : function(ta) { |
| 2636 | var fm = this.fm, |
| 2637 | dfrd = $(ta).data('dfrd'); |
| 2638 | if (dfrd && dfrd.state() === 'pending') { |
| 2639 | dfrd.reject(); |
| 2640 | } |
| 2641 | } |
| 2642 | } |
| 2643 | ]; |
| 2644 | }, window.elFinder)); |
| 2645 | })(jQuery) |