update popper e jSON

This commit is contained in:
Samuele E. Locatelli
2018-03-26 17:16:43 +02:00
parent 20968cb1e1
commit cd83d33c25
62 changed files with 102693 additions and 317 deletions
+96 -45
View File
@@ -1,6 +1,6 @@
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.12.9
* @version 1.14.1
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
@@ -75,13 +75,44 @@ function getScrollParent(element) {
// Firefox want us to check `-x` and `-y` variations as well
const { overflow, overflowX, overflowY } = getStyleComputedProperty(element);
if (/(auto|scroll)/.test(overflow + overflowY + overflowX)) {
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
return element;
}
return getScrollParent(getParentNode(element));
}
/**
* Tells if you are running Internet Explorer
* @method
* @memberof Popper.Utils
* @argument {number} version to check
* @returns {Boolean} isIE
*/
const cache = {};
var isIE = function (version = 'all') {
version = version.toString();
if (cache.hasOwnProperty(version)) {
return cache[version];
}
switch (version) {
case '11':
cache[version] = navigator.userAgent.indexOf('Trident') !== -1;
break;
case '10':
cache[version] = navigator.appVersion.indexOf('MSIE 10') !== -1;
break;
case 'all':
cache[version] = navigator.userAgent.indexOf('Trident') !== -1 || navigator.userAgent.indexOf('MSIE') !== -1;
break;
}
//Set IE
cache.all = cache.all || Object.keys(cache).some(key => cache[key]);
return cache[version];
};
/**
* Returns the offset parent of the given element
* @method
@@ -90,16 +121,23 @@ function getScrollParent(element) {
* @returns {Element} offset parent
*/
function getOffsetParent(element) {
if (!element) {
return document.documentElement;
}
const noOffsetParent = isIE(10) ? document.body : null;
// NOTE: 1 DOM access here
const offsetParent = element && element.offsetParent;
let offsetParent = element.offsetParent;
// Skip hidden elements which don't have an offsetParent
while (offsetParent === noOffsetParent && element.nextElementSibling) {
offsetParent = (element = element.nextElementSibling).offsetParent;
}
const nodeName = offsetParent && offsetParent.nodeName;
if (!nodeName || nodeName === 'BODY' || nodeName === 'HTML') {
if (element) {
return element.ownerDocument.documentElement;
}
return document.documentElement;
return element ? element.ownerDocument.documentElement : document.documentElement;
}
// .offsetParent will return the closest TD or TABLE in case
@@ -235,29 +273,14 @@ function getBordersSize(styles, axis) {
return parseFloat(styles[`border${sideA}Width`], 10) + parseFloat(styles[`border${sideB}Width`], 10);
}
/**
* Tells if you are running Internet Explorer 10
* @method
* @memberof Popper.Utils
* @returns {Boolean} isIE10
*/
let isIE10 = undefined;
var isIE10$1 = function () {
if (isIE10 === undefined) {
isIE10 = navigator.appVersion.indexOf('MSIE 10') !== -1;
}
return 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$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}`], isIE(10) ? html[`offset${axis}`] + computedStyle[`margin${axis === 'Height' ? 'Top' : 'Left'}`] + computedStyle[`margin${axis === 'Height' ? 'Bottom' : 'Right'}`] : 0);
}
function getWindowSizes() {
const body = document.body;
const html = document.documentElement;
const computedStyle = isIE10$1() && getComputedStyle(html);
const computedStyle = isIE(10) && getComputedStyle(html);
return {
height: getSize('Height', body, html, computedStyle),
@@ -306,8 +329,8 @@ function getBoundingClientRect(element) {
// IE10 10 FIX: Please, don't ask, the element isn't
// considered in DOM in some circumstances...
// This isn't reproducible in IE10 compatibility mode of IE11
if (isIE10$1()) {
try {
try {
if (isIE(10)) {
rect = element.getBoundingClientRect();
const scrollTop = getScroll(element, 'top');
const scrollLeft = getScroll(element, 'left');
@@ -315,10 +338,10 @@ function getBoundingClientRect(element) {
rect.left += scrollLeft;
rect.bottom += scrollTop;
rect.right += scrollLeft;
} catch (err) {}
} else {
rect = element.getBoundingClientRect();
}
} else {
rect = element.getBoundingClientRect();
}
} catch (e) {}
const result = {
left: rect.left,
@@ -349,8 +372,8 @@ function getBoundingClientRect(element) {
return getClientRect(result);
}
function getOffsetRectRelativeToArbitraryNode(children, parent) {
const isIE10 = isIE10$1();
function getOffsetRectRelativeToArbitraryNode(children, parent, fixedPosition = false) {
const isIE10 = isIE(10);
const isHTML = parent.nodeName === 'HTML';
const childrenRect = getBoundingClientRect(children);
const parentRect = getBoundingClientRect(parent);
@@ -360,6 +383,11 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
const borderTopWidth = parseFloat(styles.borderTopWidth, 10);
const borderLeftWidth = parseFloat(styles.borderLeftWidth, 10);
// In cases where the parent is fixed, we must ignore negative scroll in offset calc
if (fixedPosition && parent.nodeName === 'HTML') {
parentRect.top = Math.max(parentRect.top, 0);
parentRect.left = Math.max(parentRect.left, 0);
}
let offsets = getClientRect({
top: childrenRect.top - parentRect.top - borderTopWidth,
left: childrenRect.left - parentRect.left - borderLeftWidth,
@@ -387,21 +415,21 @@ function getOffsetRectRelativeToArbitraryNode(children, parent) {
offsets.marginLeft = marginLeft;
}
if (isIE10 ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
if (isIE10 && !fixedPosition ? parent.contains(scrollParent) : parent === scrollParent && scrollParent.nodeName !== 'BODY') {
offsets = includeScroll(offsets, parent);
}
return offsets;
}
function getViewportOffsetRectRelativeToArtbitraryNode(element) {
function getViewportOffsetRectRelativeToArtbitraryNode(element, excludeScroll = false) {
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);
const scrollTop = getScroll(html);
const scrollLeft = getScroll(html, 'left');
const scrollTop = !excludeScroll ? getScroll(html) : 0;
const scrollLeft = !excludeScroll ? getScroll(html, 'left') : 0;
const offset = {
top: scrollTop - relativeOffset.top + relativeOffset.marginTop,
@@ -432,6 +460,26 @@ function isFixed(element) {
return isFixed(getParentNode(element));
}
/**
* Finds the first parent of an element that has a transformed property defined
* @method
* @memberof Popper.Utils
* @argument {Element} element
* @returns {Element} first transformed parent or documentElement
*/
function getFixedPositionOffsetParent(element) {
// This check is needed to avoid errors in case one of the elements isn't defined for any reason
if (!element || !element.parentElement || isIE()) {
return document.documentElement;
}
let el = element.parentElement;
while (el && getStyleComputedProperty(el, 'transform') === 'none') {
el = el.parentElement;
}
return el || document.documentElement;
}
/**
* Computed the boundaries limits and return them
* @method
@@ -440,16 +488,18 @@ function isFixed(element) {
* @param {HTMLElement} reference
* @param {number} padding
* @param {HTMLElement} boundariesElement - Element used to define the boundaries
* @param {Boolean} fixedPosition - Is in fixed position mode
* @returns {Object} Coordinates of the boundaries
*/
function getBoundaries(popper, reference, padding, boundariesElement) {
function getBoundaries(popper, reference, padding, boundariesElement, fixedPosition = false) {
// NOTE: 1 DOM access here
let boundaries = { top: 0, left: 0 };
const offsetParent = findCommonOffsetParent(popper, reference);
const offsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
// Handle viewport case
if (boundariesElement === 'viewport') {
boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent);
boundaries = getViewportOffsetRectRelativeToArtbitraryNode(offsetParent, fixedPosition);
} else {
// Handle other cases based on DOM element used as boundaries
let boundariesNode;
@@ -464,7 +514,7 @@ function getBoundaries(popper, reference, padding, boundariesElement) {
boundariesNode = boundariesElement;
}
const offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent);
const offsets = getOffsetRectRelativeToArbitraryNode(boundariesNode, offsetParent, fixedPosition);
// In case of HTML, we need a different computation
if (boundariesNode.nodeName === 'HTML' && !isFixed(offsetParent)) {
@@ -737,11 +787,12 @@ function getPopperOffsets(popper, referenceOffsets, placement) {
* @param {Object} state
* @param {Element} popper - the popper element
* @param {Element} reference - the reference element (the popper will be relative to this)
* @param {Element} fixedPosition - is in fixed position mode
* @returns {Object} An object containing the offsets which will be applied to the popper
*/
function getReferenceOffsets(state, popper, reference) {
const commonOffsetParent = findCommonOffsetParent(popper, reference);
return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent);
function getReferenceOffsets(state, popper, reference, fixedPosition = null) {
const commonOffsetParent = fixedPosition ? getFixedPositionOffsetParent(popper) : findCommonOffsetParent(popper, reference);
return getOffsetRectRelativeToArbitraryNode(reference, commonOffsetParent, fixedPosition);
}
/**
@@ -755,7 +806,7 @@ function getSupportedPropertyName(property) {
const prefixes = [false, 'ms', 'Webkit', 'Moz', 'O'];
const upperProp = property.charAt(0).toUpperCase() + property.slice(1);
for (let i = 0; i < prefixes.length - 1; i++) {
for (let i = 0; i < prefixes.length; i++) {
const prefix = prefixes[i];
const toCheck = prefix ? `${prefix}${upperProp}` : property;
if (typeof document.body.style[toCheck] !== 'undefined') {