diff options
| author | XhmikosR <[email protected]> | 2019-02-26 13:20:34 +0200 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-03-11 17:01:28 +0200 |
| commit | 46c037410b8c7eaab3cf50a5cf44093aa2fd41f4 (patch) | |
| tree | cb8c857562c4d3f819a5a8fcc563bc8f2c126e4e /js/src/util | |
| parent | 44e6abcba50309df4fae56a9c7ef79145b64a356 (diff) | |
| download | bootstrap-46c037410b8c7eaab3cf50a5cf44093aa2fd41f4.tar.xz bootstrap-46c037410b8c7eaab3cf50a5cf44093aa2fd41f4.zip | |
Comply to the new rules.
Diffstat (limited to 'js/src/util')
| -rw-r--r-- | js/src/util/index.js | 34 | ||||
| -rw-r--r-- | js/src/util/sanitizer.js | 4 |
2 files changed, 20 insertions, 18 deletions
diff --git a/js/src/util/index.js b/js/src/util/index.js index 7c86a95ff..aea369558 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -8,10 +8,10 @@ const MAX_UID = 1000000 const MILLISECONDS_MULTIPLIER = 1000 const TRANSITION_END = 'transitionend' -const jQuery = window.jQuery +const { jQuery } = window // Shoutout AngusCroll (https://goo.gl/pxwQGp) -const toType = (obj) => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()) +const toType = obj => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()) /** * -------------------------------------------------------------------------- @@ -19,15 +19,16 @@ const toType = (obj) => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCa * -------------------------------------------------------------------------- */ -const getUID = (prefix) => { +const getUID = prefix => { do { // eslint-disable-next-line no-bitwise prefix += ~~(Math.random() * MAX_UID) // "~~" acts like a faster Math.floor() here } while (document.getElementById(prefix)) + return prefix } -const getSelectorFromElement = (element) => { +const getSelectorFromElement = element => { let selector = element.getAttribute('data-target') if (!selector || selector === '#') { @@ -38,12 +39,12 @@ const getSelectorFromElement = (element) => { try { return document.querySelector(selector) ? selector : null - } catch (err) { + } catch (error) { return null } } -const getTransitionDurationFromElement = (element) => { +const getTransitionDurationFromElement = element => { if (!element) { return 0 } @@ -69,11 +70,11 @@ const getTransitionDurationFromElement = (element) => { return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER } -const triggerTransitionEnd = (element) => { +const triggerTransitionEnd = element => { element.dispatchEvent(new Event(TRANSITION_END)) } -const isElement = (obj) => (obj[0] || obj).nodeType +const isElement = obj => (obj[0] || obj).nodeType const emulateTransitionEnd = (element, duration) => { let called = false @@ -94,11 +95,12 @@ const emulateTransitionEnd = (element, duration) => { const typeCheckConfig = (componentName, config, configTypes) => { Object.keys(configTypes) - .forEach((property) => { + .forEach(property => { const expectedTypes = configTypes[property] - const value = config[property] - const valueType = value && isElement(value) - ? 'element' : toType(value) + const value = config[property] + const valueType = value && isElement(value) ? + 'element' : + toType(value) if (!new RegExp(expectedTypes).test(valueType)) { throw new Error( @@ -109,7 +111,7 @@ const typeCheckConfig = (componentName, config, configTypes) => { }) } -const makeArray = (nodeList) => { +const makeArray = nodeList => { if (!nodeList) { return [] } @@ -117,7 +119,7 @@ const makeArray = (nodeList) => { return [].slice.call(nodeList) } -const isVisible = (element) => { +const isVisible = element => { if (!element) { return false } @@ -131,7 +133,7 @@ const isVisible = (element) => { return false } -const findShadowRoot = (element) => { +const findShadowRoot = element => { if (!document.documentElement.attachShadow) { return null } @@ -157,7 +159,7 @@ const findShadowRoot = (element) => { // eslint-disable-next-line no-empty-function const noop = () => function () {} -const reflow = (element) => element.offsetHeight +const reflow = element => element.offsetHeight export { jQuery, diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index f8bb172a9..b2a1d0548 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -47,7 +47,7 @@ const allowedAttribute = (attr, allowedAttributeList) => { return true } - const regExp = allowedAttributeList.filter((attrRegex) => attrRegex instanceof RegExp) + const regExp = allowedAttributeList.filter(attrRegex => attrRegex instanceof RegExp) // Check if a regular expression validates the attribute. for (let i = 0, l = regExp.length; i < l; i++) { @@ -120,7 +120,7 @@ export function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) { const attributeList = makeArray(el.attributes) const whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []) - attributeList.forEach((attr) => { + attributeList.forEach(attr => { if (!allowedAttribute(attr, whitelistedAttributes)) { el.removeAttribute(attr.nodeName) } |
