cleanup of edit flight page; added deps

This commit is contained in:
Nabeel Shahzad
2017-11-01 11:08:36 -04:00
parent d48a02dd32
commit 321f2e94f5
293 changed files with 43830 additions and 572 deletions
+4 -4
View File
@@ -22,12 +22,12 @@
"bower_components",
"tests"
],
"version": "1.12.2",
"_release": "1.12.2",
"version": "1.12.6",
"_release": "1.12.6",
"_resolution": {
"type": "version",
"tag": "v1.12.2",
"commit": "f0620ae9583bd516dab60dfbfb4379d0d5272e84"
"tag": "v1.12.6",
"commit": "ef87c99e389a304fa00e85d6372bf8cb596b9de8"
},
"_source": "https://github.com/FezVrasta/popper.js.git",
"_target": "^1.12.0",
+5 -2
View File
@@ -1,3 +1,5 @@
<!-- IGNORE THE HTML BLOCK BELOW, THE INTERESTING PART IS AFTER IT -->
<h1 align="center">Popper.js</h1>
<p align="center">
@@ -16,6 +18,7 @@
<img src="https://raw.githubusercontent.com/FezVrasta/popper.js/master/popperjs.png" align="right" width=250 />
<!-- 🚨 HEY! HERE BEGINS THE INTERESTING STUFF 🚨 -->
## Wut? Poppers?
@@ -31,7 +34,7 @@ to make it possible to position it near a given reference element.
The engine is completely modular and most of its features are implemented as **modifiers**
(similar to middlewares or plugins).
The whole code base is written in ES2015 and its features are automatically tested on real browsers thank to [SauceLabs](https://saucelabs.com/) and [TravisCI](https://travis-ci.org/).
The whole code base is written in ES2015 and its features are automatically tested on real browsers thanks to [SauceLabs](https://saucelabs.com/) and [TravisCI](https://travis-ci.org/).
Popper.js has zero dependencies. No jQuery, no LoDash, nothing.
It's used by big companies like [Twitter in Bootstrap v4](https://getbootstrap.com/), [Microsoft in WebClipper](https://github.com/OneNoteDev/WebClipper) and [Atlassian in AtlasKit](https://aui-cdn.atlassian.com/atlaskit/registry/).
@@ -118,7 +121,7 @@ var anotherPopper = new Popper(
### Callbacks
Popper.js supports two kind of callbacks, the `onCreate` callback is called after
Popper.js supports two kinds of callbacks, the `onCreate` callback is called after
the popper has been initalized. The `onUpdate` one is called on any subsequent update.
```js
+48 -55
View File
@@ -1,6 +1,6 @@
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.12.2
* @version 1.12.6
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
@@ -61,10 +61,18 @@ function getParentNode(element) {
*/
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) {
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
var _getStyleComputedProp = getStyleComputedProperty(element),
@@ -92,6 +100,10 @@ function getOffsetParent(element) {
var nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
if (element) {
return element.ownerDocument.documentElement;
}
return window.document.documentElement;
}
@@ -187,8 +199,8 @@ function getScroll(element) {
var nodeName = element.nodeName;
if (nodeName === 'BODY' || nodeName === 'HTML') {
var html = window.document.documentElement;
var scrollingElement = window.document.scrollingElement || html;
var html = element.ownerDocument.documentElement;
var scrollingElement = element.ownerDocument.scrollingElement || html;
return scrollingElement[upperSide];
}
@@ -250,7 +262,7 @@ var isIE10$1 = function () {
};
function getSize(axis, body, html, computedStyle) {
return Math.max(body['offset' + axis], html['client' + axis], html['offset' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
}
function getWindowSizes() {
@@ -394,7 +406,7 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
}
function getViewportOffsetRectRelativeToArtbitraryNode(element) {
var html = window.document.documentElement;
var html = element.ownerDocument.documentElement;
var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
var width = Math.max(html.clientWidth, window.innerWidth || 0);
var height = Math.max(html.clientHeight, window.innerHeight || 0);
@@ -455,10 +467,10 @@ function getBoundaries(popper, reference, padding, boundariesElement) {
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;
}
@@ -557,22 +569,7 @@ function computeAutoPlacement(placement, refRect, popper, reference, boundariesE
return computedPlacement + (variation ? '-' + variation : '');
}
var nativeHints = ['native code', '[object MutationObserverConstructor]'];
/**
* 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}
*/
var isNative = (function (fn) {
return nativeHints.some(function (hint) {
return (fn || '').toString().indexOf(hint) > -1;
});
});
var isBrowser = typeof window !== 'undefined';
var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
var timeoutDuration = 0;
for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
@@ -583,26 +580,16 @@ for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
}
function microtaskDebounce(fn) {
var scheduled = false;
var i = 0;
var 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.
var observer = new MutationObserver(function () {
fn();
scheduled = false;
});
observer.observe(elem, { attributes: true });
var called = false;
return function () {
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(function () {
called = false;
fn();
});
};
}
@@ -619,11 +606,7 @@ 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.
var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserver);
var supportsMicroTasks = isBrowser && window.Promise;
/**
* Create a debounced version of a method, that's asynchronously deferred
@@ -634,7 +617,7 @@ var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserv
* @argument {Function} fn
* @returns {Function}
*/
var debounce = supportsNativeMutationObserver ? microtaskDebounce : taskDebounce;
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
/**
* Mimics the `find` method of Array
@@ -883,6 +866,16 @@ function isNumeric(n) {
return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
}
/**
* Get the window associated with the element
* @argument {Element} element
* @returns {Window}
*/
function getWindow(element) {
var ownerDocument = element.ownerDocument;
return ownerDocument ? ownerDocument.defaultView : window;
}
/**
* Remove event listeners used to update the popper position
* @method
@@ -891,7 +884,7 @@ function isNumeric(n) {
*/
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(function (target) {
@@ -920,10 +913,11 @@ function runModifiers(modifiers, data, ends) {
var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
modifiersToRun.forEach(function (modifier) {
if (modifier.function) {
if (modifier['function']) {
// eslint-disable-line dot-notation
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
}
var fn = modifier.function || modifier.fn;
var 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
@@ -978,7 +972,7 @@ function setStyles(element, styles) {
function attachToScrollParents(scrollParent, event, callback, scrollParents) {
var isBody = scrollParent.nodeName === 'BODY';
var target = isBody ? window : scrollParent;
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
target.addEventListener(event, callback, { passive: true });
if (!isBody) {
@@ -996,7 +990,7 @@ function attachToScrollParents(scrollParent, event, callback, scrollParents) {
function setupEventListeners(reference, options, state, updateBound) {
// 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
var scrollElement = getScrollParent(reference);
@@ -1037,7 +1031,6 @@ var index = {
isFunction: isFunction,
isModifierEnabled: isModifierEnabled,
isModifierRequired: isModifierRequired,
isNative: isNative,
isNumeric: isNumeric,
removeEventListeners: removeEventListeners,
runModifiers: runModifiers,
@@ -1046,5 +1039,5 @@ var index = {
setupEventListeners: setupEventListeners
};
export { computeAutoPlacement, debounce, findIndex, getBordersSize, getBoundaries, getBoundingClientRect, getClientRect, getOffsetParent, getOffsetRect, getOffsetRectRelativeToArbitraryNode, getOuterSizes, getParentNode, getPopperOffsets, getReferenceOffsets, getScroll, getScrollParent, getStyleComputedProperty, getSupportedPropertyName, getWindowSizes, isFixed, isFunction, isModifierEnabled, isModifierRequired, isNative, isNumeric, removeEventListeners, runModifiers, setAttributes, setStyles, setupEventListeners };export default index;
export { computeAutoPlacement, debounce, findIndex, getBordersSize, getBoundaries, getBoundingClientRect, getClientRect, getOffsetParent, getOffsetRect, getOffsetRectRelativeToArbitraryNode, getOuterSizes, getParentNode, getPopperOffsets, getReferenceOffsets, getScroll, getScrollParent, getStyleComputedProperty, getSupportedPropertyName, getWindowSizes, isFixed, isFunction, isModifierEnabled, isModifierRequired, isNumeric, removeEventListeners, runModifiers, setAttributes, setStyles, setupEventListeners };export default index;
//# sourceMappingURL=popper-utils.js.map
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+49 -55
View File
@@ -1,6 +1,6 @@
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.12.2
* @version 1.12.6
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
@@ -22,22 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
var nativeHints = ['native code', '[object MutationObserverConstructor]'];
/**
* 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}
*/
var isNative = (function (fn) {
return nativeHints.some(function (hint) {
return (fn || '').toString().indexOf(hint) > -1;
});
});
var isBrowser = typeof window !== 'undefined';
var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
var timeoutDuration = 0;
for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
@@ -48,26 +33,16 @@ for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
}
function microtaskDebounce(fn) {
var scheduled = false;
var i = 0;
var 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.
var observer = new MutationObserver(function () {
fn();
scheduled = false;
});
observer.observe(elem, { attributes: true });
var called = false;
return function () {
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(function () {
called = false;
fn();
});
};
}
@@ -84,11 +59,7 @@ 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.
var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserver);
var supportsMicroTasks = isBrowser && window.Promise;
/**
* Create a debounced version of a method, that's asynchronously deferred
@@ -99,7 +70,7 @@ var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserv
* @argument {Function} fn
* @returns {Function}
*/
var debounce = supportsNativeMutationObserver ? microtaskDebounce : taskDebounce;
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
/**
* Check if the given variable is a function
@@ -152,10 +123,18 @@ function getParentNode(element) {
*/
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) {
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
var _getStyleComputedProp = getStyleComputedProperty(element),
@@ -183,6 +162,10 @@ function getOffsetParent(element) {
var nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
if (element) {
return element.ownerDocument.documentElement;
}
return window.document.documentElement;
}
@@ -278,8 +261,8 @@ function getScroll(element) {
var nodeName = element.nodeName;
if (nodeName === 'BODY' || nodeName === 'HTML') {
var html = window.document.documentElement;
var scrollingElement = window.document.scrollingElement || html;
var html = element.ownerDocument.documentElement;
var scrollingElement = element.ownerDocument.scrollingElement || html;
return scrollingElement[upperSide];
}
@@ -341,7 +324,7 @@ var isIE10$1 = function () {
};
function getSize(axis, body, html, computedStyle) {
return Math.max(body['offset' + axis], html['client' + axis], html['offset' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
}
function getWindowSizes() {
@@ -528,7 +511,7 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
}
function getViewportOffsetRectRelativeToArtbitraryNode(element) {
var html = window.document.documentElement;
var html = element.ownerDocument.documentElement;
var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
var width = Math.max(html.clientWidth, window.innerWidth || 0);
var height = Math.max(html.clientHeight, window.innerHeight || 0);
@@ -589,10 +572,10 @@ function getBoundaries(popper, reference, padding, boundariesElement) {
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;
}
@@ -833,10 +816,11 @@ function runModifiers(modifiers, data, ends) {
var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
modifiersToRun.forEach(function (modifier) {
if (modifier.function) {
if (modifier['function']) {
// eslint-disable-line dot-notation
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
}
var fn = modifier.function || modifier.fn;
var 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
@@ -963,9 +947,19 @@ function destroy() {
return this;
}
/**
* Get the window associated with the element
* @argument {Element} element
* @returns {Window}
*/
function getWindow(element) {
var ownerDocument = element.ownerDocument;
return ownerDocument ? ownerDocument.defaultView : window;
}
function attachToScrollParents(scrollParent, event, callback, scrollParents) {
var isBody = scrollParent.nodeName === 'BODY';
var target = isBody ? window : scrollParent;
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
target.addEventListener(event, callback, { passive: true });
if (!isBody) {
@@ -983,7 +977,7 @@ function attachToScrollParents(scrollParent, event, callback, scrollParents) {
function setupEventListeners(reference, options, state, updateBound) {
// 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
var scrollElement = getScrollParent(reference);
@@ -1014,7 +1008,7 @@ function enableEventListeners() {
*/
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(function (target) {
@@ -2316,8 +2310,8 @@ var Popper = function () {
};
// 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 = {};
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+48 -51
View File
@@ -1,6 +1,6 @@
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.12.2
* @version 1.12.6
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
@@ -61,10 +61,18 @@ function getParentNode(element) {
*/
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) {
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
const { overflow, overflowX, overflowY } = getStyleComputedProperty(element);
if (/(auto|scroll)/.test(overflow + overflowY + overflowX)) {
@@ -87,6 +95,10 @@ function getOffsetParent(element) {
const nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
if (element) {
return element.ownerDocument.documentElement;
}
return window.document.documentElement;
}
@@ -178,8 +190,8 @@ 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];
}
@@ -239,7 +251,7 @@ var isIE10$1 = function () {
};
function getSize(axis, body, html, computedStyle) {
return Math.max(body[`offset${axis}`], html[`client${axis}`], html[`offset${axis}`], isIE10$1() ? html[`offset${axis}`] + computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`] + computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`] : 0);
return Math.max(body[`offset${axis}`], body[`scroll${axis}`], html[`client${axis}`], html[`offset${axis}`], html[`scroll${axis}`], isIE10$1() ? html[`offset${axis}`] + computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`] + computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`] : 0);
}
function getWindowSizes() {
@@ -383,7 +395,7 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
}
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);
@@ -444,10 +456,10 @@ function getBoundaries(popper, reference, padding, boundariesElement) {
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;
}
@@ -530,18 +542,7 @@ function computeAutoPlacement(placement, refRect, popper, reference, boundariesE
return computedPlacement + (variation ? `-${variation}` : '');
}
const nativeHints = ['native code', '[object MutationObserverConstructor]'];
/**
* 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}
*/
var isNative = (fn => nativeHints.some(hint => (fn || '').toString().indexOf(hint) > -1));
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) {
@@ -552,26 +553,16 @@ for (let i = 0; i < longerTimeoutBrowsers.length; i += 1) {
}
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();
});
};
}
@@ -588,11 +579,7 @@ 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
@@ -603,7 +590,7 @@ const supportsNativeMutationObserver = isBrowser && isNative(window.MutationObse
* @argument {Function} fn
* @returns {Function}
*/
var debounce = supportsNativeMutationObserver ? microtaskDebounce : taskDebounce;
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
/**
* Mimics the `find` method of Array
@@ -836,6 +823,16 @@ function isNumeric(n) {
return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
}
/**
* Get the window associated with the element
* @argument {Element} element
* @returns {Window}
*/
function getWindow(element) {
const ownerDocument = element.ownerDocument;
return ownerDocument ? ownerDocument.defaultView : window;
}
/**
* Remove event listeners used to update the popper position
* @method
@@ -844,7 +841,7 @@ function isNumeric(n) {
*/
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 => {
@@ -873,10 +870,11 @@ function runModifiers(modifiers, data, ends) {
const modifiersToRun = ends === undefined ? modifiers : 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
@@ -931,7 +929,7 @@ function setStyles(element, styles) {
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) {
@@ -949,7 +947,7 @@ function attachToScrollParents(scrollParent, event, callback, scrollParents) {
function setupEventListeners(reference, options, state, updateBound) {
// 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);
@@ -990,7 +988,6 @@ var index = {
isFunction,
isModifierEnabled,
isModifierRequired,
isNative,
isNumeric,
removeEventListeners,
runModifiers,
@@ -999,5 +996,5 @@ var index = {
setupEventListeners
};
export { computeAutoPlacement, debounce, findIndex, getBordersSize, getBoundaries, getBoundingClientRect, getClientRect, getOffsetParent, getOffsetRect, getOffsetRectRelativeToArbitraryNode, getOuterSizes, getParentNode, getPopperOffsets, getReferenceOffsets, getScroll, getScrollParent, getStyleComputedProperty, getSupportedPropertyName, getWindowSizes, isFixed, isFunction, isModifierEnabled, isModifierRequired, isNative, isNumeric, removeEventListeners, runModifiers, setAttributes, setStyles, setupEventListeners };export default index;
export { computeAutoPlacement, debounce, findIndex, getBordersSize, getBoundaries, getBoundingClientRect, getClientRect, getOffsetParent, getOffsetRect, getOffsetRectRelativeToArbitraryNode, getOuterSizes, getParentNode, getPopperOffsets, getReferenceOffsets, getScroll, getScrollParent, getStyleComputedProperty, getSupportedPropertyName, getWindowSizes, isFixed, isFunction, isModifierEnabled, isModifierRequired, isNumeric, removeEventListeners, runModifiers, setAttributes, setStyles, setupEventListeners };export default index;
//# sourceMappingURL=popper-utils.js.map
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+49 -51
View File
@@ -1,6 +1,6 @@
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.12.2
* @version 1.12.6
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
@@ -22,18 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
const nativeHints = ['native code', '[object MutationObserverConstructor]'];
/**
* 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}
*/
var isNative = (fn => nativeHints.some(hint => (fn || '').toString().indexOf(hint) > -1));
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) {
@@ -44,26 +33,16 @@ for (let i = 0; i < longerTimeoutBrowsers.length; i += 1) {
}
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();
});
};
}
@@ -80,11 +59,7 @@ 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
@@ -95,7 +70,7 @@ const supportsNativeMutationObserver = isBrowser && isNative(window.MutationObse
* @argument {Function} fn
* @returns {Function}
*/
var debounce = supportsNativeMutationObserver ? microtaskDebounce : taskDebounce;
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
/**
* Check if the given variable is a function
@@ -148,10 +123,18 @@ function getParentNode(element) {
*/
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) {
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
const { overflow, overflowX, overflowY } = getStyleComputedProperty(element);
if (/(auto|scroll)/.test(overflow + overflowY + overflowX)) {
@@ -174,6 +157,10 @@ function getOffsetParent(element) {
const nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
if (element) {
return element.ownerDocument.documentElement;
}
return window.document.documentElement;
}
@@ -265,8 +252,8 @@ 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];
}
@@ -326,7 +313,7 @@ var isIE10$1 = function () {
};
function getSize(axis, body, html, computedStyle) {
return Math.max(body[`offset${axis}`], html[`client${axis}`], html[`offset${axis}`], isIE10$1() ? html[`offset${axis}`] + computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`] + computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`] : 0);
return Math.max(body[`offset${axis}`], body[`scroll${axis}`], html[`client${axis}`], html[`offset${axis}`], html[`scroll${axis}`], isIE10$1() ? html[`offset${axis}`] + computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`] + computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`] : 0);
}
function getWindowSizes() {
@@ -470,7 +457,7 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
}
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);
@@ -531,10 +518,10 @@ function getBoundaries(popper, reference, padding, boundariesElement) {
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;
}
@@ -753,10 +740,11 @@ function runModifiers(modifiers, data, ends) {
const modifiersToRun = ends === undefined ? modifiers : 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
@@ -879,9 +867,19 @@ function destroy() {
return this;
}
/**
* Get the window associated with the element
* @argument {Element} element
* @returns {Window}
*/
function getWindow(element) {
const ownerDocument = element.ownerDocument;
return ownerDocument ? ownerDocument.defaultView : window;
}
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) {
@@ -899,7 +897,7 @@ function attachToScrollParents(scrollParent, event, callback, scrollParents) {
function setupEventListeners(reference, options, state, updateBound) {
// 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);
@@ -930,7 +928,7 @@ function enableEventListeners() {
*/
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 => {
@@ -2192,8 +2190,8 @@ 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 = {};
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+47 -55
View File
@@ -1,6 +1,6 @@
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.12.2
* @version 1.12.6
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
@@ -67,10 +67,18 @@ function getParentNode(element) {
*/
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) {
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
var _getStyleComputedProp = getStyleComputedProperty(element),
@@ -98,6 +106,10 @@ function getOffsetParent(element) {
var nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
if (element) {
return element.ownerDocument.documentElement;
}
return window.document.documentElement;
}
@@ -193,8 +205,8 @@ function getScroll(element) {
var nodeName = element.nodeName;
if (nodeName === 'BODY' || nodeName === 'HTML') {
var html = window.document.documentElement;
var scrollingElement = window.document.scrollingElement || html;
var html = element.ownerDocument.documentElement;
var scrollingElement = element.ownerDocument.scrollingElement || html;
return scrollingElement[upperSide];
}
@@ -256,7 +268,7 @@ var isIE10$1 = function () {
};
function getSize(axis, body, html, computedStyle) {
return Math.max(body['offset' + axis], html['client' + axis], html['offset' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
}
function getWindowSizes() {
@@ -400,7 +412,7 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
}
function getViewportOffsetRectRelativeToArtbitraryNode(element) {
var html = window.document.documentElement;
var html = element.ownerDocument.documentElement;
var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
var width = Math.max(html.clientWidth, window.innerWidth || 0);
var height = Math.max(html.clientHeight, window.innerHeight || 0);
@@ -461,10 +473,10 @@ function getBoundaries(popper, reference, padding, boundariesElement) {
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;
}
@@ -563,22 +575,7 @@ function computeAutoPlacement(placement, refRect, popper, reference, boundariesE
return computedPlacement + (variation ? '-' + variation : '');
}
var nativeHints = ['native code', '[object MutationObserverConstructor]'];
/**
* 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}
*/
var isNative = (function (fn) {
return nativeHints.some(function (hint) {
return (fn || '').toString().indexOf(hint) > -1;
});
});
var isBrowser = typeof window !== 'undefined';
var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
var timeoutDuration = 0;
for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
@@ -589,26 +586,16 @@ for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
}
function microtaskDebounce(fn) {
var scheduled = false;
var i = 0;
var 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.
var observer = new MutationObserver(function () {
fn();
scheduled = false;
});
observer.observe(elem, { attributes: true });
var called = false;
return function () {
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(function () {
called = false;
fn();
});
};
}
@@ -625,11 +612,7 @@ 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.
var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserver);
var supportsMicroTasks = isBrowser && window.Promise;
/**
* Create a debounced version of a method, that's asynchronously deferred
@@ -640,7 +623,7 @@ var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserv
* @argument {Function} fn
* @returns {Function}
*/
var debounce = supportsNativeMutationObserver ? microtaskDebounce : taskDebounce;
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
/**
* Mimics the `find` method of Array
@@ -889,6 +872,16 @@ function isNumeric(n) {
return n !== '' && !isNaN(parseFloat(n)) && isFinite(n);
}
/**
* Get the window associated with the element
* @argument {Element} element
* @returns {Window}
*/
function getWindow(element) {
var ownerDocument = element.ownerDocument;
return ownerDocument ? ownerDocument.defaultView : window;
}
/**
* Remove event listeners used to update the popper position
* @method
@@ -897,7 +890,7 @@ function isNumeric(n) {
*/
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(function (target) {
@@ -926,10 +919,11 @@ function runModifiers(modifiers, data, ends) {
var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
modifiersToRun.forEach(function (modifier) {
if (modifier.function) {
if (modifier['function']) {
// eslint-disable-line dot-notation
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
}
var fn = modifier.function || modifier.fn;
var 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
@@ -984,7 +978,7 @@ function setStyles(element, styles) {
function attachToScrollParents(scrollParent, event, callback, scrollParents) {
var isBody = scrollParent.nodeName === 'BODY';
var target = isBody ? window : scrollParent;
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
target.addEventListener(event, callback, { passive: true });
if (!isBody) {
@@ -1002,7 +996,7 @@ function attachToScrollParents(scrollParent, event, callback, scrollParents) {
function setupEventListeners(reference, options, state, updateBound) {
// 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
var scrollElement = getScrollParent(reference);
@@ -1043,7 +1037,6 @@ var index = {
isFunction: isFunction,
isModifierEnabled: isModifierEnabled,
isModifierRequired: isModifierRequired,
isNative: isNative,
isNumeric: isNumeric,
removeEventListeners: removeEventListeners,
runModifiers: runModifiers,
@@ -1075,7 +1068,6 @@ exports.isFixed = isFixed;
exports.isFunction = isFunction;
exports.isModifierEnabled = isModifierEnabled;
exports.isModifierRequired = isModifierRequired;
exports.isNative = isNative;
exports.isNumeric = isNumeric;
exports.removeEventListeners = removeEventListeners;
exports.runModifiers = runModifiers;
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+49 -55
View File
@@ -1,6 +1,6 @@
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.12.2
* @version 1.12.6
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
@@ -28,22 +28,7 @@
(global.Popper = factory());
}(this, (function () { 'use strict';
var nativeHints = ['native code', '[object MutationObserverConstructor]'];
/**
* 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}
*/
var isNative = (function (fn) {
return nativeHints.some(function (hint) {
return (fn || '').toString().indexOf(hint) > -1;
});
});
var isBrowser = typeof window !== 'undefined';
var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
var longerTimeoutBrowsers = ['Edge', 'Trident', 'Firefox'];
var timeoutDuration = 0;
for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
@@ -54,26 +39,16 @@ for (var i = 0; i < longerTimeoutBrowsers.length; i += 1) {
}
function microtaskDebounce(fn) {
var scheduled = false;
var i = 0;
var 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.
var observer = new MutationObserver(function () {
fn();
scheduled = false;
});
observer.observe(elem, { attributes: true });
var called = false;
return function () {
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(function () {
called = false;
fn();
});
};
}
@@ -90,11 +65,7 @@ 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.
var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserver);
var supportsMicroTasks = isBrowser && window.Promise;
/**
* Create a debounced version of a method, that's asynchronously deferred
@@ -105,7 +76,7 @@ var supportsNativeMutationObserver = isBrowser && isNative(window.MutationObserv
* @argument {Function} fn
* @returns {Function}
*/
var debounce = supportsNativeMutationObserver ? microtaskDebounce : taskDebounce;
var debounce = supportsMicroTasks ? microtaskDebounce : taskDebounce;
/**
* Check if the given variable is a function
@@ -158,10 +129,18 @@ function getParentNode(element) {
*/
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) {
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
var _getStyleComputedProp = getStyleComputedProperty(element),
@@ -189,6 +168,10 @@ function getOffsetParent(element) {
var nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
if (element) {
return element.ownerDocument.documentElement;
}
return window.document.documentElement;
}
@@ -284,8 +267,8 @@ function getScroll(element) {
var nodeName = element.nodeName;
if (nodeName === 'BODY' || nodeName === 'HTML') {
var html = window.document.documentElement;
var scrollingElement = window.document.scrollingElement || html;
var html = element.ownerDocument.documentElement;
var scrollingElement = element.ownerDocument.scrollingElement || html;
return scrollingElement[upperSide];
}
@@ -347,7 +330,7 @@ var isIE10$1 = function () {
};
function getSize(axis, body, html, computedStyle) {
return Math.max(body['offset' + axis], html['client' + axis], html['offset' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
return Math.max(body['offset' + axis], body['scroll' + axis], html['client' + axis], html['offset' + axis], html['scroll' + axis], isIE10$1() ? html['offset' + axis] + computedStyle['margin' + (axis === 'Height' ? 'Top' : 'Left')] + computedStyle['margin' + (axis === 'Height' ? 'Bottom' : 'Right')] : 0);
}
function getWindowSizes() {
@@ -534,7 +517,7 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
}
function getViewportOffsetRectRelativeToArtbitraryNode(element) {
var html = window.document.documentElement;
var html = element.ownerDocument.documentElement;
var relativeOffset = getOffsetRectRelativeToArbitraryNode(element, html);
var width = Math.max(html.clientWidth, window.innerWidth || 0);
var height = Math.max(html.clientHeight, window.innerHeight || 0);
@@ -595,10 +578,10 @@ function getBoundaries(popper, reference, padding, boundariesElement) {
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;
}
@@ -839,10 +822,11 @@ function runModifiers(modifiers, data, ends) {
var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));
modifiersToRun.forEach(function (modifier) {
if (modifier.function) {
if (modifier['function']) {
// eslint-disable-line dot-notation
console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
}
var fn = modifier.function || modifier.fn;
var 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
@@ -969,9 +953,19 @@ function destroy() {
return this;
}
/**
* Get the window associated with the element
* @argument {Element} element
* @returns {Window}
*/
function getWindow(element) {
var ownerDocument = element.ownerDocument;
return ownerDocument ? ownerDocument.defaultView : window;
}
function attachToScrollParents(scrollParent, event, callback, scrollParents) {
var isBody = scrollParent.nodeName === 'BODY';
var target = isBody ? window : scrollParent;
var target = isBody ? scrollParent.ownerDocument.defaultView : scrollParent;
target.addEventListener(event, callback, { passive: true });
if (!isBody) {
@@ -989,7 +983,7 @@ function attachToScrollParents(scrollParent, event, callback, scrollParents) {
function setupEventListeners(reference, options, state, updateBound) {
// 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
var scrollElement = getScrollParent(reference);
@@ -1020,7 +1014,7 @@ function enableEventListeners() {
*/
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(function (target) {
@@ -2322,8 +2316,8 @@ var Popper = function () {
};
// 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 = {};
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -7,7 +7,7 @@ layout: landing
<h2>{{ site.title }}</h2>
<p>{{ site.description | markdownify }}</p>
<ul class="actions">
<li><a href="https://github.com/FezVrasta/popper.js/releases" class="button special">Download v1</a></li>
<li><a href="https://github.com/FezVrasta/popper.js#installation" class="button special">Install v1</a></li>
</ul>
</div>
<a href="#one" class="more scrolly">Learn More</a>
+1 -1
View File
@@ -4,7 +4,7 @@
"packages/*"
],
"version": "0.0.0",
"npmClient": "npm",
"npmClient": "yarn",
"commands": {
"run": {
"ignore": "\\@popperjs/*"
+9 -7
View File
@@ -6,16 +6,15 @@
"devDependencies": {
"async": "^2.5.0",
"babel-eslint": "^7.2.3",
"bundlesize": "^0.12.1",
"bundlesize": "^0.14.4",
"chalk": "^2.1.0",
"eslint-plugin-jasmine": "^2.7.1",
"jsdoc-to-markdown": "^3.0.0",
"lerna": "^2.0.0",
"lerna": "^2.2.0",
"lint-staged": "^4.0.1",
"opt-cli": "^1.5.1",
"pre-commit": "^1.2.2",
"prettier-eslint-cli": "^4.1.1",
"wait-on": "^2.0.2",
"wide-align": "^1.1.2"
"wait-on": "^2.0.2"
},
"scripts": {
"precommit": "lint-staged",
@@ -37,12 +36,15 @@
"bundlesize": [
{
"path": "./packages/popper/dist/popper.min.js",
"threshold": "7 Kb"
"threshold": "7.5 Kb"
},
{
"path": "./packages/tooltip/dist/tooltip.min.js",
"threshold": "2 Kb"
}
],
"dependencies": {}
"dependencies": {},
"workspaces": [
"packages/*"
]
}
+219
View File
@@ -0,0 +1,219 @@
<!-- IGNORE THE HTML BLOCK BELOW, THE INTERESTING PART IS AFTER IT -->
<h1 align="center">Popper.js</h1>
<p align="center">
<strong>A library used to position poppers in web applications.</strong>
</p>
<p align="center">
<a href="https://travis-ci.org/FezVrasta/popper.js/branches" target="_blank"><img src="https://travis-ci.org/FezVrasta/popper.js.svg?branch=master" alt="Build Status"/></a>
<img src="http://img.badgesize.io/https://unpkg.com/popper.js/dist/popper.min.js?compression=gzip" alt="Stable Release Size"/>
<a href="https://www.bithound.io/github/FezVrasta/popper.js"><img src="https://www.bithound.io/github/FezVrasta/popper.js/badges/score.svg" alt="bitHound Overall Score"></a>
<a href="https://codeclimate.com/github/FezVrasta/popper.js/coverage"><img src="https://codeclimate.com/github/FezVrasta/popper.js/badges/coverage.svg" alt="Istanbul Code Coverage"/></a>
<a href="https://gitter.im/FezVrasta/popper.js" target="_blank"><img src="https://img.shields.io/gitter/room/nwjs/nw.js.svg" alt="Get support or discuss"/></a>
<br />
<a href="https://saucelabs.com/u/popperjs" target="_blank"><img src="https://badges.herokuapp.com/browsers?labels=none&googlechrome=latest&firefox=latest&microsoftedge=latest&iexplore=11,10&safari=latest&iphone=latest" alt="SauceLabs Reports"/></a>
</p>
<img src="https://raw.githubusercontent.com/FezVrasta/popper.js/master/popperjs.png" align="right" width=250 />
<!-- 🚨 HEY! HERE BEGINS THE INTERESTING STUFF 🚨 -->
## Wut? Poppers?
A popper is an element on the screen which "pops out" from the natural flow of your application.
Common examples of poppers are tooltips, popovers and drop-downs.
## So, yet another tooltip library?
Well, basically, **no**.
Popper.js is a **positioning engine**, its purpose is to calculate the position of an element
to make it possible to position it near a given reference element.
The engine is completely modular and most of its features are implemented as **modifiers**
(similar to middlewares or plugins).
The whole code base is written in ES2015 and its features are automatically tested on real browsers thanks to [SauceLabs](https://saucelabs.com/) and [TravisCI](https://travis-ci.org/).
Popper.js has zero dependencies. No jQuery, no LoDash, nothing.
It's used by big companies like [Twitter in Bootstrap v4](https://getbootstrap.com/), [Microsoft in WebClipper](https://github.com/OneNoteDev/WebClipper) and [Atlassian in AtlasKit](https://aui-cdn.atlassian.com/atlaskit/registry/).
### Popper.js
This is the engine, the library that computes and, optionally, applies the styles to
the poppers.
Some of the key points are:
- Position elements keeping them in their original DOM context (doesn't mess with your DOM!);
- Allows to export the computed informations to integrate with React and other view libraries;
- Supports Shadow DOM elements;
- Completely customizable thanks to the modifiers based structure;
Visit our [project page](https://fezvrasta.github.io/popper.js) to see a lot of examples of what you can do with Popper.js!
Find [the documentation here](docs/_includes/popper-documentation.md).
### Tooltip.js
Since lots of users just need a simple way to integrate powerful tooltips in their projects,
we created **Tooltip.js**.
It's a small library that makes it easy to automatically create tooltips using as engine Popper.js.
Its API is almost identical to the famous tooltip system of Bootstrap, in this way it will be
easy to integrate it in your projects.
The tooltips generated by Tooltip.js are accessible thanks to the `aria` tags.
Find [the documentation here](docs/_includes/tooltip-documentation.md).
## Installation
Popper.js is available on the following package managers and CDNs:
| Source | |
|:-------|:---------------------------------------------------------------------------------|
| npm | `npm install popper.js --save` |
| yarn | `yarn add popper.js` |
| NuGet | `PM> Install-Package popper.js` |
| Bower | `bower install popper.js --save` |
| unpkg | [`https://unpkg.com/popper.js`](https://unpkg.com/popper.js) |
| cdnjs | [`https://cdnjs.com/libraries/popper.js`](https://cdnjs.com/libraries/popper.js) |
Tooltip.js as well:
| Source | |
|:-------|:---------------------------------------------------------------------------------|
| npm | `npm install tooltip.js --save` |
| yarn | `yarn add tooltip.js` |
| Bower* | `bower install tooltip.js=https://unpkg.com/tooltip.js --save` |
| unpkg | [`https://unpkg.com/tooltip.js`](https://unpkg.com/tooltip.js) |
| cdnjs | [`https://cdnjs.com/libraries/popper.js`](https://cdnjs.com/libraries/popper.js) |
\*: Bower isn't officially supported, it can be used to install Tooltip.js only trough the unpkg.com CDN. This method has the limitation of not being able to define a specific version of the library. Bower and Popper.js suggests to use npm or Yarn for your projects.
For more info, [read the related issue](https://github.com/FezVrasta/popper.js/issues/390).
### Dist targets
Popper.js is currently shipped with 3 targets in mind: UMD, ESM and ESNext.
- UMD - Universal Module Definition: AMD, RequireJS and globals;
- ESM - ES Modules: For webpack/Rollup or browser supporting the spec;
- ESNext: Available in `dist/`, can be used with webpack and `babel-preset-env`;
Make sure to use the right one for your needs. If you want to import it with a `<script>` tag, use UMD.
## Usage
Given an existing popper DOM node, ask Popper.js to position it near its button
```js
var reference = document.querySelector('.my-button');
var popper = document.querySelector('.my-popper');
var anotherPopper = new Popper(
reference,
popper,
{
// popper options here
}
);
```
### Callbacks
Popper.js supports two kinds of callbacks, the `onCreate` callback is called after
the popper has been initalized. The `onUpdate` one is called on any subsequent update.
```js
const reference = document.querySelector('.my-button');
const popper = document.querySelector('.my-popper');
new Popper(reference, popper, {
onCreate: (data) => {
// data is an object containing all the informations computed
// by Popper.js and used to style the popper and its arrow
// The complete description is available in Popper.js documentation
},
onUpdate: (data) => {
// same as `onCreate` but called on subsequent updates
}
});
```
### Writing your own modifiers
Popper.js is based on a "plugin-like" architecture, most of its features are fully encapsulated "modifiers".
A modifier is a function that is called each time Popper.js needs to compute the position of the popper. For this reason, modifiers should be very performant to avoid bottlenecks.
To learn how to create a modifier, [read the modifiers documentation](docs/_includes/popper-documentation.md#modifiers--object)
### React, Vue.js, Angular, AngularJS, Ember.js (etc...) integration
Integrating 3rd party libraries in React or other libraries can be a pain because
they usually alter the DOM and drive the libraries crazy.
Popper.js limits all its DOM modifications inside the `applyStyle` modifier,
you can simply disable it and manually apply the popper coordinates using
your library of choice.
For a comprehensive list of libraries that let you use Popper.js into existing
frameworks, visit the [MENTIONS](MENTIONS.md) page.
Alternatively, you may even override your own `applyStyles` with your custom one and
integrate Popper.js by yourself!
```js
function applyReactStyle(data) {
// export data in your framework and use its content to apply the style to your popper
};
const reference = document.querySelector('.my-button');
const popper = document.querySelector('.my-popper');
new Popper(reference, popper, {
modifiers: {
applyStyle: { enabled: false },
applyReactStyle: {
enabled: true,
fn: applyReactStyle,
order: 800,
},
},
});
```
### Migration from Popper.js v0
Since the API changed, we prepared some migration instructions to make it easy to upgrade to
Popper.js v1.
https://github.com/FezVrasta/popper.js/issues/62
Feel free to comment inside the issue if you have any questions.
### Performances
Popper.js is very performant. It usually takes 0.5ms to compute a popper's position (on an iMac with 3.5G GHz Intel Core i5).
This means that it will not cause any [jank](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/anatomy-of-jank), leading to a smooth user experience.
## Notes
### Libraries using Popper.js
The aim of Popper.js is to provide a stable and powerful positioning engine ready to
be used in 3rd party libraries.
Visit the [MENTIONS](MENTIONS.md) page for an updated list of projects.
### Credits
I want to thank some friends and projects for the work they did:
- [@AndreaScn](https://github.com/AndreaScn) for his work on the GitHub Page and the manual testing he did during the development;
- [@vampolo](https://github.com/vampolo) for the original idea and for the name of the library;
- [Sysdig](https://github.com/Draios) for all the awesome things I learned during these years that made it possible for me to write this library;
- [Tether.js](http://github.hubspot.com/tether/) for having inspired me in writing a positioning library ready for the real world;
- [The Contributors](https://github.com/FezVrasta/popper.js/graphs/contributors) for their much appreciated Pull Requests and bug reports;
- **you** for the star you'll give to this project and for being so awesome to give this project a try 🙂
### Copyright and license
Code and documentation copyright 2016 **Federico Zivolo**. Code released under the [MIT license](LICENSE.md). Docs released under Creative Commons.
@@ -1,14 +1,26 @@
#!/bin/sh
# Get version from package.json
version="$(cat package.json | jq -r '.version')"
# Bower doesn't support Lerna multi-packages, we sacrificy flexibity
# making Bower use the whole repository just for the Popper.js release
cp -R dist ../../dist
cp bower.json ../../bower.json
git add -f ../../dist/*
git add ../../bower.json
git add package.json # In case we directly bump version during publish
# Commit the dist files
git commit --no-verify -m "chore(automatic): v${version} (dist files)"
# Create a tag which will reference the previous commit containing dist files
git tag -a v${version} -m "chore(automatic): v${version} (tag release)"
# Delete dist files and the copied `bower.json` root file
git rm ../../dist/**/*
git rm ../../dist/*
git rm ../../bower.json
# Create a git commit to get rid of the dist files from the repository
# they will still be accessible referencing the just created tag
git commit --no-verify -m "chore(automatic): v${version} (dist files cleanup)"
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "popper.js",
"version": "1.12.2",
"version": "1.12.6",
"description": "A kickass library to manage your poppers",
"homepage": "https://popper.js.org",
"repository": {
@@ -41,7 +41,7 @@
"devDependencies": {
"@popperjs/bundle": "^1.0.2",
"@popperjs/eslint-config-popper": "^1.0.0",
"nuget-publish": "^1.0.1",
"nuget-publish": "^1.0.3",
"@popperjs/test": "^1.0.0",
"@popperjs/test-utils": "^1.0.0",
"eslint": "^4.1.1"
+2 -2
View File
@@ -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
View File
@@ -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
@@ -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);
+17 -2
View File
@@ -3,7 +3,10 @@ const path = require('path');
const babel = require('rollup-plugin-babel');
const resolve = require('rollup-plugin-node-resolve');
const browsers = (argv.browsers || process.env.BROWSERS || 'ChromeHeadless').split(',');
const browsers = (argv.browsers ||
process.env.BROWSERS ||
'ChromeHeadless'
).split(',');
const singleRun = process.env.NODE_ENV === 'development' ? false : true;
const coverage = process.env.COVERAGE === true;
const basePath = process.cwd();
@@ -117,7 +120,7 @@ module.exports = function(config) {
rollupPreprocessor: {
format: 'umd',
sourceMap: 'inline',
sourcemap: 'inline',
globals: {
chai: 'chai',
'popper-utils': 'PopperUtils',
@@ -144,6 +147,18 @@ module.exports = function(config) {
],
},
reporters: ['mocha', 'saucelabs', 'coverage'],
plugins: [
require('karma-chai'),
require('karma-chrome-launcher'),
require('karma-coverage'),
require('karma-firefox-launcher'),
require('karma-jasmine'),
require('karma-mocha-reporter'),
require('karma-rollup-preprocessor'),
require('karma-safari-launcher'),
require('karma-sauce-launcher'),
require('karma-sinon'),
],
};
config.set(configuration);
+3 -3
View File
@@ -16,8 +16,8 @@
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-module-resolver": "^2.7.1",
"babel-preset-minify": "^0.2.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-minify": "^0.2.0",
"babel-preset-stage-2": "^6.24.1",
"chai": "^4.0.1",
"eslint": "^4.0.0",
@@ -32,11 +32,11 @@
"karma-firefox-launcher": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.3",
"karma-rollup-preprocessor": "^4.0.0",
"karma-rollup-preprocessor": "^5.0.0",
"karma-safari-launcher": "^1.0.0",
"karma-sauce-launcher": "^1.1.0",
"karma-sinon": "^1.0.5",
"rollup": "^0.43.0",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-watch": "^4.0.0",
+11 -9
View File
@@ -246,21 +246,23 @@ export default class Tooltip {
}
_dispose() {
// remove event listeners first to prevent any unexpected behaviour
this._events.forEach(({ func, event }) => {
this.reference.removeEventListener(event, func);
});
this._events = [];
if (this._tooltipNode) {
this._hide();
// destroy instance
this.popperInstance.destroy();
// remove event listeners
this._events.forEach(({ func, event }) => {
this.reference.removeEventListener(event, func);
});
this._events = [];
// destroy tooltipNode
this._tooltipNode.parentNode.removeChild(this._tooltipNode);
this._tooltipNode = null;
// destroy tooltipNode if removeOnDestroy is not set, as popperInstance.destroy() already removes the element
if(!this.popperInstance.options.removeOnDestroy){
this._tooltipNode.parentNode.removeChild(this._tooltipNode);
this._tooltipNode = null;
}
}
return this;
}
+6662 -46
View File
File diff suppressed because it is too large Load Diff