Browse Source

Add has() method to Commands and set conditionally image editor toolbar

pull/79/merge
Artur Arseniev 9 years ago
parent
commit
930aecd950
  1. 12
      src/commands/main.js
  2. 34
      src/dom_components/model/ComponentImage.js

12
src/commands/main.js

@ -2,6 +2,7 @@
* *
* * [add](#add) * * [add](#add)
* * [get](#get) * * [get](#get)
* * [has](#has)
* *
* You can init the editor with all necessary commands via configuration * You can init the editor with all necessary commands via configuration
* *
@ -201,7 +202,7 @@ define(function(require) {
* var myCommand = commands.get('myCommand'); * var myCommand = commands.get('myCommand');
* myCommand.run(); * myCommand.run();
* */ * */
get: function(id){ get: function(id) {
var el = commands[id]; var el = commands[id];
if(typeof el == 'function'){ if(typeof el == 'function'){
@ -212,6 +213,15 @@ define(function(require) {
return el; return el;
}, },
/**
* Check if command exists
* @param {string} id Command's ID
* @return {Boolean}
* */
has: function(id) {
return !!commands[id];
},
/** /**
* Load default commands * Load default commands
* @return {this} * @return {this}

34
src/dom_components/model/ComponentImage.js

@ -10,20 +10,7 @@ define(['./Component'],
void: 1, void: 1,
droppable: false, droppable: false,
resizable: true, resizable: true,
traits: ['alt'], traits: ['alt']
toolbar: [{
attributes: {class: 'fa fa-arrows'},
command: 'tlb-move',
},{
attributes: {class: 'fa fa-clone'},
command: 'tlb-clone',
},{
attributes: {class: 'fa fa-pencil'},
command: 'tlb-edit',
},{
attributes: {class: 'fa fa-trash-o'},
command: 'tlb-delete',
}],
}), }),
initialize: function(o, opt) { initialize: function(o, opt) {
@ -33,6 +20,25 @@ define(['./Component'],
this.set('src', attr.src); this.set('src', attr.src);
}, },
initToolbar: function() {
Component.prototype.initToolbar.apply(this, arguments);
if (this.sm && this.sm.get) {
var cmd = this.sm.get('Commands');
var cmdName = 'image-editor';
// Add Image Editor button only if the default command exists
if (cmd.has(cmdName)) {
var tb = this.get('toolbar');
tb.push({
attributes: {class: 'fa fa-pencil'},
command: cmdName,
});
this.set('toolbar', tb);
}
}
},
/** /**
* Returns object of attributes for HTML * Returns object of attributes for HTML
* @return {Object} * @return {Object}

Loading…
Cancel
Save