Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve enable handling #970

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions core/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Emitter.events = {
SCROLL_OPTIMIZE : 'scroll-optimize',
SCROLL_UPDATE : 'scroll-update',
SELECTION_CHANGE : 'selection-change',
STATE_CHANGE : 'state-change',
TEXT_CHANGE : 'text-change'
};
Emitter.sources = {
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