-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: drop ie8 support
- Loading branch information
Showing
28 changed files
with
205 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "dom-helpers", | ||
"version": "3.4.0", | ||
"description": "tiny modular DOM lib for ie8+", | ||
"description": "tiny modular DOM lib for ie9+", | ||
"author": { | ||
"name": "Jason Quense", | ||
"email": "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
import ownerDocument from './ownerDocument' | ||
|
||
/** | ||
* Return the actively focused element safely. | ||
* | ||
* @param doc the document to checl | ||
*/ | ||
export default function activeElement(doc = ownerDocument()) { | ||
// Support: IE 9 only | ||
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe> | ||
try { | ||
return doc.activeElement | ||
const active = doc.activeElement | ||
// IE11 returns a seemingly empty object in some cases when accessing | ||
// document.activeElement from an <iframe> | ||
if (!active || !active.nodeName) return null | ||
return active | ||
} catch (e) { | ||
/* ie throws if no active element */ | ||
return null | ||
return doc.body | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* eslint-disable no-return-assign */ | ||
import canUseDOM from './canUseDOM' | ||
|
||
export let optionsSupported = false | ||
export let onceSupported = false | ||
|
||
try { | ||
const options = { | ||
get passive() { | ||
return (optionsSupported = true) | ||
}, | ||
get once() { | ||
// eslint-disable-next-line no-multi-assign | ||
return (onceSupported = optionsSupported = true) | ||
}, | ||
} | ||
if (canUseDOM) { | ||
window.addEventListener('test', options as any, options) | ||
window.removeEventListener('test', options as any, true) | ||
} | ||
} catch (e) { | ||
/* */ | ||
} | ||
|
||
export type EventHandler<K extends keyof HTMLElementEventMap> = ( | ||
this: HTMLElement, | ||
event: HTMLElementEventMap[K] | ||
) => any | ||
|
||
export type TaggedEventHandler< | ||
K extends keyof HTMLElementEventMap | ||
> = EventHandler<K> & { __once?: EventHandler<K> } | ||
/** | ||
* An `addEventListener` ponyfill, supports the `once` option | ||
*/ | ||
function addEventListener<K extends keyof HTMLElementEventMap>( | ||
node: HTMLElement, | ||
eventName: K, | ||
handler: TaggedEventHandler<K>, | ||
options?: boolean | AddEventListenerOptions | ||
) { | ||
if (options && typeof options !== 'boolean' && !onceSupported) { | ||
const { once, capture } = options | ||
let wrappedHandler = handler | ||
if (!onceSupported && once) { | ||
wrappedHandler = | ||
handler.__once || | ||
function onceHandler(event) { | ||
this.removeEventListener(eventName, onceHandler, capture) | ||
handler.call(this, event) | ||
} | ||
handler.__once = wrappedHandler | ||
} | ||
|
||
node.addEventListener( | ||
eventName, | ||
wrappedHandler, | ||
optionsSupported ? options : capture | ||
) | ||
} | ||
|
||
node.addEventListener(eventName, handler, options) | ||
} | ||
|
||
export default addEventListener |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
import isDocument from './isDocument' | ||
import matches from './matches' | ||
|
||
let isDoc = (obj: any) => obj != null && obj.nodeType === document.DOCUMENT_NODE | ||
|
||
export default function closest( | ||
node: Element, | ||
selector: string, | ||
context: Element | ||
): Element | undefined { | ||
while (node && (isDoc(node) || !matches(node, selector))) { | ||
// @ts-ignore | ||
node = node !== context && !isDoc(node) ? node.parentNode : undefined | ||
} | ||
return node | ||
stopAt?: Element | ||
): Element | null { | ||
if (node.closest && !stopAt) node.closest(selector) | ||
|
||
let nextNode: Element | null = node | ||
do { | ||
if (matches(nextNode, selector)) return nextNode | ||
nextNode = nextNode.parentElement | ||
} while ( | ||
nextNode && | ||
nextNode !== stopAt && | ||
nextNode.nodeType === document.ELEMENT_NODE | ||
) | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
/* eslint-disable no-bitwise, no-cond-assign */ | ||
import canUseDOM from './canUseDOM' | ||
|
||
function fallback(context: Element, node: Element) { | ||
if (node) | ||
do { | ||
if (node === context) return true | ||
// @ts-ignore | ||
} while ((node = node.parentNode)) | ||
|
||
return false | ||
// HTML DOM and SVG DOM may have different support levels, | ||
// so we need to check on context instead of a document root element. | ||
export default function contains(context: Element, node: Element) { | ||
if (context.contains) return context.contains(node) | ||
if (context.compareDocumentPosition) | ||
return context === node || !!(context.compareDocumentPosition(node) & 16) | ||
} | ||
|
||
export default (function getContains() { | ||
// HTML DOM and SVG DOM may have different support levels, | ||
// so we need to check on context instead of a document root element. | ||
return canUseDOM | ||
? function contains(context: Element, node: Element) { | ||
if (context.contains) { | ||
return context.contains(node) | ||
} | ||
if (context.compareDocumentPosition) { | ||
return ( | ||
context === node || !!(context.compareDocumentPosition(node) & 16) | ||
) | ||
} | ||
return fallback(context, node) | ||
} | ||
: fallback | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,8 @@ | ||
import camelize from './camelizeStyle' | ||
import ownerWindow from './ownerWindow' | ||
import { Property } from './types' | ||
|
||
let rposition = /^(top|right|bottom|left)$/ | ||
let rnumnonpx = /^([+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|))(?!px)[a-z%]+$/i | ||
|
||
export default function _getComputedStyle(node: HTMLElement) { | ||
if (!node) throw new TypeError('No Element passed to `getComputedStyle()`') | ||
let window = ownerWindow(node) | ||
|
||
return 'getComputedStyle' in window | ||
? window.getComputedStyle(node, null) | ||
: // eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion | ||
({ | ||
// ie 8 "magic" from: https://github.com/jquery/jquery/blob/1.11-stable/src/css/curCSS.js#L72 | ||
getPropertyValue(property: Property) { | ||
let prop: string = property as string | ||
let style = node.style | ||
|
||
prop = camelize(prop) | ||
|
||
if (prop === 'float') prop = 'styleFloat' | ||
// @ts-ignore | ||
let current = node.currentStyle[prop] || null | ||
// @ts-ignore | ||
if (current == null && style && style[prop]) current = style[prop] | ||
|
||
if (rnumnonpx.test(current) && !rposition.test(prop)) { | ||
// Remember the original values | ||
let left = style.left | ||
// @ts-ignore | ||
let runStyle = node.runtimeStyle | ||
let rsLeft = runStyle && runStyle.left | ||
|
||
// Put in the new values to get a computed value out | ||
// @ts-ignore | ||
if (rsLeft) runStyle.left = node.currentStyle.left | ||
|
||
style.left = prop === 'fontSize' ? '1em' : current | ||
// @ts-ignore | ||
current = `${style.pixelLeft}px` | ||
|
||
// Revert the changed values | ||
style.left = left | ||
if (rsLeft) runStyle.left = rsLeft | ||
} | ||
|
||
return current | ||
}, | ||
} as CSSStyleDeclaration) | ||
export default function getComputedStyle( | ||
node: HTMLElement, | ||
psuedoElement?: string | ||
) { | ||
return ownerWindow(node).getComputedStyle(node, psuedoElement) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.