Skip to content

Commit

Permalink
[cmd:edit] add a property id into editor.info
Browse files Browse the repository at this point in the history
rel. #2381
  • Loading branch information
nao-pon committed Feb 15, 2018
1 parent c602e69 commit 04322e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
30 changes: 19 additions & 11 deletions js/commands/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
};
}

Expand Down Expand Up @@ -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;
}
});
},
Expand All @@ -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()});
}
Expand All @@ -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),
Expand Down Expand Up @@ -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: $('<span/>')
Expand Down Expand Up @@ -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() {
Expand Down
44 changes: 23 additions & 21 deletions js/extras/editors.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -210,6 +210,7 @@
{
// Pixlr Editor
info : {
id : 'pixlreditor',
name : 'Pixlr Editor',
iconImg : 'img/edit_pixlreditor.png',
urlAsContent: true,
Expand Down Expand Up @@ -242,6 +243,7 @@
{
// Pixlr Express
info : {
id: 'pixlrexpress',
name : 'Pixlr Express',
iconImg : 'img/edit_pixlrexpress.png',
urlAsContent: true,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
},
Expand Down Expand Up @@ -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: {}
Expand Down Expand Up @@ -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'
},
Expand Down Expand Up @@ -641,9 +644,8 @@
};

// trigger event 'editEditorPrepare'
fm.trigger('editEditorPrepare', {
self.trigger('Prepare', {
node: textarea,
name: 'CodeMirror',
editorObj: CodeMirror,
instance: void(0),
opts: opts
Expand Down Expand Up @@ -769,6 +771,7 @@
}
},
info : {
id : 'simplemde',
name : 'SimpleMDE',
iconImg : 'img/edit_simplemde.png'
},
Expand Down Expand Up @@ -807,9 +810,8 @@
};

// trigger event 'editEditorPrepare'
fm.trigger('editEditorPrepare', {
self.trigger('Prepare', {
node: textarea,
name: 'SimpleMDE',
editorObj: SimpleMDE,
instance: void(0),
opts: opts
Expand Down Expand Up @@ -865,6 +867,7 @@
{
// CKEditor for html file
info : {
id : 'ckeditor',
name : 'CKEditor',
iconImg : 'img/edit_ckeditor.png'
},
Expand Down Expand Up @@ -929,9 +932,8 @@
};

// trigger event 'editEditorPrepare'
fm.trigger('editEditorPrepare', {
self.trigger('Prepare', {
node: textarea,
name: 'CKEditor',
editorObj: CKEDITOR,
instance: void(0),
opts: opts
Expand Down Expand Up @@ -981,6 +983,7 @@
{
// CKEditor5 balloon mode for html file
info : {
id : 'ckeditor5',
name : 'CKEditor5',
iconImg : 'img/edit_ckeditor5.png'
},
Expand Down Expand Up @@ -1042,9 +1045,8 @@
};

// trigger event 'editEditorPrepare'
fm.trigger('editEditorPrepare', {
self.trigger('Prepare', {
node: editnode,
name: 'CKEditor5',
editorObj: cEditor,
instance: void(0),
opts: opts
Expand Down Expand Up @@ -1138,6 +1140,7 @@
{
// TinyMCE for html file
info : {
id : 'tinymce',
name : 'TinyMCE',
iconImg : 'img/edit_tinymce.png'
},
Expand Down Expand Up @@ -1250,9 +1253,8 @@
};

// trigger event 'editEditorPrepare'
fm.trigger('editEditorPrepare', {
self.trigger('Prepare', {
node: textarea,
name: 'TinyMCE',
editorObj: tinymce,
instance: void(0),
opts: opts
Expand Down Expand Up @@ -1292,6 +1294,7 @@
},
{
info : {
id : 'zohoeditor',
name : 'Zoho Editor',
iconImg : 'img/edit_zohooffice.png',
cmdCheck : 'ZohoOffice',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {}
Expand Down

0 comments on commit 04322e7

Please sign in to comment.