Browse Source

Add `togglable` option to Buttons, if it's `false` you can't turn off the button

pull/1287/head
Artur Arseniev 8 years ago
parent
commit
f2e323b3ae
  1. 5
      docs/.vuepress/components/demos/utils.js
  2. 2
      docs/.vuepress/config.js
  3. 6
      docs/getting-started.md
  4. 1
      src/panels/model/Button.js
  5. 12
      src/panels/view/ButtonView.js

5
docs/.vuepress/components/demos/utils.js

@ -136,6 +136,7 @@ var panelSidebar = {
var buttonShowLayers = { var buttonShowLayers = {
id: 'show-layers', id: 'show-layers',
active: true, active: true,
togglable: false,
label: 'Layers', label: 'Layers',
command: { command: {
getRowEl(editor) { return editor.getContainer().parentNode.parentNode; }, getRowEl(editor) { return editor.getContainer().parentNode.parentNode; },
@ -157,6 +158,7 @@ var buttonShowLayers = {
var buttonShowStyle = { var buttonShowStyle = {
id: 'show-style', id: 'show-style',
label: 'Styles', label: 'Styles',
togglable: false,
active: true, active: true,
command: { command: {
getRowEl(editor) { return editor.getContainer().parentNode.parentNode; }, getRowEl(editor) { return editor.getContainer().parentNode.parentNode; },
@ -178,6 +180,7 @@ var buttonShowStyle = {
var buttonShowTraits = { var buttonShowTraits = {
id: 'show-traits', id: 'show-traits',
label: 'Traits', label: 'Traits',
togglable: false,
active: true, active: true,
command: { command: {
getTraitsEl(editor) { getTraitsEl(editor) {
@ -217,10 +220,12 @@ var panelDevices = {
label: 'D', label: 'D',
command: { run: editor => editor.setDevice('Desktop') }, command: { run: editor => editor.setDevice('Desktop') },
active: true, active: true,
togglable: false,
}, { }, {
id: 'device-mobile', id: 'device-mobile',
label: 'M', label: 'M',
command: { run: editor => editor.setDevice('Mobile') }, command: { run: editor => editor.setDevice('Mobile') },
togglable: false,
}], }],
}; };

2
docs/.vuepress/config.js

@ -74,7 +74,7 @@ module.exports = {
'/': [ '/': [
'', '',
['/getting-started', 'Getting Started'], ['/getting-started', 'Getting Started'],
['/faq', 'FAQ'], // ['/faq', 'FAQ'],
{ {
title: 'Modules', title: 'Modules',
collapsable: false, collapsable: false,

6
docs/getting-started.md

@ -318,11 +318,14 @@ const editor = grapesjs.init({
active: true, active: true,
label: 'Layers', label: 'Layers',
command: 'show-layers', command: 'show-layers',
// Once activated disable the possibility to turn it off
togglable: false,
}, { }, {
id: 'show-style', id: 'show-style',
active: true, active: true,
label: 'Styles', label: 'Styles',
command: 'show-styles', command: 'show-styles',
togglable: false,
}], }],
} }
] ]
@ -447,6 +450,7 @@ const editor = grapesjs.init({
active: true, active: true,
label: 'Traits', label: 'Traits',
command: 'show-traits', command: 'show-traits',
togglable: false,
}], }],
} }
] ]
@ -519,10 +523,12 @@ const editor = grapesjs.init({
label: 'D', label: 'D',
command: 'set-device-desktop', command: 'set-device-desktop',
active: true, active: true,
togglable: false,
}, { }, {
id: 'device-mobile', id: 'device-mobile',
label: 'M', label: 'M',
command: 'set-device-mobile', command: 'set-device-mobile',
togglable: false,
}], }],
} }
] ]

1
src/panels/model/Button.js

@ -12,6 +12,7 @@ module.exports = Backbone.Model.extend({
options: {}, options: {},
active: false, active: false,
dragDrop: false, dragDrop: false,
togglable: true,
runDefaultCommand: true, runDefaultCommand: true,
stopDefaultCommand: false, stopDefaultCommand: false,
disable: false disable: false

12
src/panels/view/ButtonView.js

@ -138,16 +138,20 @@ module.exports = Backbone.View.extend({
}, },
toogleActive() { toogleActive() {
var active = this.model.get('active'); const { model } = this;
this.model.set('active', !active); const { active, togglable } = model.attributes;
if (active && !togglable) return;
model.set('active', !active);
// If the stop is requested // If the stop is requested
var command = this.em.get('Commands').get('select-comp'); var command = this.em.get('Commands').get('select-comp');
if (active) { if (active) {
if (this.model.get('runDefaultCommand')) this.em.runDefault(); if (model.get('runDefaultCommand')) this.em.runDefault();
} else { } else {
if (this.model.get('stopDefaultCommand')) this.em.stopDefault(); if (model.get('stopDefaultCommand')) this.em.stopDefault();
} }
}, },

Loading…
Cancel
Save