@borngroup/born-utilities
Advanced tools
Comparing version 2.5.3 to 3.0.0
@@ -1,389 +0,382 @@ | ||
define(['exports'], function (exports) { | ||
'use strict'; | ||
define(["exports"], function (_exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.isRTL = isRTL; | ||
exports.whichTransition = whichTransition; | ||
exports.createElWithAttrs = createElWithAttrs; | ||
exports.callbackOnElements = callbackOnElements; | ||
exports.getUrlParameter = getUrlParameter; | ||
exports.hasURLParameter = hasURLParameter; | ||
exports.getTotalRect = getTotalRect; | ||
exports.scrollToPosition = scrollToPosition; | ||
exports.objectAssign = objectAssign; | ||
exports.createCookie = createCookie; | ||
exports.readCookie = readCookie; | ||
exports.eraseCookie = eraseCookie; | ||
exports.forceFocus = forceFocus; | ||
exports.focusTrap = focusTrap; | ||
exports.parseScripts = parseScripts; | ||
Object.defineProperty(_exports, "__esModule", { | ||
value: true | ||
}); | ||
_exports.isRTL = isRTL; | ||
_exports.whichTransition = whichTransition; | ||
_exports.createElWithAttrs = createElWithAttrs; | ||
_exports.callbackOnElements = callbackOnElements; | ||
_exports.getUrlParameter = getUrlParameter; | ||
_exports.hasURLParameter = hasURLParameter; | ||
_exports.getTotalRect = getTotalRect; | ||
_exports.scrollToPosition = scrollToPosition; | ||
_exports.objectAssign = objectAssign; | ||
_exports.createCookie = createCookie; | ||
_exports.readCookie = readCookie; | ||
_exports.eraseCookie = eraseCookie; | ||
_exports.forceFocus = forceFocus; | ||
_exports.focusTrap = focusTrap; | ||
_exports.parseScripts = parseScripts; | ||
_exports.isMobile = void 0; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
/** | ||
* [Utilities]: methods and objects that contain reusable functionality and can be called on demand. | ||
*/ | ||
/** | ||
* [Utilities]: methods and objects that contain reusable functionality and can be called on demand. | ||
*/ | ||
/** | ||
* A few polyfillis to add core functionality on old browsers and help get rid of jQuery. | ||
* These should be removed once we don't care about older browsers. | ||
*/ | ||
(function () { | ||
//Element.matches() | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = Element.prototype.msMatchesSelector; | ||
} | ||
/** | ||
* A few polyfillis to add core functionality on old browsers and help get rid of jQuery. | ||
* These should be removed once we don't care about older browsers. | ||
*/ | ||
(function () { | ||
//Element.matches() | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = Element.prototype.msMatchesSelector; | ||
} //Element.closest() | ||
//Element.closest() | ||
if (!Element.prototype.closest) { | ||
Element.prototype.closest = _getClosest; | ||
} | ||
})(); | ||
function _getClosest(selector) { | ||
if (!Element.prototype.closest) { | ||
Element.prototype.closest = _getClosest; | ||
} | ||
})(); | ||
var currentEl = this; | ||
function _getClosest(selector) { | ||
var currentEl = this; | ||
while (currentEl.constructor !== HTMLHtmlElement) { | ||
if (currentEl.parentNode.matches(selector)) { | ||
while (currentEl.constructor !== HTMLHtmlElement) { | ||
if (currentEl.parentNode.matches(selector)) { | ||
return currentEl.parentNode; | ||
} else if (currentEl.matches(selector)) { | ||
return currentEl; | ||
} | ||
return currentEl.parentNode; | ||
} else if (currentEl.matches(selector)) { | ||
currentEl = currentEl.parentNode; | ||
} | ||
return currentEl; | ||
} | ||
return false; | ||
} | ||
/** | ||
* Returns true if current browser "is mobile" | ||
* @return {Boolean} | ||
*/ | ||
currentEl = currentEl.parentNode; | ||
} | ||
return false; | ||
var isMobile = { | ||
Android: function Android() { | ||
return navigator.userAgent.match(/Android/i); | ||
}, | ||
BlackBerry: function BlackBerry() { | ||
return navigator.userAgent.match(/BlackBerry/i); | ||
}, | ||
iOS: function iOS() { | ||
return navigator.userAgent.match(/iPhone|iPad|iPod/i); | ||
}, | ||
Opera: function Opera() { | ||
return navigator.userAgent.match(/Opera Mini/i); | ||
}, | ||
Windows: function Windows() { | ||
return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i); | ||
}, | ||
any: function any() { | ||
return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows(); | ||
} | ||
}; | ||
/** | ||
* Returns true if the document element <html> has its dir attribute set to rtl (dir="rtl") | ||
* @return {Boolean} | ||
*/ | ||
/** | ||
* Returns true if current browser "is mobile" | ||
* @return {Boolean} | ||
*/ | ||
var isMobile = exports.isMobile = { | ||
Android: function Android() { | ||
return navigator.userAgent.match(/Android/i); | ||
}, | ||
BlackBerry: function BlackBerry() { | ||
return navigator.userAgent.match(/BlackBerry/i); | ||
}, | ||
iOS: function iOS() { | ||
return navigator.userAgent.match(/iPhone|iPad|iPod/i); | ||
}, | ||
Opera: function Opera() { | ||
return navigator.userAgent.match(/Opera Mini/i); | ||
}, | ||
Windows: function Windows() { | ||
return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i); | ||
}, | ||
any: function any() { | ||
return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows(); | ||
} | ||
}; | ||
_exports.isMobile = isMobile; | ||
/** | ||
* Returns true if the document element <html> has its dir attribute set to rtl (dir="rtl") | ||
* @return {Boolean} | ||
*/ | ||
function isRTL() { | ||
return document.documentElement.getAttribute('dir') === 'rtl' ? true : false; | ||
function isRTL() { | ||
return document.documentElement.getAttribute('dir') === 'rtl' ? true : false; | ||
} | ||
; | ||
/** | ||
* [Returns the transition event type supported by the browser] | ||
*/ | ||
function whichTransition() { | ||
var dummyEl = document.createElement('dummy'), | ||
transitions = { | ||
'transition': 'transitionend', | ||
'OTransition': 'oTransitionEnd', | ||
'MozTransition': 'transitionend', | ||
'WebkitTransition': 'webkitTransitionEnd' | ||
}; | ||
/** | ||
* [Returns the transition event type supported by the browser] | ||
*/ | ||
function whichTransition() { | ||
var dummyEl = document.createElement('dummy'), | ||
transitions = { | ||
'transition': 'transitionend', | ||
'OTransition': 'oTransitionEnd', | ||
'MozTransition': 'transitionend', | ||
'WebkitTransition': 'webkitTransitionEnd' | ||
}; | ||
for (var key in transitions) { | ||
if (dummyEl.style[key] !== undefined) { | ||
return transitions[key]; | ||
} | ||
} | ||
for (var key in transitions) { | ||
if (dummyEl.style[key] !== undefined) { | ||
return transitions[key]; | ||
} | ||
} | ||
} | ||
/** | ||
* [createElWithAttrs creates an element with a set of given attributes passed as the 2nd parameter, | ||
* then appends the new element to the target parent passed on the 1st parameter] | ||
* @param {[String]} appendTarget [description] | ||
* @param {[Object]} attributes [description] | ||
* @param {[String]} type [description] | ||
* @return {[Element]} [description] | ||
*/ | ||
/** | ||
* [createElWithAttrs creates an element with a set of given attributes passed as the 2nd parameter, | ||
* then appends the new element to the target parent passed on the 1st parameter] | ||
* @param {[String]} appendTarget [description] | ||
* @param {[Object]} attributes [description] | ||
* @param {[String]} type [description] | ||
* @return {[Element]} [description] | ||
*/ | ||
function createElWithAttrs(appendTarget, attributes, type, textContent) { | ||
var el = void 0; | ||
if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object') { | ||
var fullNameSpace = type.nameSpace === 'svg' ? 'http://www.w3.org/2000/svg' : 'http://www.w3.org/1999/xhtml'; | ||
function createElWithAttrs(appendTarget, attributes, type, textContent) { | ||
var el; | ||
el = document.createElementNS(fullNameSpace, type.tagName || 'div'); | ||
} else { | ||
el = document.createElement(type || 'div'); | ||
} | ||
if (_typeof(type) === 'object') { | ||
var fullNameSpace = type.nameSpace === 'svg' ? 'http://www.w3.org/2000/svg' : 'http://www.w3.org/1999/xhtml'; | ||
el = document.createElementNS(fullNameSpace, type.tagName || 'div'); | ||
} else { | ||
el = document.createElement(type || 'div'); | ||
} | ||
for (var key in attributes) { | ||
el.setAttribute(key, attributes[key]); | ||
} | ||
for (var key in attributes) { | ||
el.setAttribute(key, attributes[key]); | ||
} | ||
if (textContent) { | ||
el.textContent = ''; | ||
if (textContent) { | ||
el.textContent = ''; | ||
el.insertAdjacentHTML('afterbegin', textContent); | ||
} | ||
el.insertAdjacentHTML('afterbegin', textContent); | ||
} | ||
if (appendTarget) { | ||
appendTarget.appendChild(el); | ||
} | ||
if (appendTarget) { | ||
appendTarget.appendChild(el); | ||
} | ||
return el; | ||
} | ||
/** | ||
* Runs a callback on the `elementSelector`. | ||
* @param {[type]} elementSelector [Query String, HTMLElement, or nodeList] | ||
* @param {Function} callback [callback to run with the matches elements.] | ||
*/ | ||
return el; | ||
} | ||
/** | ||
* Runs a callback on the `elementSelector`. | ||
* @param {[type]} elementSelector [Query String, HTMLElement, or nodeList] | ||
* @param {Function} callback [callback to run with the matches elements.] | ||
*/ | ||
function callbackOnElements(elementSelector, callback) { | ||
var elementList = void 0; | ||
function callbackOnElements(elementSelector, callback) { | ||
var elementList; | ||
if (elementSelector.length) { | ||
if (typeof elementSelector === 'string') { | ||
elementList = document.querySelectorAll(elementSelector); | ||
} else { | ||
elementList = elementSelector; | ||
} | ||
if (elementSelector.length) { | ||
if (typeof elementSelector === 'string') { | ||
elementList = document.querySelectorAll(elementSelector); | ||
} else { | ||
elementList = elementSelector; | ||
} | ||
[].forEach.call(elementList, callback.bind(this)); | ||
} else { | ||
callback.call(this, elementSelector); | ||
} | ||
[].forEach.call(elementList, callback.bind(this)); | ||
} else { | ||
callback.call(this, elementSelector); | ||
} | ||
} | ||
/** | ||
* Returns the matched parameter or null. | ||
* @param {[String]} name [Name of the parameter to lookup on the current URL] | ||
*/ | ||
/** | ||
* Returns the matched parameter or null. | ||
* @param {[String]} name [Name of the parameter to lookup on the current URL] | ||
*/ | ||
function getUrlParameter(name) { | ||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | ||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'), | ||
results = regex.exec(location.search); | ||
function getUrlParameter(name) { | ||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | ||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'), | ||
results = regex.exec(location.search); | ||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); | ||
} | ||
/** | ||
* Returns true if 'name' parameter or hash is found on the URL. | ||
*/ | ||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); | ||
} | ||
/** | ||
* Returns true if 'name' parameter or hash is found on the URL. | ||
*/ | ||
function hasURLParameter(name) { | ||
var regex = new RegExp('[?&]' + name); | ||
function hasURLParameter(name) { | ||
var regex = new RegExp('[?&]' + name); | ||
return '#' + name === window.location.hash || regex.test(window.location.search); | ||
} | ||
/** | ||
* Adds the specified getBoundingClientRect()[`property`] from each node found in `elements`. | ||
* @return {Integer} [description] | ||
*/ | ||
return '#' + name === window.location.hash || regex.test(window.location.search); | ||
} | ||
/** | ||
* Adds the specified getBoundingClientRect()[`property`] from each node found in `elements`. | ||
* @return {Integer} [description] | ||
*/ | ||
function getTotalRect(elements, property) { | ||
var totalOffsetHeight = 0; | ||
function getTotalRect(elements, property) { | ||
var totalOffsetHeight = 0; | ||
callbackOnElements(elements, function (currentEl) { | ||
totalOffsetHeight += currentEl.getBoundingClientRect()[property || 'height']; | ||
}); | ||
return totalOffsetHeight; | ||
} | ||
/** | ||
* Returns the target relative to the current window scroll position. | ||
* @param {HTMLElement | HTML Selector | Number} target [Target element(s) or position value to scroll to] | ||
* @param {HTMLElement | NodeList | HTML Selector | Number} offset [Offset element to calculate the height from, or offset value to substract] | ||
*/ | ||
callbackOnElements(elements, function (currentEl) { | ||
totalOffsetHeight += currentEl.getBoundingClientRect()[property || 'height']; | ||
}); | ||
return totalOffsetHeight; | ||
} | ||
function scrollToPosition(target) { | ||
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var scrollContainer = arguments.length > 2 ? arguments[2] : undefined; | ||
var documentHeight = scrollContainer ? scrollContainer.scrollHeight : Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight), | ||
documentScrollTop = scrollContainer ? scrollContainer.scrollTop : window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop, | ||
windowHeight = scrollContainer ? scrollContainer.offsetHeight : document.documentElement.clientHeight, | ||
totalOffset = typeof offset === 'number' ? offset : getTotalRect(offset), | ||
targetOffset = typeof target === 'number' ? target : getTotalRect(target, 'top') + documentScrollTop, | ||
targetOffsetToScroll = Math.round(documentHeight - targetOffset < windowHeight ? documentHeight - windowHeight : targetOffset); //Remove manual offset from target position. | ||
/** | ||
* Returns the target relative to the current window scroll position. | ||
* @param {HTMLElement | HTML Selector | Number} target [Target element(s) or position value to scroll to] | ||
* @param {HTMLElement | NodeList | HTML Selector | Number} offset [Offset element to calculate the height from, or offset value to substract] | ||
*/ | ||
function scrollToPosition(target) { | ||
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var scrollContainer = arguments[2]; | ||
targetOffsetToScroll -= totalOffset; | ||
return targetOffsetToScroll; | ||
} //Polyfill for the Object.assign method, which is not supported in IE11. | ||
// inspired by https://github.com/Raynos/xtend/blob/master/mutable.js | ||
var documentHeight = scrollContainer ? scrollContainer.scrollHeight : Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight), | ||
documentScrollTop = scrollContainer ? scrollContainer.scrollTop : window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop, | ||
windowHeight = scrollContainer ? scrollContainer.offsetHeight : document.documentElement.clientHeight, | ||
totalOffset = typeof offset === 'number' ? offset : getTotalRect(offset), | ||
targetOffset = typeof target === 'number' ? target : getTotalRect(target, 'top') + documentScrollTop, | ||
targetOffsetToScroll = Math.round(documentHeight - targetOffset < windowHeight ? documentHeight - windowHeight : targetOffset); | ||
//Remove manual offset from target position. | ||
targetOffsetToScroll -= totalOffset; | ||
function objectAssign(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
return targetOffsetToScroll; | ||
for (var key in source) { | ||
if (source.hasOwnProperty(key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
//Polyfill for the Object.assign method, which is not supported in IE11. | ||
// inspired by https://github.com/Raynos/xtend/blob/master/mutable.js | ||
function objectAssign(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
return target; | ||
} | ||
/** | ||
* [createCookie creates a cookie] | ||
* @param {[string]} name [cookie name] | ||
* @param {[string]} value [cookie description] | ||
* @param {[int]} days [amount of days the cookie must be alive for] | ||
*/ | ||
for (var key in source) { | ||
if (source.hasOwnProperty(key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
function createCookie(name, value, days, domain) { | ||
var expires; | ||
domain = domain ? ';domain=' + domain : ''; | ||
if (days) { | ||
var date = new Date(); | ||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); | ||
expires = '; expires=' + date.toGMTString(); | ||
} else { | ||
expires = ''; | ||
} | ||
/** | ||
* [createCookie creates a cookie] | ||
* @param {[string]} name [cookie name] | ||
* @param {[string]} value [cookie description] | ||
* @param {[int]} days [amount of days the cookie must be alive for] | ||
*/ | ||
function createCookie(name, value, days, domain) { | ||
var expires = void 0; | ||
document.cookie = name + '=' + value + expires + domain + '; path=/'; | ||
} | ||
/** | ||
* [readCookie tries to find a cookie with the provided name] | ||
* @param {[string]} name [cookie name] | ||
* @return {[string]} [string containing the searched cookie, if any] | ||
*/ | ||
domain = domain ? ';domain=' + domain : ''; | ||
if (days) { | ||
var date = new Date(); | ||
function readCookie(name) { | ||
var nameEQ = name + '=', | ||
cookieList = document.cookie.split(';'); | ||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); | ||
expires = '; expires=' + date.toGMTString(); | ||
} else { | ||
expires = ''; | ||
} | ||
for (var i = 0; i < cookieList.length; i++) { | ||
var currentCookie = cookieList[i]; | ||
document.cookie = name + '=' + value + expires + domain + '; path=/'; | ||
while (currentCookie.charAt(0) == ' ') { | ||
currentCookie = currentCookie.substring(1, currentCookie.length); | ||
} | ||
if (currentCookie.indexOf(nameEQ) === 0) { | ||
return currentCookie.substring(nameEQ.length, currentCookie.length); | ||
} | ||
} | ||
/** | ||
* [readCookie tries to find a cookie with the provided name] | ||
* @param {[string]} name [cookie name] | ||
* @return {[string]} [string containing the searched cookie, if any] | ||
*/ | ||
function readCookie(name) { | ||
var nameEQ = name + '=', | ||
cookieList = document.cookie.split(';'); | ||
return null; | ||
} | ||
/** | ||
* [eraseCookie] | ||
* @param {[string]} name [cookie name that needs to be erased] | ||
*/ | ||
for (var i = 0; i < cookieList.length; i++) { | ||
var currentCookie = cookieList[i]; | ||
while (currentCookie.charAt(0) == ' ') { | ||
currentCookie = currentCookie.substring(1, currentCookie.length); | ||
} | ||
function eraseCookie(name) { | ||
createCookie(name, '', -1); | ||
} | ||
if (currentCookie.indexOf(nameEQ) === 0) { | ||
return currentCookie.substring(nameEQ.length, currentCookie.length); | ||
} | ||
} | ||
var focusInterval; | ||
/** | ||
* Attemps to add focus to a `focusTarget` until it is able to. | ||
*/ | ||
return null; | ||
} | ||
function forceFocus(focusTarget) { | ||
focusTarget.focus(); | ||
window.clearInterval(focusInterval); | ||
focusInterval = window.setInterval(function () { | ||
if (focusTarget.matches(':focus')) { | ||
window.clearInterval(focusInterval); | ||
} else { | ||
focusTarget.focus(); | ||
} | ||
}, 25); | ||
} | ||
/** | ||
* Traps keyboard focus in a designated `containerEl`. | ||
*/ | ||
/** | ||
* [eraseCookie] | ||
* @param {[string]} name [cookie name that needs to be erased] | ||
*/ | ||
function eraseCookie(name) { | ||
createCookie(name, '', -1); | ||
} | ||
var focusInterval = void 0; | ||
function focusTrap(containerEl) { | ||
var focusableEls = {}; | ||
if (!containerEl.dataset.focustrapEnabled) { | ||
containerEl.dataset.focustrapEnabled = true; | ||
containerEl.addEventListener('focusin', _focusinHandler); | ||
containerEl.addEventListener('keydown', _tabbingHandler); | ||
} | ||
/** | ||
* Attemps to add focus to a `focusTarget` until it is able to. | ||
* Updates the "focusable" element values whenever a child of `containerEl` recives focus. | ||
*/ | ||
function forceFocus(focusTarget) { | ||
focusTarget.focus(); | ||
window.clearInterval(focusInterval); | ||
focusInterval = window.setInterval(function () { | ||
if (focusTarget.matches(':focus')) { | ||
window.clearInterval(focusInterval); | ||
} else { | ||
focusTarget.focus(); | ||
} | ||
}, 25); | ||
function _focusinHandler(evt) { | ||
//Refresh the focusable elements list whenever something gains focus. | ||
//This ensures the list is up to date in case the contents of the `containerEl` change. | ||
focusableEls.list = this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])'); | ||
focusableEls.first = focusableEls.list[0]; | ||
focusableEls.last = focusableEls.list[focusableEls.list.length - 1]; | ||
focusableEls.loopTo = null; //Set the `focusableEls.loopTo` value depending on the currently focused element. | ||
//`focusableEls.loopTo` will be equal to the `focusableEls.first` whenever the `focusableEls.last` receives focus, and viceversa. | ||
if (evt.target === focusableEls.last) { | ||
focusableEls.loopTo = focusableEls.first; | ||
} else if (evt.target === focusableEls.first) { | ||
focusableEls.loopTo = focusableEls.last; | ||
} | ||
} | ||
/** | ||
* Traps keyboard focus in a designated `containerEl`. | ||
* Listens to the keyboard Tab press and shifts focus to the first/last focusable element. | ||
*/ | ||
function focusTrap(containerEl) { | ||
var focusableEls = {}; | ||
if (!containerEl.dataset.focustrapEnabled) { | ||
containerEl.dataset.focustrapEnabled = true; | ||
containerEl.addEventListener('focusin', _focusinHandler); | ||
containerEl.addEventListener('keydown', _tabbingHandler); | ||
} | ||
/** | ||
* Updates the "focusable" element values whenever a child of `containerEl` recives focus. | ||
*/ | ||
function _focusinHandler(evt) { | ||
//Refresh the focusable elements list whenever something gains focus. | ||
//This ensures the list is up to date in case the contents of the `containerEl` change. | ||
focusableEls.list = this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])'); | ||
function _tabbingHandler(evt) { | ||
var loopToFirstEl = focusableEls.loopTo === focusableEls.first && !evt.shiftKey, | ||
loopToLastEl = focusableEls.loopTo === focusableEls.last && evt.shiftKey; | ||
focusableEls.first = focusableEls.list[0]; | ||
focusableEls.last = focusableEls.list[focusableEls.list.length - 1]; | ||
focusableEls.loopTo = null; | ||
//Set the `focusableEls.loopTo` value depending on the currently focused element. | ||
//`focusableEls.loopTo` will be equal to the `focusableEls.first` whenever the `focusableEls.last` receives focus, and viceversa. | ||
if (evt.target === focusableEls.last) { | ||
focusableEls.loopTo = focusableEls.first; | ||
} else if (evt.target === focusableEls.first) { | ||
focusableEls.loopTo = focusableEls.last; | ||
} | ||
} | ||
/** | ||
* Listens to the keyboard Tab press and shifts focus to the first/last focusable element. | ||
*/ | ||
function _tabbingHandler(evt) { | ||
var loopToFirstEl = focusableEls.loopTo === focusableEls.first && !evt.shiftKey, | ||
loopToLastEl = focusableEls.loopTo === focusableEls.last && evt.shiftKey; | ||
if (evt.keyCode === 9 && focusableEls.loopTo && (loopToFirstEl || loopToLastEl)) { | ||
evt.preventDefault(); | ||
focusableEls.loopTo.focus(); | ||
} | ||
} | ||
if (evt.keyCode === 9 && focusableEls.loopTo && (loopToFirstEl || loopToLastEl)) { | ||
evt.preventDefault(); | ||
focusableEls.loopTo.focus(); | ||
} | ||
} | ||
} | ||
/** | ||
* Parses and executes any scripts found within the provided `containerEl` element. | ||
* @param {HTMLElement} containerEl [description] | ||
*/ | ||
/** | ||
* Parses and executes any scripts found within the provided `containerEl` element. | ||
* @param {HTMLElement} containerEl [description] | ||
*/ | ||
function parseScripts(containerEl) { | ||
[].forEach.call(containerEl.querySelectorAll('script'), function (oldScript) { | ||
var newScript = document.createElement('script'); | ||
Array.from(oldScript.attributes).forEach(function (attr) { | ||
return newScript.setAttribute(attr.name, attr.value); | ||
}); | ||
newScript.appendChild(document.createTextNode(oldScript.innerHTML)); | ||
oldScript.parentNode.replaceChild(newScript, oldScript); | ||
}); | ||
} | ||
function parseScripts(containerEl) { | ||
[].forEach.call(containerEl.querySelectorAll('script'), function (oldScript) { | ||
var newScript = document.createElement('script'); | ||
Array.from(oldScript.attributes).forEach(function (attr) { | ||
return newScript.setAttribute(attr.name, attr.value); | ||
}); | ||
newScript.appendChild(document.createTextNode(oldScript.innerHTML)); | ||
oldScript.parentNode.replaceChild(newScript, oldScript); | ||
}); | ||
} | ||
}); |
@@ -1,1 +0,1 @@ | ||
define(["exports"],function(exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isRTL=isRTL;exports.whichTransition=whichTransition;exports.createElWithAttrs=createElWithAttrs;exports.callbackOnElements=callbackOnElements;exports.getUrlParameter=getUrlParameter;exports.hasURLParameter=hasURLParameter;exports.getTotalRect=getTotalRect;exports.scrollToPosition=scrollToPosition;exports.objectAssign=objectAssign;exports.createCookie=createCookie;exports.readCookie=readCookie;exports.eraseCookie=eraseCookie;exports.forceFocus=forceFocus;exports.focusTrap=focusTrap;exports.parseScripts=parseScripts;var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};(function(){if(!Element.prototype.matches){Element.prototype.matches=Element.prototype.msMatchesSelector}if(!Element.prototype.closest){Element.prototype.closest=_getClosest}})();function _getClosest(selector){var currentEl=this;while(currentEl.constructor!==HTMLHtmlElement){if(currentEl.parentNode.matches(selector)){return currentEl.parentNode}else if(currentEl.matches(selector)){return currentEl}currentEl=currentEl.parentNode}return false}var isMobile=exports.isMobile={Android:function Android(){return navigator.userAgent.match(/Android/i)},BlackBerry:function BlackBerry(){return navigator.userAgent.match(/BlackBerry/i)},iOS:function iOS(){return navigator.userAgent.match(/iPhone|iPad|iPod/i)},Opera:function Opera(){return navigator.userAgent.match(/Opera Mini/i)},Windows:function Windows(){return navigator.userAgent.match(/IEMobile/i)||navigator.userAgent.match(/WPDesktop/i)},any:function any(){return isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows()}};function isRTL(){return document.documentElement.getAttribute("dir")==="rtl"?true:false}function whichTransition(){var dummyEl=document.createElement("dummy"),transitions={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var key in transitions){if(dummyEl.style[key]!==undefined){return transitions[key]}}}function createElWithAttrs(appendTarget,attributes,type,textContent){var el=void 0;if((typeof type==="undefined"?"undefined":_typeof(type))==="object"){var fullNameSpace=type.nameSpace==="svg"?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml";el=document.createElementNS(fullNameSpace,type.tagName||"div")}else{el=document.createElement(type||"div")}for(var key in attributes){el.setAttribute(key,attributes[key])}if(textContent){el.textContent="";el.insertAdjacentHTML("afterbegin",textContent)}if(appendTarget){appendTarget.appendChild(el)}return el}function callbackOnElements(elementSelector,callback){var elementList=void 0;if(elementSelector.length){if(typeof elementSelector==="string"){elementList=document.querySelectorAll(elementSelector)}else{elementList=elementSelector}[].forEach.call(elementList,callback.bind(this))}else{callback.call(this,elementSelector)}}function getUrlParameter(name){name=name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var regex=new RegExp("[\\?&]"+name+"=([^&#]*)"),results=regex.exec(location.search);return results===null?"":decodeURIComponent(results[1].replace(/\+/g," "))}function hasURLParameter(name){var regex=new RegExp("[?&]"+name);return"#"+name===window.location.hash||regex.test(window.location.search)}function getTotalRect(elements,property){var totalOffsetHeight=0;callbackOnElements(elements,function(currentEl){totalOffsetHeight+=currentEl.getBoundingClientRect()[property||"height"]});return totalOffsetHeight}function scrollToPosition(target){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var scrollContainer=arguments[2];var documentHeight=scrollContainer?scrollContainer.scrollHeight:Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight),documentScrollTop=scrollContainer?scrollContainer.scrollTop:window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop,windowHeight=scrollContainer?scrollContainer.offsetHeight:document.documentElement.clientHeight,totalOffset=typeof offset==="number"?offset:getTotalRect(offset),targetOffset=typeof target==="number"?target:getTotalRect(target,"top")+documentScrollTop,targetOffsetToScroll=Math.round(documentHeight-targetOffset<windowHeight?documentHeight-windowHeight:targetOffset);targetOffsetToScroll-=totalOffset;return targetOffsetToScroll}function objectAssign(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(source.hasOwnProperty(key)){target[key]=source[key]}}}return target}function createCookie(name,value,days,domain){var expires=void 0;domain=domain?";domain="+domain:"";if(days){var date=new Date;date.setTime(date.getTime()+days*24*60*60*1e3);expires="; expires="+date.toGMTString()}else{expires=""}document.cookie=name+"="+value+expires+domain+"; path=/"}function readCookie(name){var nameEQ=name+"=",cookieList=document.cookie.split(";");for(var i=0;i<cookieList.length;i++){var currentCookie=cookieList[i];while(currentCookie.charAt(0)==" "){currentCookie=currentCookie.substring(1,currentCookie.length)}if(currentCookie.indexOf(nameEQ)===0){return currentCookie.substring(nameEQ.length,currentCookie.length)}}return null}function eraseCookie(name){createCookie(name,"",-1)}var focusInterval=void 0;function forceFocus(focusTarget){focusTarget.focus();window.clearInterval(focusInterval);focusInterval=window.setInterval(function(){if(focusTarget.matches(":focus")){window.clearInterval(focusInterval)}else{focusTarget.focus()}},25)}function focusTrap(containerEl){var focusableEls={};if(!containerEl.dataset.focustrapEnabled){containerEl.dataset.focustrapEnabled=true;containerEl.addEventListener("focusin",_focusinHandler);containerEl.addEventListener("keydown",_tabbingHandler)}function _focusinHandler(evt){focusableEls.list=this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');focusableEls.first=focusableEls.list[0];focusableEls.last=focusableEls.list[focusableEls.list.length-1];focusableEls.loopTo=null;if(evt.target===focusableEls.last){focusableEls.loopTo=focusableEls.first}else if(evt.target===focusableEls.first){focusableEls.loopTo=focusableEls.last}}function _tabbingHandler(evt){var loopToFirstEl=focusableEls.loopTo===focusableEls.first&&!evt.shiftKey,loopToLastEl=focusableEls.loopTo===focusableEls.last&&evt.shiftKey;if(evt.keyCode===9&&focusableEls.loopTo&&(loopToFirstEl||loopToLastEl)){evt.preventDefault();focusableEls.loopTo.focus()}}}function parseScripts(containerEl){[].forEach.call(containerEl.querySelectorAll("script"),function(oldScript){var newScript=document.createElement("script");Array.from(oldScript.attributes).forEach(function(attr){return newScript.setAttribute(attr.name,attr.value)});newScript.appendChild(document.createTextNode(oldScript.innerHTML));oldScript.parentNode.replaceChild(newScript,oldScript)})}}); | ||
define(["exports"],function(_exports){"use strict";Object.defineProperty(_exports,"__esModule",{value:true});_exports.isRTL=isRTL;_exports.whichTransition=whichTransition;_exports.createElWithAttrs=createElWithAttrs;_exports.callbackOnElements=callbackOnElements;_exports.getUrlParameter=getUrlParameter;_exports.hasURLParameter=hasURLParameter;_exports.getTotalRect=getTotalRect;_exports.scrollToPosition=scrollToPosition;_exports.objectAssign=objectAssign;_exports.createCookie=createCookie;_exports.readCookie=readCookie;_exports.eraseCookie=eraseCookie;_exports.forceFocus=forceFocus;_exports.focusTrap=focusTrap;_exports.parseScripts=parseScripts;_exports.isMobile=void 0;function _typeof(obj){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj}}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj}}return _typeof(obj)}(function(){if(!Element.prototype.matches){Element.prototype.matches=Element.prototype.msMatchesSelector}if(!Element.prototype.closest){Element.prototype.closest=_getClosest}})();function _getClosest(selector){var currentEl=this;while(currentEl.constructor!==HTMLHtmlElement){if(currentEl.parentNode.matches(selector)){return currentEl.parentNode}else if(currentEl.matches(selector)){return currentEl}currentEl=currentEl.parentNode}return false}var isMobile={Android:function Android(){return navigator.userAgent.match(/Android/i)},BlackBerry:function BlackBerry(){return navigator.userAgent.match(/BlackBerry/i)},iOS:function iOS(){return navigator.userAgent.match(/iPhone|iPad|iPod/i)},Opera:function Opera(){return navigator.userAgent.match(/Opera Mini/i)},Windows:function Windows(){return navigator.userAgent.match(/IEMobile/i)||navigator.userAgent.match(/WPDesktop/i)},any:function any(){return isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows()}};_exports.isMobile=isMobile;function isRTL(){return document.documentElement.getAttribute("dir")==="rtl"?true:false}function whichTransition(){var dummyEl=document.createElement("dummy"),transitions={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var key in transitions){if(dummyEl.style[key]!==undefined){return transitions[key]}}}function createElWithAttrs(appendTarget,attributes,type,textContent){var el;if(_typeof(type)==="object"){var fullNameSpace=type.nameSpace==="svg"?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml";el=document.createElementNS(fullNameSpace,type.tagName||"div")}else{el=document.createElement(type||"div")}for(var key in attributes){el.setAttribute(key,attributes[key])}if(textContent){el.textContent="";el.insertAdjacentHTML("afterbegin",textContent)}if(appendTarget){appendTarget.appendChild(el)}return el}function callbackOnElements(elementSelector,callback){var elementList;if(elementSelector.length){if(typeof elementSelector==="string"){elementList=document.querySelectorAll(elementSelector)}else{elementList=elementSelector}[].forEach.call(elementList,callback.bind(this))}else{callback.call(this,elementSelector)}}function getUrlParameter(name){name=name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var regex=new RegExp("[\\?&]"+name+"=([^&#]*)"),results=regex.exec(location.search);return results===null?"":decodeURIComponent(results[1].replace(/\+/g," "))}function hasURLParameter(name){var regex=new RegExp("[?&]"+name);return"#"+name===window.location.hash||regex.test(window.location.search)}function getTotalRect(elements,property){var totalOffsetHeight=0;callbackOnElements(elements,function(currentEl){totalOffsetHeight+=currentEl.getBoundingClientRect()[property||"height"]});return totalOffsetHeight}function scrollToPosition(target){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var scrollContainer=arguments.length>2?arguments[2]:undefined;var documentHeight=scrollContainer?scrollContainer.scrollHeight:Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight),documentScrollTop=scrollContainer?scrollContainer.scrollTop:window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop,windowHeight=scrollContainer?scrollContainer.offsetHeight:document.documentElement.clientHeight,totalOffset=typeof offset==="number"?offset:getTotalRect(offset),targetOffset=typeof target==="number"?target:getTotalRect(target,"top")+documentScrollTop,targetOffsetToScroll=Math.round(documentHeight-targetOffset<windowHeight?documentHeight-windowHeight:targetOffset);targetOffsetToScroll-=totalOffset;return targetOffsetToScroll}function objectAssign(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(source.hasOwnProperty(key)){target[key]=source[key]}}}return target}function createCookie(name,value,days,domain){var expires;domain=domain?";domain="+domain:"";if(days){var date=new Date;date.setTime(date.getTime()+days*24*60*60*1e3);expires="; expires="+date.toGMTString()}else{expires=""}document.cookie=name+"="+value+expires+domain+"; path=/"}function readCookie(name){var nameEQ=name+"=",cookieList=document.cookie.split(";");for(var i=0;i<cookieList.length;i++){var currentCookie=cookieList[i];while(currentCookie.charAt(0)==" "){currentCookie=currentCookie.substring(1,currentCookie.length)}if(currentCookie.indexOf(nameEQ)===0){return currentCookie.substring(nameEQ.length,currentCookie.length)}}return null}function eraseCookie(name){createCookie(name,"",-1)}var focusInterval;function forceFocus(focusTarget){focusTarget.focus();window.clearInterval(focusInterval);focusInterval=window.setInterval(function(){if(focusTarget.matches(":focus")){window.clearInterval(focusInterval)}else{focusTarget.focus()}},25)}function focusTrap(containerEl){var focusableEls={};if(!containerEl.dataset.focustrapEnabled){containerEl.dataset.focustrapEnabled=true;containerEl.addEventListener("focusin",_focusinHandler);containerEl.addEventListener("keydown",_tabbingHandler)}function _focusinHandler(evt){focusableEls.list=this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');focusableEls.first=focusableEls.list[0];focusableEls.last=focusableEls.list[focusableEls.list.length-1];focusableEls.loopTo=null;if(evt.target===focusableEls.last){focusableEls.loopTo=focusableEls.first}else if(evt.target===focusableEls.first){focusableEls.loopTo=focusableEls.last}}function _tabbingHandler(evt){var loopToFirstEl=focusableEls.loopTo===focusableEls.first&&!evt.shiftKey,loopToLastEl=focusableEls.loopTo===focusableEls.last&&evt.shiftKey;if(evt.keyCode===9&&focusableEls.loopTo&&(loopToFirstEl||loopToLastEl)){evt.preventDefault();focusableEls.loopTo.focus()}}}function parseScripts(containerEl){[].forEach.call(containerEl.querySelectorAll("script"),function(oldScript){var newScript=document.createElement("script");Array.from(oldScript.attributes).forEach(function(attr){return newScript.setAttribute(attr.name,attr.value)});newScript.appendChild(document.createTextNode(oldScript.innerHTML));oldScript.parentNode.replaceChild(newScript,oldScript)})}}); |
@@ -1,9 +0,6 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
exports.isRTL = isRTL; | ||
@@ -24,2 +21,6 @@ exports.whichTransition = whichTransition; | ||
exports.parseScripts = parseScripts; | ||
exports.isMobile = void 0; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
/** | ||
@@ -34,32 +35,28 @@ * [Utilities]: methods and objects that contain reusable functionality and can be called on demand. | ||
(function () { | ||
//Element.matches() | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = Element.prototype.msMatchesSelector; | ||
} | ||
//Element.matches() | ||
if (!Element.prototype.matches) { | ||
Element.prototype.matches = Element.prototype.msMatchesSelector; | ||
} //Element.closest() | ||
//Element.closest() | ||
if (!Element.prototype.closest) { | ||
Element.prototype.closest = _getClosest; | ||
} | ||
if (!Element.prototype.closest) { | ||
Element.prototype.closest = _getClosest; | ||
} | ||
})(); | ||
function _getClosest(selector) { | ||
var currentEl = this; | ||
var currentEl = this; | ||
while (currentEl.constructor !== HTMLHtmlElement) { | ||
if (currentEl.parentNode.matches(selector)) { | ||
return currentEl.parentNode; | ||
} else if (currentEl.matches(selector)) { | ||
return currentEl; | ||
} | ||
while (currentEl.constructor !== HTMLHtmlElement) { | ||
if (currentEl.parentNode.matches(selector)) { | ||
currentEl = currentEl.parentNode; | ||
} | ||
return currentEl.parentNode; | ||
} else if (currentEl.matches(selector)) { | ||
return currentEl; | ||
} | ||
currentEl = currentEl.parentNode; | ||
} | ||
return false; | ||
return false; | ||
} | ||
/** | ||
@@ -69,23 +66,24 @@ * Returns true if current browser "is mobile" | ||
*/ | ||
var isMobile = exports.isMobile = { | ||
Android: function Android() { | ||
return navigator.userAgent.match(/Android/i); | ||
}, | ||
BlackBerry: function BlackBerry() { | ||
return navigator.userAgent.match(/BlackBerry/i); | ||
}, | ||
iOS: function iOS() { | ||
return navigator.userAgent.match(/iPhone|iPad|iPod/i); | ||
}, | ||
Opera: function Opera() { | ||
return navigator.userAgent.match(/Opera Mini/i); | ||
}, | ||
Windows: function Windows() { | ||
return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i); | ||
}, | ||
any: function any() { | ||
return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows(); | ||
} | ||
var isMobile = { | ||
Android: function Android() { | ||
return navigator.userAgent.match(/Android/i); | ||
}, | ||
BlackBerry: function BlackBerry() { | ||
return navigator.userAgent.match(/BlackBerry/i); | ||
}, | ||
iOS: function iOS() { | ||
return navigator.userAgent.match(/iPhone|iPad|iPod/i); | ||
}, | ||
Opera: function Opera() { | ||
return navigator.userAgent.match(/Opera Mini/i); | ||
}, | ||
Windows: function Windows() { | ||
return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i); | ||
}, | ||
any: function any() { | ||
return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows(); | ||
} | ||
}; | ||
/** | ||
@@ -95,25 +93,29 @@ * Returns true if the document element <html> has its dir attribute set to rtl (dir="rtl") | ||
*/ | ||
exports.isMobile = isMobile; | ||
function isRTL() { | ||
return document.documentElement.getAttribute('dir') === 'rtl' ? true : false; | ||
}; | ||
return document.documentElement.getAttribute('dir') === 'rtl' ? true : false; | ||
} | ||
; | ||
/** | ||
* [Returns the transition event type supported by the browser] | ||
*/ | ||
function whichTransition() { | ||
var dummyEl = document.createElement('dummy'), | ||
transitions = { | ||
'transition': 'transitionend', | ||
'OTransition': 'oTransitionEnd', | ||
'MozTransition': 'transitionend', | ||
'WebkitTransition': 'webkitTransitionEnd' | ||
}; | ||
var dummyEl = document.createElement('dummy'), | ||
transitions = { | ||
'transition': 'transitionend', | ||
'OTransition': 'oTransitionEnd', | ||
'MozTransition': 'transitionend', | ||
'WebkitTransition': 'webkitTransitionEnd' | ||
}; | ||
for (var key in transitions) { | ||
if (dummyEl.style[key] !== undefined) { | ||
return transitions[key]; | ||
} | ||
for (var key in transitions) { | ||
if (dummyEl.style[key] !== undefined) { | ||
return transitions[key]; | ||
} | ||
} | ||
} | ||
/** | ||
@@ -127,30 +129,29 @@ * [createElWithAttrs creates an element with a set of given attributes passed as the 2nd parameter, | ||
*/ | ||
function createElWithAttrs(appendTarget, attributes, type, textContent) { | ||
var el = void 0; | ||
if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object') { | ||
var fullNameSpace = type.nameSpace === 'svg' ? 'http://www.w3.org/2000/svg' : 'http://www.w3.org/1999/xhtml'; | ||
el = document.createElementNS(fullNameSpace, type.tagName || 'div'); | ||
} else { | ||
el = document.createElement(type || 'div'); | ||
} | ||
function createElWithAttrs(appendTarget, attributes, type, textContent) { | ||
var el; | ||
for (var key in attributes) { | ||
el.setAttribute(key, attributes[key]); | ||
} | ||
if (_typeof(type) === 'object') { | ||
var fullNameSpace = type.nameSpace === 'svg' ? 'http://www.w3.org/2000/svg' : 'http://www.w3.org/1999/xhtml'; | ||
el = document.createElementNS(fullNameSpace, type.tagName || 'div'); | ||
} else { | ||
el = document.createElement(type || 'div'); | ||
} | ||
if (textContent) { | ||
el.textContent = ''; | ||
for (var key in attributes) { | ||
el.setAttribute(key, attributes[key]); | ||
} | ||
el.insertAdjacentHTML('afterbegin', textContent); | ||
} | ||
if (textContent) { | ||
el.textContent = ''; | ||
el.insertAdjacentHTML('afterbegin', textContent); | ||
} | ||
if (appendTarget) { | ||
appendTarget.appendChild(el); | ||
} | ||
if (appendTarget) { | ||
appendTarget.appendChild(el); | ||
} | ||
return el; | ||
return el; | ||
} | ||
/** | ||
@@ -161,18 +162,19 @@ * Runs a callback on the `elementSelector`. | ||
*/ | ||
function callbackOnElements(elementSelector, callback) { | ||
var elementList = void 0; | ||
var elementList; | ||
if (elementSelector.length) { | ||
if (typeof elementSelector === 'string') { | ||
elementList = document.querySelectorAll(elementSelector); | ||
} else { | ||
elementList = elementSelector; | ||
} | ||
[].forEach.call(elementList, callback.bind(this)); | ||
if (elementSelector.length) { | ||
if (typeof elementSelector === 'string') { | ||
elementList = document.querySelectorAll(elementSelector); | ||
} else { | ||
callback.call(this, elementSelector); | ||
elementList = elementSelector; | ||
} | ||
[].forEach.call(elementList, callback.bind(this)); | ||
} else { | ||
callback.call(this, elementSelector); | ||
} | ||
} | ||
/** | ||
@@ -182,20 +184,19 @@ * Returns the matched parameter or null. | ||
*/ | ||
function getUrlParameter(name) { | ||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | ||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'), | ||
results = regex.exec(location.search); | ||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); | ||
function getUrlParameter(name) { | ||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | ||
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'), | ||
results = regex.exec(location.search); | ||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); | ||
} | ||
/** | ||
* Returns true if 'name' parameter or hash is found on the URL. | ||
*/ | ||
function hasURLParameter(name) { | ||
var regex = new RegExp('[?&]' + name); | ||
return '#' + name === window.location.hash || regex.test(window.location.search); | ||
var regex = new RegExp('[?&]' + name); | ||
return '#' + name === window.location.hash || regex.test(window.location.search); | ||
} | ||
/** | ||
@@ -205,12 +206,11 @@ * Adds the specified getBoundingClientRect()[`property`] from each node found in `elements`. | ||
*/ | ||
function getTotalRect(elements, property) { | ||
var totalOffsetHeight = 0; | ||
callbackOnElements(elements, function (currentEl) { | ||
totalOffsetHeight += currentEl.getBoundingClientRect()[property || 'height']; | ||
}); | ||
return totalOffsetHeight; | ||
function getTotalRect(elements, property) { | ||
var totalOffsetHeight = 0; | ||
callbackOnElements(elements, function (currentEl) { | ||
totalOffsetHeight += currentEl.getBoundingClientRect()[property || 'height']; | ||
}); | ||
return totalOffsetHeight; | ||
} | ||
/** | ||
@@ -221,35 +221,33 @@ * Returns the target relative to the current window scroll position. | ||
*/ | ||
function scrollToPosition(target) { | ||
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var scrollContainer = arguments[2]; | ||
var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var scrollContainer = arguments.length > 2 ? arguments[2] : undefined; | ||
var documentHeight = scrollContainer ? scrollContainer.scrollHeight : Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight), | ||
documentScrollTop = scrollContainer ? scrollContainer.scrollTop : window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop, | ||
windowHeight = scrollContainer ? scrollContainer.offsetHeight : document.documentElement.clientHeight, | ||
totalOffset = typeof offset === 'number' ? offset : getTotalRect(offset), | ||
targetOffset = typeof target === 'number' ? target : getTotalRect(target, 'top') + documentScrollTop, | ||
targetOffsetToScroll = Math.round(documentHeight - targetOffset < windowHeight ? documentHeight - windowHeight : targetOffset); //Remove manual offset from target position. | ||
var documentHeight = scrollContainer ? scrollContainer.scrollHeight : Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight), | ||
documentScrollTop = scrollContainer ? scrollContainer.scrollTop : window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop, | ||
windowHeight = scrollContainer ? scrollContainer.offsetHeight : document.documentElement.clientHeight, | ||
totalOffset = typeof offset === 'number' ? offset : getTotalRect(offset), | ||
targetOffset = typeof target === 'number' ? target : getTotalRect(target, 'top') + documentScrollTop, | ||
targetOffsetToScroll = Math.round(documentHeight - targetOffset < windowHeight ? documentHeight - windowHeight : targetOffset); | ||
targetOffsetToScroll -= totalOffset; | ||
return targetOffsetToScroll; | ||
} //Polyfill for the Object.assign method, which is not supported in IE11. | ||
// inspired by https://github.com/Raynos/xtend/blob/master/mutable.js | ||
//Remove manual offset from target position. | ||
targetOffsetToScroll -= totalOffset; | ||
return targetOffsetToScroll; | ||
} | ||
//Polyfill for the Object.assign method, which is not supported in IE11. | ||
// inspired by https://github.com/Raynos/xtend/blob/master/mutable.js | ||
function objectAssign(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (source.hasOwnProperty(key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
for (var key in source) { | ||
if (source.hasOwnProperty(key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
return target; | ||
} | ||
/** | ||
@@ -261,19 +259,18 @@ * [createCookie creates a cookie] | ||
*/ | ||
function createCookie(name, value, days, domain) { | ||
var expires = void 0; | ||
domain = domain ? ';domain=' + domain : ''; | ||
if (days) { | ||
var date = new Date(); | ||
function createCookie(name, value, days, domain) { | ||
var expires; | ||
domain = domain ? ';domain=' + domain : ''; | ||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); | ||
expires = '; expires=' + date.toGMTString(); | ||
} else { | ||
expires = ''; | ||
} | ||
if (days) { | ||
var date = new Date(); | ||
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); | ||
expires = '; expires=' + date.toGMTString(); | ||
} else { | ||
expires = ''; | ||
} | ||
document.cookie = name + '=' + value + expires + domain + '; path=/'; | ||
document.cookie = name + '=' + value + expires + domain + '; path=/'; | ||
} | ||
/** | ||
@@ -284,21 +281,22 @@ * [readCookie tries to find a cookie with the provided name] | ||
*/ | ||
function readCookie(name) { | ||
var nameEQ = name + '=', | ||
cookieList = document.cookie.split(';'); | ||
var nameEQ = name + '=', | ||
cookieList = document.cookie.split(';'); | ||
for (var i = 0; i < cookieList.length; i++) { | ||
var currentCookie = cookieList[i]; | ||
for (var i = 0; i < cookieList.length; i++) { | ||
var currentCookie = cookieList[i]; | ||
while (currentCookie.charAt(0) == ' ') { | ||
currentCookie = currentCookie.substring(1, currentCookie.length); | ||
} | ||
while (currentCookie.charAt(0) == ' ') { | ||
currentCookie = currentCookie.substring(1, currentCookie.length); | ||
} | ||
if (currentCookie.indexOf(nameEQ) === 0) { | ||
return currentCookie.substring(nameEQ.length, currentCookie.length); | ||
} | ||
if (currentCookie.indexOf(nameEQ) === 0) { | ||
return currentCookie.substring(nameEQ.length, currentCookie.length); | ||
} | ||
} | ||
return null; | ||
return null; | ||
} | ||
/** | ||
@@ -308,73 +306,72 @@ * [eraseCookie] | ||
*/ | ||
function eraseCookie(name) { | ||
createCookie(name, '', -1); | ||
createCookie(name, '', -1); | ||
} | ||
var focusInterval = void 0; | ||
var focusInterval; | ||
/** | ||
* Attemps to add focus to a `focusTarget` until it is able to. | ||
*/ | ||
function forceFocus(focusTarget) { | ||
focusTarget.focus(); | ||
window.clearInterval(focusInterval); | ||
focusInterval = window.setInterval(function () { | ||
if (focusTarget.matches(':focus')) { | ||
window.clearInterval(focusInterval); | ||
} else { | ||
focusTarget.focus(); | ||
} | ||
}, 25); | ||
focusTarget.focus(); | ||
window.clearInterval(focusInterval); | ||
focusInterval = window.setInterval(function () { | ||
if (focusTarget.matches(':focus')) { | ||
window.clearInterval(focusInterval); | ||
} else { | ||
focusTarget.focus(); | ||
} | ||
}, 25); | ||
} | ||
/** | ||
* Traps keyboard focus in a designated `containerEl`. | ||
*/ | ||
function focusTrap(containerEl) { | ||
var focusableEls = {}; | ||
var focusableEls = {}; | ||
if (!containerEl.dataset.focustrapEnabled) { | ||
containerEl.dataset.focustrapEnabled = true; | ||
containerEl.addEventListener('focusin', _focusinHandler); | ||
containerEl.addEventListener('keydown', _tabbingHandler); | ||
} | ||
if (!containerEl.dataset.focustrapEnabled) { | ||
containerEl.dataset.focustrapEnabled = true; | ||
containerEl.addEventListener('focusin', _focusinHandler); | ||
containerEl.addEventListener('keydown', _tabbingHandler); | ||
} | ||
/** | ||
* Updates the "focusable" element values whenever a child of `containerEl` recives focus. | ||
*/ | ||
/** | ||
* Updates the "focusable" element values whenever a child of `containerEl` recives focus. | ||
*/ | ||
function _focusinHandler(evt) { | ||
//Refresh the focusable elements list whenever something gains focus. | ||
//This ensures the list is up to date in case the contents of the `containerEl` change. | ||
focusableEls.list = this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])'); | ||
focusableEls.first = focusableEls.list[0]; | ||
focusableEls.last = focusableEls.list[focusableEls.list.length - 1]; | ||
function _focusinHandler(evt) { | ||
//Refresh the focusable elements list whenever something gains focus. | ||
//This ensures the list is up to date in case the contents of the `containerEl` change. | ||
focusableEls.list = this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])'); | ||
focusableEls.first = focusableEls.list[0]; | ||
focusableEls.last = focusableEls.list[focusableEls.list.length - 1]; | ||
focusableEls.loopTo = null; //Set the `focusableEls.loopTo` value depending on the currently focused element. | ||
//`focusableEls.loopTo` will be equal to the `focusableEls.first` whenever the `focusableEls.last` receives focus, and viceversa. | ||
focusableEls.loopTo = null; | ||
//Set the `focusableEls.loopTo` value depending on the currently focused element. | ||
//`focusableEls.loopTo` will be equal to the `focusableEls.first` whenever the `focusableEls.last` receives focus, and viceversa. | ||
if (evt.target === focusableEls.last) { | ||
focusableEls.loopTo = focusableEls.first; | ||
} else if (evt.target === focusableEls.first) { | ||
focusableEls.loopTo = focusableEls.last; | ||
} | ||
if (evt.target === focusableEls.last) { | ||
focusableEls.loopTo = focusableEls.first; | ||
} else if (evt.target === focusableEls.first) { | ||
focusableEls.loopTo = focusableEls.last; | ||
} | ||
} | ||
/** | ||
* Listens to the keyboard Tab press and shifts focus to the first/last focusable element. | ||
*/ | ||
/** | ||
* Listens to the keyboard Tab press and shifts focus to the first/last focusable element. | ||
*/ | ||
function _tabbingHandler(evt) { | ||
var loopToFirstEl = focusableEls.loopTo === focusableEls.first && !evt.shiftKey, | ||
loopToLastEl = focusableEls.loopTo === focusableEls.last && evt.shiftKey; | ||
if (evt.keyCode === 9 && focusableEls.loopTo && (loopToFirstEl || loopToLastEl)) { | ||
evt.preventDefault(); | ||
focusableEls.loopTo.focus(); | ||
} | ||
function _tabbingHandler(evt) { | ||
var loopToFirstEl = focusableEls.loopTo === focusableEls.first && !evt.shiftKey, | ||
loopToLastEl = focusableEls.loopTo === focusableEls.last && evt.shiftKey; | ||
if (evt.keyCode === 9 && focusableEls.loopTo && (loopToFirstEl || loopToLastEl)) { | ||
evt.preventDefault(); | ||
focusableEls.loopTo.focus(); | ||
} | ||
} | ||
} | ||
/** | ||
@@ -384,13 +381,13 @@ * Parses and executes any scripts found within the provided `containerEl` element. | ||
*/ | ||
function parseScripts(containerEl) { | ||
[].forEach.call(containerEl.querySelectorAll('script'), function (oldScript) { | ||
var newScript = document.createElement('script'); | ||
Array.from(oldScript.attributes).forEach(function (attr) { | ||
return newScript.setAttribute(attr.name, attr.value); | ||
}); | ||
newScript.appendChild(document.createTextNode(oldScript.innerHTML)); | ||
oldScript.parentNode.replaceChild(newScript, oldScript); | ||
function parseScripts(containerEl) { | ||
[].forEach.call(containerEl.querySelectorAll('script'), function (oldScript) { | ||
var newScript = document.createElement('script'); | ||
Array.from(oldScript.attributes).forEach(function (attr) { | ||
return newScript.setAttribute(attr.name, attr.value); | ||
}); | ||
newScript.appendChild(document.createTextNode(oldScript.innerHTML)); | ||
oldScript.parentNode.replaceChild(newScript, oldScript); | ||
}); | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj};exports.isRTL=isRTL;exports.whichTransition=whichTransition;exports.createElWithAttrs=createElWithAttrs;exports.callbackOnElements=callbackOnElements;exports.getUrlParameter=getUrlParameter;exports.hasURLParameter=hasURLParameter;exports.getTotalRect=getTotalRect;exports.scrollToPosition=scrollToPosition;exports.objectAssign=objectAssign;exports.createCookie=createCookie;exports.readCookie=readCookie;exports.eraseCookie=eraseCookie;exports.forceFocus=forceFocus;exports.focusTrap=focusTrap;exports.parseScripts=parseScripts;(function(){if(!Element.prototype.matches){Element.prototype.matches=Element.prototype.msMatchesSelector}if(!Element.prototype.closest){Element.prototype.closest=_getClosest}})();function _getClosest(selector){var currentEl=this;while(currentEl.constructor!==HTMLHtmlElement){if(currentEl.parentNode.matches(selector)){return currentEl.parentNode}else if(currentEl.matches(selector)){return currentEl}currentEl=currentEl.parentNode}return false}var isMobile=exports.isMobile={Android:function Android(){return navigator.userAgent.match(/Android/i)},BlackBerry:function BlackBerry(){return navigator.userAgent.match(/BlackBerry/i)},iOS:function iOS(){return navigator.userAgent.match(/iPhone|iPad|iPod/i)},Opera:function Opera(){return navigator.userAgent.match(/Opera Mini/i)},Windows:function Windows(){return navigator.userAgent.match(/IEMobile/i)||navigator.userAgent.match(/WPDesktop/i)},any:function any(){return isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows()}};function isRTL(){return document.documentElement.getAttribute("dir")==="rtl"?true:false}function whichTransition(){var dummyEl=document.createElement("dummy"),transitions={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var key in transitions){if(dummyEl.style[key]!==undefined){return transitions[key]}}}function createElWithAttrs(appendTarget,attributes,type,textContent){var el=void 0;if((typeof type==="undefined"?"undefined":_typeof(type))==="object"){var fullNameSpace=type.nameSpace==="svg"?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml";el=document.createElementNS(fullNameSpace,type.tagName||"div")}else{el=document.createElement(type||"div")}for(var key in attributes){el.setAttribute(key,attributes[key])}if(textContent){el.textContent="";el.insertAdjacentHTML("afterbegin",textContent)}if(appendTarget){appendTarget.appendChild(el)}return el}function callbackOnElements(elementSelector,callback){var elementList=void 0;if(elementSelector.length){if(typeof elementSelector==="string"){elementList=document.querySelectorAll(elementSelector)}else{elementList=elementSelector}[].forEach.call(elementList,callback.bind(this))}else{callback.call(this,elementSelector)}}function getUrlParameter(name){name=name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var regex=new RegExp("[\\?&]"+name+"=([^&#]*)"),results=regex.exec(location.search);return results===null?"":decodeURIComponent(results[1].replace(/\+/g," "))}function hasURLParameter(name){var regex=new RegExp("[?&]"+name);return"#"+name===window.location.hash||regex.test(window.location.search)}function getTotalRect(elements,property){var totalOffsetHeight=0;callbackOnElements(elements,function(currentEl){totalOffsetHeight+=currentEl.getBoundingClientRect()[property||"height"]});return totalOffsetHeight}function scrollToPosition(target){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var scrollContainer=arguments[2];var documentHeight=scrollContainer?scrollContainer.scrollHeight:Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight),documentScrollTop=scrollContainer?scrollContainer.scrollTop:window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop,windowHeight=scrollContainer?scrollContainer.offsetHeight:document.documentElement.clientHeight,totalOffset=typeof offset==="number"?offset:getTotalRect(offset),targetOffset=typeof target==="number"?target:getTotalRect(target,"top")+documentScrollTop,targetOffsetToScroll=Math.round(documentHeight-targetOffset<windowHeight?documentHeight-windowHeight:targetOffset);targetOffsetToScroll-=totalOffset;return targetOffsetToScroll}function objectAssign(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(source.hasOwnProperty(key)){target[key]=source[key]}}}return target}function createCookie(name,value,days,domain){var expires=void 0;domain=domain?";domain="+domain:"";if(days){var date=new Date;date.setTime(date.getTime()+days*24*60*60*1e3);expires="; expires="+date.toGMTString()}else{expires=""}document.cookie=name+"="+value+expires+domain+"; path=/"}function readCookie(name){var nameEQ=name+"=",cookieList=document.cookie.split(";");for(var i=0;i<cookieList.length;i++){var currentCookie=cookieList[i];while(currentCookie.charAt(0)==" "){currentCookie=currentCookie.substring(1,currentCookie.length)}if(currentCookie.indexOf(nameEQ)===0){return currentCookie.substring(nameEQ.length,currentCookie.length)}}return null}function eraseCookie(name){createCookie(name,"",-1)}var focusInterval=void 0;function forceFocus(focusTarget){focusTarget.focus();window.clearInterval(focusInterval);focusInterval=window.setInterval(function(){if(focusTarget.matches(":focus")){window.clearInterval(focusInterval)}else{focusTarget.focus()}},25)}function focusTrap(containerEl){var focusableEls={};if(!containerEl.dataset.focustrapEnabled){containerEl.dataset.focustrapEnabled=true;containerEl.addEventListener("focusin",_focusinHandler);containerEl.addEventListener("keydown",_tabbingHandler)}function _focusinHandler(evt){focusableEls.list=this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');focusableEls.first=focusableEls.list[0];focusableEls.last=focusableEls.list[focusableEls.list.length-1];focusableEls.loopTo=null;if(evt.target===focusableEls.last){focusableEls.loopTo=focusableEls.first}else if(evt.target===focusableEls.first){focusableEls.loopTo=focusableEls.last}}function _tabbingHandler(evt){var loopToFirstEl=focusableEls.loopTo===focusableEls.first&&!evt.shiftKey,loopToLastEl=focusableEls.loopTo===focusableEls.last&&evt.shiftKey;if(evt.keyCode===9&&focusableEls.loopTo&&(loopToFirstEl||loopToLastEl)){evt.preventDefault();focusableEls.loopTo.focus()}}}function parseScripts(containerEl){[].forEach.call(containerEl.querySelectorAll("script"),function(oldScript){var newScript=document.createElement("script");Array.from(oldScript.attributes).forEach(function(attr){return newScript.setAttribute(attr.name,attr.value)});newScript.appendChild(document.createTextNode(oldScript.innerHTML));oldScript.parentNode.replaceChild(newScript,oldScript)})} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isRTL=isRTL;exports.whichTransition=whichTransition;exports.createElWithAttrs=createElWithAttrs;exports.callbackOnElements=callbackOnElements;exports.getUrlParameter=getUrlParameter;exports.hasURLParameter=hasURLParameter;exports.getTotalRect=getTotalRect;exports.scrollToPosition=scrollToPosition;exports.objectAssign=objectAssign;exports.createCookie=createCookie;exports.readCookie=readCookie;exports.eraseCookie=eraseCookie;exports.forceFocus=forceFocus;exports.focusTrap=focusTrap;exports.parseScripts=parseScripts;exports.isMobile=void 0;function _typeof(obj){"@babel/helpers - typeof";if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj}}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj}}return _typeof(obj)}(function(){if(!Element.prototype.matches){Element.prototype.matches=Element.prototype.msMatchesSelector}if(!Element.prototype.closest){Element.prototype.closest=_getClosest}})();function _getClosest(selector){var currentEl=this;while(currentEl.constructor!==HTMLHtmlElement){if(currentEl.parentNode.matches(selector)){return currentEl.parentNode}else if(currentEl.matches(selector)){return currentEl}currentEl=currentEl.parentNode}return false}var isMobile={Android:function Android(){return navigator.userAgent.match(/Android/i)},BlackBerry:function BlackBerry(){return navigator.userAgent.match(/BlackBerry/i)},iOS:function iOS(){return navigator.userAgent.match(/iPhone|iPad|iPod/i)},Opera:function Opera(){return navigator.userAgent.match(/Opera Mini/i)},Windows:function Windows(){return navigator.userAgent.match(/IEMobile/i)||navigator.userAgent.match(/WPDesktop/i)},any:function any(){return isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows()}};exports.isMobile=isMobile;function isRTL(){return document.documentElement.getAttribute("dir")==="rtl"?true:false}function whichTransition(){var dummyEl=document.createElement("dummy"),transitions={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(var key in transitions){if(dummyEl.style[key]!==undefined){return transitions[key]}}}function createElWithAttrs(appendTarget,attributes,type,textContent){var el;if(_typeof(type)==="object"){var fullNameSpace=type.nameSpace==="svg"?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml";el=document.createElementNS(fullNameSpace,type.tagName||"div")}else{el=document.createElement(type||"div")}for(var key in attributes){el.setAttribute(key,attributes[key])}if(textContent){el.textContent="";el.insertAdjacentHTML("afterbegin",textContent)}if(appendTarget){appendTarget.appendChild(el)}return el}function callbackOnElements(elementSelector,callback){var elementList;if(elementSelector.length){if(typeof elementSelector==="string"){elementList=document.querySelectorAll(elementSelector)}else{elementList=elementSelector}[].forEach.call(elementList,callback.bind(this))}else{callback.call(this,elementSelector)}}function getUrlParameter(name){name=name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var regex=new RegExp("[\\?&]"+name+"=([^&#]*)"),results=regex.exec(location.search);return results===null?"":decodeURIComponent(results[1].replace(/\+/g," "))}function hasURLParameter(name){var regex=new RegExp("[?&]"+name);return"#"+name===window.location.hash||regex.test(window.location.search)}function getTotalRect(elements,property){var totalOffsetHeight=0;callbackOnElements(elements,function(currentEl){totalOffsetHeight+=currentEl.getBoundingClientRect()[property||"height"]});return totalOffsetHeight}function scrollToPosition(target){var offset=arguments.length>1&&arguments[1]!==undefined?arguments[1]:0;var scrollContainer=arguments.length>2?arguments[2]:undefined;var documentHeight=scrollContainer?scrollContainer.scrollHeight:Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight),documentScrollTop=scrollContainer?scrollContainer.scrollTop:window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop,windowHeight=scrollContainer?scrollContainer.offsetHeight:document.documentElement.clientHeight,totalOffset=typeof offset==="number"?offset:getTotalRect(offset),targetOffset=typeof target==="number"?target:getTotalRect(target,"top")+documentScrollTop,targetOffsetToScroll=Math.round(documentHeight-targetOffset<windowHeight?documentHeight-windowHeight:targetOffset);targetOffsetToScroll-=totalOffset;return targetOffsetToScroll}function objectAssign(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(source.hasOwnProperty(key)){target[key]=source[key]}}}return target}function createCookie(name,value,days,domain){var expires;domain=domain?";domain="+domain:"";if(days){var date=new Date;date.setTime(date.getTime()+days*24*60*60*1e3);expires="; expires="+date.toGMTString()}else{expires=""}document.cookie=name+"="+value+expires+domain+"; path=/"}function readCookie(name){var nameEQ=name+"=",cookieList=document.cookie.split(";");for(var i=0;i<cookieList.length;i++){var currentCookie=cookieList[i];while(currentCookie.charAt(0)==" "){currentCookie=currentCookie.substring(1,currentCookie.length)}if(currentCookie.indexOf(nameEQ)===0){return currentCookie.substring(nameEQ.length,currentCookie.length)}}return null}function eraseCookie(name){createCookie(name,"",-1)}var focusInterval;function forceFocus(focusTarget){focusTarget.focus();window.clearInterval(focusInterval);focusInterval=window.setInterval(function(){if(focusTarget.matches(":focus")){window.clearInterval(focusInterval)}else{focusTarget.focus()}},25)}function focusTrap(containerEl){var focusableEls={};if(!containerEl.dataset.focustrapEnabled){containerEl.dataset.focustrapEnabled=true;containerEl.addEventListener("focusin",_focusinHandler);containerEl.addEventListener("keydown",_tabbingHandler)}function _focusinHandler(evt){focusableEls.list=this.querySelectorAll('button, [href], input:not([type="hidden"]), select, textarea, [tabindex]:not([tabindex="-1"])');focusableEls.first=focusableEls.list[0];focusableEls.last=focusableEls.list[focusableEls.list.length-1];focusableEls.loopTo=null;if(evt.target===focusableEls.last){focusableEls.loopTo=focusableEls.first}else if(evt.target===focusableEls.first){focusableEls.loopTo=focusableEls.last}}function _tabbingHandler(evt){var loopToFirstEl=focusableEls.loopTo===focusableEls.first&&!evt.shiftKey,loopToLastEl=focusableEls.loopTo===focusableEls.last&&evt.shiftKey;if(evt.keyCode===9&&focusableEls.loopTo&&(loopToFirstEl||loopToLastEl)){evt.preventDefault();focusableEls.loopTo.focus()}}}function parseScripts(containerEl){[].forEach.call(containerEl.querySelectorAll("script"),function(oldScript){var newScript=document.createElement("script");Array.from(oldScript.attributes).forEach(function(attr){return newScript.setAttribute(attr.name,attr.value)});newScript.appendChild(document.createTextNode(oldScript.innerHTML));oldScript.parentNode.replaceChild(newScript,oldScript)})} |
{ | ||
"name": "@borngroup/born-utilities", | ||
"version": "2.5.3", | ||
"version": "3.0.0", | ||
"description": "Set of useful utilities for BORN projects.", | ||
@@ -11,3 +11,3 @@ "main": "dist/born-utilities.min.js", | ||
"build:commonjs": "babel src/born-utilities.js --out-file dist/born-utilities.js", | ||
"build:amd": "babel --plugins transform-es2015-modules-amd src/born-utilities.js --out-file dist/born-utilities.amd.js", | ||
"build:amd": "babel --plugins @babel/plugin-transform-modules-amd src/born-utilities.js --out-file dist/born-utilities.amd.js", | ||
"uglify:commonjs": "uglifyjs dist/born-utilities.js --output dist/born-utilities.min.js", | ||
@@ -27,8 +27,9 @@ "uglify:amd": "uglifyjs dist/born-utilities.amd.js --output dist/born-utilities.amd.min.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-plugin-transform-es2015-modules-amd": "^6.24.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"npm-run-all": "^4.0.2", | ||
"uglify-js": "^3.0.15" | ||
"@babel/cli": "^7.12.10", | ||
"@babel/core": "^7.12.10", | ||
"@babel/plugin-transform-modules-amd": "^7.12.1", | ||
"@babel/preset-env": "^7.12.11", | ||
"npm-run-all": "^4.1.5", | ||
"uglify-js": "^3.12.6" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56458
6
1028