perf: only run getSelection() check if we have to (#817)
This commit is contained in:
parent
3a335a9f4a
commit
f2f5508144
|
@ -1,7 +1,5 @@
|
||||||
// Delegate certain events to the global document for perf purposes.
|
// Delegate certain events to the global document for perf purposes.
|
||||||
|
|
||||||
import { mark, stop } from './marks'
|
|
||||||
|
|
||||||
const callbacks = {}
|
const callbacks = {}
|
||||||
|
|
||||||
if (process.browser && process.env.NODE_ENV !== 'production') {
|
if (process.browser && process.env.NODE_ENV !== 'production') {
|
||||||
|
@ -14,14 +12,6 @@ function onEvent (e) {
|
||||||
// we're not interested in any non-click or non-Enter events
|
// we're not interested in any non-click or non-Enter events
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (type === 'click') {
|
|
||||||
let selection = window.getSelection()
|
|
||||||
let selectionStr = selection && selection.toString()
|
|
||||||
if (selectionStr && selectionStr.length && target.contains(selection.anchorNode)) {
|
|
||||||
return // ignore if the user is selecting text inside the clickable area
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mark('delegate onEvent')
|
|
||||||
let key
|
let key
|
||||||
let element = target
|
let element = target
|
||||||
while (element) {
|
while (element) {
|
||||||
|
@ -31,9 +21,15 @@ function onEvent (e) {
|
||||||
element = element.parentElement
|
element = element.parentElement
|
||||||
}
|
}
|
||||||
if (key && callbacks[key]) {
|
if (key && callbacks[key]) {
|
||||||
|
if (type === 'click') {
|
||||||
|
let selection = window.getSelection()
|
||||||
|
let selectionStr = selection && selection.toString()
|
||||||
|
if (selectionStr && selectionStr.length && target.contains(selection.anchorNode)) {
|
||||||
|
return // ignore if the user is selecting text inside the clickable area
|
||||||
|
}
|
||||||
|
}
|
||||||
callbacks[key](e)
|
callbacks[key](e)
|
||||||
}
|
}
|
||||||
stop('delegate onEvent')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerClickDelegates (component, delegates) {
|
export function registerClickDelegates (component, delegates) {
|
||||||
|
|
Loading…
Reference in New Issue