diff --git a/src/commands/main.js b/src/commands/main.js index de1f46026..972da145e 100644 --- a/src/commands/main.js +++ b/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} diff --git a/src/dom_components/model/ComponentImage.js b/src/dom_components/model/ComponentImage.js index 99c7122c6..bd20a3fb6 100644 --- a/src/dom_components/model/ComponentImage.js +++ b/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}