cleanup of edit flight page; added deps
This commit is contained in:
+2
-2
@@ -34,8 +34,8 @@ export default class Popper {
|
||||
};
|
||||
|
||||
// get reference and popper elements (allow jQuery wrappers)
|
||||
this.reference = reference.jquery ? reference[0] : reference;
|
||||
this.popper = popper.jquery ? popper[0] : popper;
|
||||
this.reference = reference && reference.jquery ? reference[0] : reference;
|
||||
this.popper = popper && popper.jquery ? popper[0] : popper;
|
||||
|
||||
// Deep merge modifiers options
|
||||
this.options.modifiers = {};
|
||||
|
||||
+13
-29
@@ -1,6 +1,4 @@
|
||||
import isNative from './isNative';
|
||||
|
||||
const isBrowser = typeof window !== 'undefined';
|
||||
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
||||
const longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
|
||||
let timeoutDuration = 0;
|
||||
for (let i = 0; i < longerTimeoutBrowsers.length; i += 1) {
|
||||
@@ -11,27 +9,17 @@ for (let i = 0; i < longerTimeoutBrowsers.length; i += 1) {
|
||||
}
|
||||
|
||||
export function microtaskDebounce(fn) {
|
||||
let scheduled = false;
|
||||
let i = 0;
|
||||
const elem = document.createElement('span');
|
||||
|
||||
// MutationObserver provides a mechanism for scheduling microtasks, which
|
||||
// are scheduled *before* the next task. This gives us a way to debounce
|
||||
// a function but ensure it's called *before* the next paint.
|
||||
const observer = new MutationObserver(() => {
|
||||
fn();
|
||||
scheduled = false;
|
||||
});
|
||||
|
||||
observer.observe(elem, { attributes: true });
|
||||
|
||||
let called = false
|
||||
return () => {
|
||||
if (!scheduled) {
|
||||
scheduled = true;
|
||||
elem.setAttribute('x-index', i);
|
||||
i = i + 1; // don't use compund (+=) because it doesn't get optimized in V8
|
||||
if (called) {
|
||||
return
|
||||
}
|
||||
};
|
||||
called = true
|
||||
Promise.resolve().then(() => {
|
||||
called = false
|
||||
fn()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function taskDebounce(fn) {
|
||||
@@ -47,12 +35,8 @@ export function taskDebounce(fn) {
|
||||
};
|
||||
}
|
||||
|
||||
// It's common for MutationObserver polyfills to be seen in the wild, however
|
||||
// these rely on Mutation Events which only occur when an element is connected
|
||||
// to the DOM. The algorithm used in this module does not use a connected element,
|
||||
// and so we must ensure that a *native* MutationObserver is available.
|
||||
const supportsNativeMutationObserver =
|
||||
isBrowser && isNative(window.MutationObserver);
|
||||
const supportsMicroTasks = isBrowser && window.Promise
|
||||
|
||||
|
||||
/**
|
||||
* Create a debounced version of a method, that's asynchronously deferred
|
||||
@@ -63,6 +47,6 @@ const supportsNativeMutationObserver =
|
||||
* @argument {Function} fn
|
||||
* @returns {Function}
|
||||
*/
|
||||
export default (supportsNativeMutationObserver
|
||||
export default (supportsMicroTasks
|
||||
? microtaskDebounce
|
||||
: taskDebounce);
|
||||
|
||||
@@ -35,10 +35,10 @@ export default function getBoundaries(
|
||||
if (boundariesElement === 'scrollParent') {
|
||||
boundariesNode = getScrollParent(getParentNode(popper));
|
||||
if (boundariesNode.nodeName === 'BODY') {
|
||||
boundariesNode = window.document.documentElement;
|
||||
boundariesNode = popper.ownerDocument.documentElement;
|
||||
}
|
||||
} else if (boundariesElement === 'window') {
|
||||
boundariesNode = window.document.documentElement;
|
||||
boundariesNode = popper.ownerDocument.documentElement;
|
||||
} else {
|
||||
boundariesNode = boundariesElement;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@ export default function getOffsetParent(element) {
|
||||
const nodeName = offsetParent && offsetParent.nodeName;
|
||||
|
||||
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
|
||||
if (element) {
|
||||
return element.ownerDocument.documentElement
|
||||
}
|
||||
|
||||
return window.document.documentElement;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ export default function getScroll(element, side = 'top') {
|
||||
const nodeName = element.nodeName;
|
||||
|
||||
if (nodeName === 'BODY' || nodeName === 'HTML') {
|
||||
const html = window.document.documentElement;
|
||||
const scrollingElement = window.document.scrollingElement || html;
|
||||
const html = element.ownerDocument.documentElement;
|
||||
const scrollingElement = element.ownerDocument.scrollingElement || html;
|
||||
return scrollingElement[upperSide];
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,16 @@ import getParentNode from './getParentNode';
|
||||
*/
|
||||
export default function getScrollParent(element) {
|
||||
// Return body, `getScroll` will take care to get the correct `scrollTop` from it
|
||||
if (
|
||||
!element ||
|
||||
['HTML', 'BODY', '#document'].indexOf(element.nodeName) !== -1
|
||||
) {
|
||||
return window.document.body;
|
||||
if (!element) {
|
||||
return window.document.body
|
||||
}
|
||||
|
||||
switch (element.nodeName) {
|
||||
case 'HTML':
|
||||
case 'BODY':
|
||||
return element.ownerDocument.body
|
||||
case '#document':
|
||||
return element.body
|
||||
}
|
||||
|
||||
// Firefox want us to check `-x` and `-y` variations as well
|
||||
|
||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ import getScroll from './getScroll';
|
||||
import getClientRect from './getClientRect';
|
||||
|
||||
export default function getViewportOffsetRectRelativeToArtbitraryNode(element) {
|
||||
const html = window.document.documentElement;
|
||||
const html = element.ownerDocument.documentElement;
|
||||
const relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
|
||||
const width = Math.max(html.clientWidth, window.innerWidth || 0);
|
||||
const height = Math.max(html.clientHeight, window.innerHeight || 0);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Get the window associated with the element
|
||||
* @argument {Element} element
|
||||
* @returns {Window}
|
||||
*/
|
||||
export default function getWindow(element) {
|
||||
const ownerDocument = element.ownerDocument;
|
||||
return ownerDocument ? ownerDocument.defaultView : window;
|
||||
}
|
||||
@@ -3,12 +3,14 @@ import isIE10 from './isIE10';
|
||||
function getSize(axis, body, html, computedStyle) {
|
||||
return Math.max(
|
||||
body[`offset${axis}`],
|
||||
body[`scroll${axis}`],
|
||||
html[`client${axis}`],
|
||||
html[`offset${axis}`],
|
||||
html[`scroll${axis}`],
|
||||
isIE10()
|
||||
? html[`offset${axis}`] +
|
||||
computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`] +
|
||||
computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`]
|
||||
computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`] +
|
||||
computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`]
|
||||
: 0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import isFixed from './isFixed';
|
||||
import isFunction from './isFunction';
|
||||
import isModifierEnabled from './isModifierEnabled';
|
||||
import isModifierRequired from './isModifierRequired';
|
||||
import isNative from './isNative';
|
||||
import isNumeric from './isNumeric';
|
||||
import removeEventListeners from './removeEventListeners';
|
||||
import runModifiers from './runModifiers';
|
||||
@@ -54,7 +53,6 @@ export {
|
||||
isFunction,
|
||||
isModifierEnabled,
|
||||
isModifierRequired,
|
||||
isNative,
|
||||
isNumeric,
|
||||
removeEventListeners,
|
||||
runModifiers,
|
||||
@@ -93,7 +91,6 @@ export default {
|
||||
isFunction,
|
||||
isModifierEnabled,
|
||||
isModifierRequired,
|
||||
isNative,
|
||||
isNumeric,
|
||||
removeEventListeners,
|
||||
runModifiers,
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
const nativeHints = [
|
||||
'native code',
|
||||
'[object MutationObserverConstructor]', // for mobile safari iOS 9.0
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if a function is implemented natively (as opposed to a polyfill).
|
||||
* @method
|
||||
* @memberof Popper.Utils
|
||||
* @argument {Function | undefined} fn the function to check
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export default fn =>
|
||||
nativeHints.some(hint => (fn || '').toString().indexOf(hint) > -1);
|
||||
@@ -1,3 +1,5 @@
|
||||
import getWindow from './getWindow';
|
||||
|
||||
/**
|
||||
* Remove event listeners used to update the popper position
|
||||
* @method
|
||||
@@ -6,7 +8,7 @@
|
||||
*/
|
||||
export default function removeEventListeners(reference, state) {
|
||||
// Remove resize event listener on window
|
||||
window.removeEventListener('resize', state.updateBound);
|
||||
getWindow(reference).removeEventListener('resize', state.updateBound);
|
||||
|
||||
// Remove scroll event listener on scroll parents
|
||||
state.scrollParents.forEach(target => {
|
||||
|
||||
@@ -18,10 +18,10 @@ export default function runModifiers(modifiers, data, ends) {
|
||||
: modifiers.slice(0, findIndex(modifiers, 'name', ends));
|
||||
|
||||
modifiersToRun.forEach(modifier => {
|
||||
if (modifier.function) {
|
||||
if (modifier['function']) { // eslint-disable-line dot-notation
|
||||
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
|
||||
}
|
||||
const fn = modifier.function || modifier.fn;
|
||||
const fn = modifier['function'] || modifier.fn; // eslint-disable-line dot-notation
|
||||
if (modifier.enabled && isFunction(fn)) {
|
||||
// Add properties to offsets to make them a complete clientRect object
|
||||
// we do this before each modifier to make sure the previous one doesn't
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import getScrollParent from './getScrollParent';
|
||||
import getWindow from './getWindow';
|
||||
|
||||
function attachToScrollParents(scrollParent, event, callback, scrollParents) {
|
||||
const isBody = scrollParent.nodeName === 'BODY';
|
||||
const target = isBody ? window : scrollParent;
|
||||
const target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
|
||||
target.addEventListener(event, callback, { passive: true });
|
||||
|
||||
if (!isBody) {
|
||||
@@ -30,7 +31,7 @@ export default function setupEventListeners(
|
||||
) {
|
||||
// Resize event listener on window
|
||||
state.updateBound = updateBound;
|
||||
window.addEventListener('resize', state.updateBound, { passive: true });
|
||||
getWindow(reference).addEventListener('resize', state.updateBound, { passive: true });
|
||||
|
||||
// Scroll event listener on scroll parents
|
||||
const scrollElement = getScrollParent(reference);
|
||||
|
||||
Reference in New Issue
Block a user