Skip to content

Commit

Permalink
feat: detect whether passive is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Dec 10, 2019
1 parent 5fe6665 commit 15dc8da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 13 additions & 1 deletion packages/x6/src/common/detector.ts
Expand Up @@ -113,6 +113,18 @@ export namespace detector {
*/
export const SUPPORT_POINTER = (window as any).PointerEvent != null && !IS_MAC

export let SUPPORT_PASSIVE = false

try {
const options = Object.defineProperty({}, 'passive', {
get() {
SUPPORT_PASSIVE = true
},
})
const div = document.createElement('div')
div.addEventListener('click', () => {}, options)
} catch (err) {}

/**
* A flag indicating whether foreignObject support is not available. This
* is the case for Opera, older SVG-based browsers and all versions of IE.
Expand All @@ -121,7 +133,7 @@ export namespace detector {
!document.createElementNS ||
`${document.createElementNS(
'http://www.w3.org/2000/svg',
'foreignObject'
'foreignObject',
)}` !== '[object SVGForeignObjectElement]' ||
ua.indexOf('Opera/') >= 0

Expand Down
14 changes: 11 additions & 3 deletions packages/x6/src/common/disablable.ts
Expand Up @@ -4,7 +4,7 @@ export abstract class Disablable extends Primer {
private disabled: boolean = false

get enabled() {
return !this.disabled
return this.isEnabled()
}

enable() {
Expand All @@ -20,10 +20,18 @@ export abstract class Disablable extends Primer {
}

setEnadled(enabled: boolean) {
this.disabled = !enabled
if (enabled) {
this.enable()
} else {
this.disable()
}
}

toggleEnadled() {
this.disabled = !this.disabled
if (this.isEnabled()) {
this.disable()
} else {
this.enable()
}
}
}

0 comments on commit 15dc8da

Please sign in to comment.