Skip to content

Commit

Permalink
Improve enable/disable handling
Browse files Browse the repository at this point in the history
This commit improves the enable/disable handling of the quill instance.
It introduces a new event called `STATE_CHANGE` which gets emitted when
the global `enable()` function is called.

Closes slab#909.
  • Loading branch information
Jacob Müller committed Sep 14, 2016
1 parent 99e35d9 commit 40a1e07
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions assets/base.styl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ colorItemsPerRow = 7
.ql-stroke, .ql-stroke-mitter
stroke: activeColor

.ql-toolbar-disabled
pointer-events: none


.ql-{themeName}
box-sizing: border-box
Expand Down
1 change: 1 addition & 0 deletions core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Editor {
this.scroll = scroll;
this.emitter = emitter;
this.emitter.on(Emitter.events.SCROLL_UPDATE, this.update.bind(this, null));
this.emitter.on(Emitter.events.STATE_CHANGE, (enabled) => this.enable(enabled));
this.delta = this.getDelta();
this.enable();
}
Expand Down
3 changes: 2 additions & 1 deletion core/quill.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class Quill {
}

enable(enabled = true) {
this.editor.enable(enabled);
const args = [enabled, Emitter.sources.API];
this.emitter.emit(Emitter.events.STATE_CHANGE, ...args);
if (!enabled) {
this.blur();
}
Expand Down
7 changes: 7 additions & 0 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class Toolbar extends Module {
let [range, ] = this.quill.selection.getRange(); // quill.getSelection triggers update
this.update(range);
});
this.quill.on(Quill.events.STATE_CHANGE, (enabled) => {
if (enabled) {
this.container.classList.remove('ql-toolbar-disabled');
} else {
this.container.classList.add('ql-toolbar-disabled');
}
});
}

addHandler(format, handler) {
Expand Down

0 comments on commit 40a1e07

Please sign in to comment.