From 04322e7b040f155f0e1b3be4f18fbeee1b1ab93f Mon Sep 17 00:00:00 2001 From: nao-pon Date: Fri, 16 Feb 2018 01:00:45 +0900 Subject: [PATCH] [cmd:edit] add a property `id` into editor.info rel. #2381 --- js/commands/edit.js | 30 +++++++++++++++--------- js/extras/editors.default.js | 44 +++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/js/commands/edit.js b/js/commands/edit.js index 8cc6e799bd..b838fe4d53 100644 --- a/js/commands/edit.js +++ b/js/commands/edit.js @@ -28,6 +28,10 @@ elFinder.prototype.commands.edit = function() { }); return sel; }, + getStoreId = function(name) { + // for compatibility to previous version + return name.toLowerCase().replace(/ +/g, ''); + }, /** * Return files acceptable to edit @@ -255,7 +259,10 @@ elFinder.prototype.commands.edit = function() { doClose : savecl, file : file, fm : fm, - confObj : editor + confObj : editor, + trigger : function(evName, data) { + fm.trigger('editEditor' + evName, Object.assign({}, editor.info || {}, data)); + } }; } @@ -590,9 +597,10 @@ elFinder.prototype.commands.edit = function() { && typeof editor.save == 'function') { name = editor.info && editor.info.name? editor.info.name : ('Editor ' + i); + editor.id = editor.info && editor.info.id? editor.info.id : ('editor' + i), editor.name = name; editor.i18n = fm.i18n(name); - editors[name] = editor; + editors[editor.id] = editor; } }); }, @@ -601,7 +609,7 @@ elFinder.prototype.commands.edit = function() { if (!$.isPlainObject(stored)) { stored = {}; } - stored[mime] = editor.name; + stored[mime] = editor.id; fm.storage('storedEditors', stored); fm.trigger('selectfiles', {files : fm.selected()}); } @@ -612,7 +620,7 @@ elFinder.prototype.commands.edit = function() { }, getSubMenuRaw = function(files, callback) { var subMenuRaw = []; - $.each(editors, function(name, ed) { + $.each(editors, function(id, ed) { subMenuRaw.push( { label : fm.escape(ed.i18n), @@ -724,14 +732,14 @@ elFinder.prototype.commands.edit = function() { file = fm.file(e.data.targets[0]); setEditors(file, e.data.targets.length); if (Object.keys(editors).length > 1) { - if (!useStoredEditor() || !stored[file.mime] || !editors[stored[file.mime]]) { + if (!useStoredEditor() || !stored[file.mime] || !editors[getStoreId(stored[file.mime])]) { delete self.extra; self.variants = []; - $.each(editors, function(name, editor) { - self.variants.push([{ editor: editor }, fm.i18n(name), editor.info && editor.info.iconImg? fm.baseUrl + editor.info.iconImg : 'edit']); + $.each(editors, function(id, editor) { + self.variants.push([{ editor: editor }, editor.i18n, editor.info && editor.info.iconImg? fm.baseUrl + editor.info.iconImg : 'edit']); }); } else { - single(editors[stored[file.mime]]); + single(editors[getStoreId(stored[file.mime])]); self.extra = { icon: 'menu', node: $('') @@ -779,11 +787,11 @@ elFinder.prototype.commands.edit = function() { node = $(opts && opts._currentNode? opts._currentNode : $('#'+ fm.cwdHash2Id(hashes[0]))), getEditor = function() { var dfd = $.Deferred(), - storedName; + storedId; if (!editor && Object.keys(editors).length > 1) { - if (useStoredEditor() && (storedName = stored[files[0].mime]) && editors[storedName]) { - return dfd.resolve(editors[storedName]); + if (useStoredEditor() && (storedId = getStoreId(stored[files[0].mime])) && editors[storedId]) { + return dfd.resolve(editors[storedId]); } fm.trigger('contextmenu', { raw: getSubMenuRaw(files, function() { diff --git a/js/extras/editors.default.js b/js/extras/editors.default.js index 309d82a480..e40ed7d5d2 100644 --- a/js/extras/editors.default.js +++ b/js/extras/editors.default.js @@ -102,7 +102,8 @@ } }, pixlrLoad = function(mode, base) { - var fm = this.fm, + var self = this, + fm = this.fm, node = $(base).children('img:first') .data('loading')() .data('resizeoff', function() { @@ -147,9 +148,8 @@ }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: base, - name: 'Pixlr ' + mode.charAt(0).toUpperCase() + mode.substring(1), editorObj: void(0), instance: container, opts: opts @@ -210,6 +210,7 @@ { // Pixlr Editor info : { + id : 'pixlreditor', name : 'Pixlr Editor', iconImg : 'img/edit_pixlreditor.png', urlAsContent: true, @@ -242,6 +243,7 @@ { // Pixlr Express info : { + id: 'pixlrexpress', name : 'Pixlr Express', iconImg : 'img/edit_pixlrexpress.png', urlAsContent: true, @@ -274,6 +276,7 @@ // Adobe Creative SDK Creative Tools Image Editor UI // MIME types to accept info : { + id : 'creativecloud', name : 'Creative Cloud', iconImg : 'img/edit_creativecloud.png', schemeContent: true, @@ -361,9 +364,8 @@ language: getLang() }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: base, - name: 'Creative Cloud', editorObj: Aviary, instance: void(0), opts: opts @@ -412,6 +414,7 @@ }, // `mimes` is not set for support everything kind of text file info : { + id : 'aceeditor', name : 'ACE Editor', iconImg : 'img/edit_aceeditor.png' }, @@ -568,9 +571,8 @@ .prependTo(taBase.next()); // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: textarea, - name: 'ACE Editor', editorObj: ace, instance: editor, opts: {} @@ -613,6 +615,7 @@ }, // `mimes` is not set for support everything kind of text file info : { + id : 'codemirror', name : 'CodeMirror', iconImg : 'img/edit_codemirror.png' }, @@ -641,9 +644,8 @@ }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: textarea, - name: 'CodeMirror', editorObj: CodeMirror, instance: void(0), opts: opts @@ -769,6 +771,7 @@ } }, info : { + id : 'simplemde', name : 'SimpleMDE', iconImg : 'img/edit_simplemde.png' }, @@ -807,9 +810,8 @@ }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: textarea, - name: 'SimpleMDE', editorObj: SimpleMDE, instance: void(0), opts: opts @@ -865,6 +867,7 @@ { // CKEditor for html file info : { + id : 'ckeditor', name : 'CKEditor', iconImg : 'img/edit_ckeditor.png' }, @@ -929,9 +932,8 @@ }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: textarea, - name: 'CKEditor', editorObj: CKEDITOR, instance: void(0), opts: opts @@ -981,6 +983,7 @@ { // CKEditor5 balloon mode for html file info : { + id : 'ckeditor5', name : 'CKEditor5', iconImg : 'img/edit_ckeditor5.png' }, @@ -1042,9 +1045,8 @@ }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: editnode, - name: 'CKEditor5', editorObj: cEditor, instance: void(0), opts: opts @@ -1138,6 +1140,7 @@ { // TinyMCE for html file info : { + id : 'tinymce', name : 'TinyMCE', iconImg : 'img/edit_tinymce.png' }, @@ -1250,9 +1253,8 @@ }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + self.trigger('Prepare', { node: textarea, - name: 'TinyMCE', editorObj: tinymce, instance: void(0), opts: opts @@ -1292,6 +1294,7 @@ }, { info : { + id : 'zohoeditor', name : 'Zoho Editor', iconImg : 'img/edit_zohooffice.png', cmdCheck : 'ZohoOffice', @@ -1371,9 +1374,8 @@ } }; // trigger event 'editEditorPrepare' - fm.trigger('editEditorPrepare', { + ta.editor.trigger('Prepare', { node: ta, - name: 'Zoho Editor', editorObj: void(0), instance: ifm, opts: opts @@ -1428,14 +1430,14 @@ { // Simple Text (basic textarea editor) info : { + id : 'textarea', name : 'TextArea', useTextAreaEvent : true }, load : function(textarea) { // trigger event 'editEditorPrepare' - this.fm.trigger('editEditorPrepare', { + this.trigger('Prepare', { node: textarea, - name: 'TextArea', editorObj: void(0), instance: void(0), opts: {}