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

34
src/dom_components/model/ComponentImage.js

@ -10,20 +10,7 @@ define(['./Component'],
void: 1,
droppable: false,
resizable: true,
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',
}],
traits: ['alt']
}),
initialize: function(o, opt) {
@ -33,6 +20,25 @@ define(['./Component'],
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
* @return {Object}

Loading…
Cancel
Save