mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-27 05:00:48 +08:00
ffad17ff1f
mouseleave event sometimes can't fire. So I detect mouseout outside the popover and activator to make it disappear. Implementation has many tricks. Sigh, life is so hard.
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
class ResizeDelegate {
|
|
constructor () {
|
|
console.debug('[ResizeDelegate]: Ctor called')
|
|
this.handlers = []
|
|
this.handleResize = this.handleResize.bind(this)
|
|
}
|
|
handleResize (e) {
|
|
const handlers = this.handlers
|
|
if (handlers.length) {
|
|
for (const handler of handlers) {
|
|
handler(e)
|
|
}
|
|
}
|
|
}
|
|
unregisterHandler (handler) {
|
|
const handlers = this.handlers
|
|
if (handlers.length) {
|
|
console.debug('[ResizeDelegate]: remove resize handler from window')
|
|
window.removeEventListener('resize', this.handleResize, true)
|
|
} else {
|
|
// console.debug(handler)
|
|
const handlerIndex = handlers.findIndex(h => handler === h)
|
|
// console.debug(handlerIndex)
|
|
if (~handlerIndex) {
|
|
handlers.splice(handlerIndex, 1)
|
|
}
|
|
}
|
|
}
|
|
registerHandler (handler) {
|
|
if (!this.handlers.length) {
|
|
console.debug('[ResizeDelegate]: add resize handler to window')
|
|
window.addEventListener('resize', this.handleResize, true)
|
|
}
|
|
this.handlers.push(handler)
|
|
}
|
|
}
|
|
|
|
export default new ResizeDelegate()
|