mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-15 11:09:01 +08:00
Merge pull request #650 from danderozier/gh-451-clean-up-event-handlers
Remove menu event handlers on destroy
This commit is contained in:
commit
15eb791b31
@ -20,18 +20,20 @@ class Menu {
|
|||||||
this.mousedownHandler = this.handleClick.bind(this)
|
this.mousedownHandler = this.handleClick.bind(this)
|
||||||
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
|
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
|
||||||
|
|
||||||
this.options.editor.on('focus', ({ view }) => {
|
this.focusHandler = ({ view }) => {
|
||||||
this.update(view)
|
this.update(view)
|
||||||
})
|
}
|
||||||
|
this.options.editor.on('focus', this.focusHandler)
|
||||||
|
|
||||||
this.options.editor.on('blur', ({ event }) => {
|
this.blurHandler = ({ event }) => {
|
||||||
if (this.preventHide) {
|
if (this.preventHide) {
|
||||||
this.preventHide = false
|
this.preventHide = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hide(event)
|
this.hide(event)
|
||||||
})
|
}
|
||||||
|
this.options.editor.on('blur', this.blurHandler)
|
||||||
|
|
||||||
// sometimes we have to update the position
|
// sometimes we have to update the position
|
||||||
// because of a loaded images for example
|
// because of a loaded images for example
|
||||||
@ -116,6 +118,9 @@ class Menu {
|
|||||||
if (this.resizeObserver) {
|
if (this.resizeObserver) {
|
||||||
this.resizeObserver.unobserve(this.editorView.dom)
|
this.resizeObserver.unobserve(this.editorView.dom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.options.editor.off('focus', this.focusHandler)
|
||||||
|
this.options.editor.off('blur', this.blurHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,15 @@ class Menu {
|
|||||||
this.mousedownHandler = this.handleClick.bind(this)
|
this.mousedownHandler = this.handleClick.bind(this)
|
||||||
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
|
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
|
||||||
|
|
||||||
this.options.editor.on('blur', () => {
|
this.blurHandler = () => {
|
||||||
if (this.preventHide) {
|
if (this.preventHide) {
|
||||||
this.preventHide = false
|
this.preventHide = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options.editor.emit('menubar:focusUpdate', false)
|
this.options.editor.emit('menubar:focusUpdate', false)
|
||||||
})
|
}
|
||||||
|
this.options.editor.on('blur', this.blurHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick() {
|
handleClick() {
|
||||||
@ -26,6 +27,7 @@ class Menu {
|
|||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
|
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
|
||||||
|
this.options.editor.off('blur', this.blurHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,18 +73,20 @@ class Menu {
|
|||||||
this.mousedownHandler = this.handleClick.bind(this)
|
this.mousedownHandler = this.handleClick.bind(this)
|
||||||
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
|
this.options.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
|
||||||
|
|
||||||
this.options.editor.on('focus', ({ view }) => {
|
this.focusHandler = ({ view }) => {
|
||||||
this.update(view)
|
this.update(view)
|
||||||
})
|
}
|
||||||
|
this.options.editor.on('focus', this.focusHandler)
|
||||||
|
|
||||||
this.options.editor.on('blur', ({ event }) => {
|
this.blurHandler = ({ event }) => {
|
||||||
if (this.preventHide) {
|
if (this.preventHide) {
|
||||||
this.preventHide = false
|
this.preventHide = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hide(event)
|
this.hide(event)
|
||||||
})
|
}
|
||||||
|
this.options.editor.on('blur', this.blurHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick() {
|
handleClick() {
|
||||||
@ -167,6 +169,8 @@ class Menu {
|
|||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
|
this.options.element.removeEventListener('mousedown', this.mousedownHandler)
|
||||||
|
this.options.editor.off('focus', this.focusHandler)
|
||||||
|
this.options.editor.off('blur', this.blurHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user