Browse Source

Disable stateless button

pull/561/head
Artur Arseniev 9 years ago
parent
commit
bea192f10b
  1. 4
      dist/grapes.min.js
  2. 2
      package-lock.json
  3. 2
      package.json
  4. 49
      src/panels/view/ButtonView.js

4
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
package-lock.json

@ -1,6 +1,6 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"version": "0.12.37", "version": "0.12.38",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Free and Open Source Web Builder Framework", "description": "Free and Open Source Web Builder Framework",
"version": "0.12.37", "version": "0.12.38",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",

49
src/panels/view/ButtonView.js

@ -1,3 +1,4 @@
import { isString, isObject, isFunction } from 'underscore';
const $ = Backbone.$; const $ = Backbone.$;
module.exports = Backbone.View.extend({ module.exports = Backbone.View.extend({
@ -197,40 +198,40 @@ module.exports = Backbone.View.extend({
* @return void * @return void
* */ * */
updateActive() { updateActive() {
const model = this.model;
const context = model.get('context');
const parent = this.parentM;
var command = null; var command = null;
var editor = this.em && this.em.get ? this.em.get('Editor') : null; var editor = this.em && this.em.get ? this.em.get('Editor') : null;
var commandName = this.model.get('command'); var commandName = model.get('command');
if (this.commands && typeof commandName === 'string') { if (this.commands && isString(commandName)) {
command = this.commands.get(commandName); command = this.commands.get(commandName);
} else if (commandName !== null && typeof commandName === 'object') { } else if (isFunction(commandName)) {
command = { run: commandName };
} else if (commandName !== null && isObject(commandName)) {
command = commandName; command = commandName;
} else if (typeof commandName === 'function') {
command = {run: commandName};
} }
if(this.model.get('active')){ if (model.get('active')) {
model.collection.deactivateAll(context);
model.set('active', true, { silent: true }).trigger('checkActive');
parent && parent.set('active', true, { silent: true }).trigger('checkActive');
this.model.collection.deactivateAll(this.model.get('context')); if (command && command.run) {
this.model.set('active', true, { silent: true }).trigger('checkActive'); command.run(editor, model, model.get('options'));
if(this.parentM)
this.parentM.set('active', true, { silent: true }).trigger('checkActive');
if(command && command.run){
command.run(editor, this.model, this.model.get('options'));
editor.trigger('run:' + commandName); editor.trigger('run:' + commandName);
} }
}else{
this.$el.removeClass(this.activeCls);
this.model.collection.deactivateAll(this.model.get('context'));
if(this.parentM) // Disable button if there is no stop method
this.parentM.set('active', false, { silent: true }).trigger('checkActive'); !command.stop && model.set('active', false);
} else {
this.$el.removeClass(this.activeCls);
model.collection.deactivateAll(context);
parent && parent.set('active', false, { silent: true }).trigger('checkActive');
if(command && command.stop){ if (command && command.stop) {
command.stop(editor, this.model, this.model.get('options')); command.stop(editor, model, model.get('options'));
editor.trigger('stop:' + commandName); editor.trigger('stop:' + commandName);
} }
} }
@ -242,7 +243,7 @@ module.exports = Backbone.View.extend({
} else { } else {
this.$el.removeClass(this.disableCls); this.$el.removeClass(this.disableCls);
} }
}, },
/** /**
@ -266,7 +267,7 @@ module.exports = Backbone.View.extend({
clicked(e) { clicked(e) {
if(this.model.get('bntsVis') ) if(this.model.get('bntsVis') )
return; return;
if(this.model.get('disable') ) if(this.model.get('disable') )
return; return;

Loading…
Cancel
Save