Skip to content

Commit

Permalink
add root document to toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Nov 2, 2017
1 parent 059d062 commit 21a05e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion core/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class Emitter extends EventEmitter {
}

handleDOM(event, ...args) {
const target = (event.composedPath ? event.composedPath()[0] : event.target);

(this.listeners[event.type] || []).forEach(function({ node, handler }) {
const target = (event.composedPath ? event.composedPath()[0] : event.target);
if (target === node || node.contains(target)) {
handler(event, ...args);
}
Expand Down
10 changes: 6 additions & 4 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Selection {
this.lastRange = this.savedRange = new Range(0, 0);
this.handleComposition();
this.handleDragging();
this.emitter.listenDOM('selectionchange', document, () => {
this.emitter.listenDOM('selectionchange', this.rootDocument, () => {
if (!this.mouseDown) {
setTimeout(this.update.bind(this, Emitter.sources.USER), 1);
}
Expand Down Expand Up @@ -76,10 +76,12 @@ class Selection {
}

handleDragging() {
this.emitter.listenDOM('mousedown', document.body, () => {
const node = (this.rootDocument === document ? document.body : this.rootNode);

this.emitter.listenDOM('mousedown', node, () => {
this.mouseDown = true;
});
this.emitter.listenDOM('mouseup', document.body, () => {
this.emitter.listenDOM('mouseup', node, () => {
this.mouseDown = false;
this.update(Emitter.sources.USER);
});
Expand Down Expand Up @@ -175,7 +177,7 @@ class Selection {
}

hasFocus() {
return document.activeElement === this.root;
return this.rootDocument.activeElement === this.root;
}

normalizedToRange(range) {
Expand Down
5 changes: 3 additions & 2 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Quill from '../core/quill';
import logger from '../core/logger';
import Module from '../core/module';

const supportsRootNode = ('getRootNode' in document);
let debug = logger('quill:toolbar');


class Toolbar extends Module {
constructor(quill, options) {
super(quill, options);
Expand All @@ -16,7 +16,8 @@ class Toolbar extends Module {
quill.container.parentNode.insertBefore(container, quill.container);
this.container = container;
} else if (typeof this.options.container === 'string') {
this.container = document.querySelector(this.options.container);
const rootDocument = (supportsRootNode ? quill.container.getRootNode() : document);
this.container = rootDocument.querySelector(this.options.container);
} else {
this.container = this.options.container;
}
Expand Down

0 comments on commit 21a05e9

Please sign in to comment.