diff options
author | XhmikosR <xhmikosr@gmail.com> | 2021-10-29 10:38:35 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2022-01-29 14:25:30 +0300 |
commit | 62d86c07f81dfae632742dbf62633e767bac8edd (patch) | |
tree | 0632411740f52351da50f74a44b9a4ecb4d923c0 /js/src | |
parent | 3ac4451d47c41c3153d554eb7b84f558c137995e (diff) |
Rename variables
Diffstat (limited to 'js/src')
-rw-r--r-- | js/src/carousel.js | 4 | ||||
-rw-r--r-- | js/src/collapse.js | 16 | ||||
-rw-r--r-- | js/src/dom/event-handler.js | 40 | ||||
-rw-r--r-- | js/src/dom/manipulator.js | 14 | ||||
-rw-r--r-- | js/src/dropdown.js | 12 | ||||
-rw-r--r-- | js/src/modal.js | 6 | ||||
-rw-r--r-- | js/src/offcanvas.js | 4 | ||||
-rw-r--r-- | js/src/tooltip.js | 12 | ||||
-rw-r--r-- | js/src/util/sanitizer.js | 6 | ||||
-rw-r--r-- | js/src/util/scrollbar.js | 24 |
10 files changed, 69 insertions, 69 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js index 51c5dded8e..fe3ccf94e8 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -220,8 +220,8 @@ class Carousel extends BaseComponent { } _addTouchEventListeners() { - for (const itemImg of SelectorEngine.find(SELECTOR_ITEM_IMG, this._element)) { - EventHandler.on(itemImg, EVENT_DRAG_START, event => event.preventDefault()) + for (const img of SelectorEngine.find(SELECTOR_ITEM_IMG, this._element)) { + EventHandler.on(img, EVENT_DRAG_START, event => event.preventDefault()) } const endCallBack = () => { diff --git a/js/src/collapse.js b/js/src/collapse.js index 56d4f51c2d..68046e1a6b 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -70,7 +70,7 @@ class Collapse extends BaseComponent { for (const elem of toggleList) { const selector = getSelectorFromElement(elem) const filterElement = SelectorEngine.find(selector) - .filter(foundElem => foundElem === this._element) + .filter(foundElement => foundElement === this._element) if (selector !== null && filterElement.length) { this._triggerArray.push(elem) @@ -185,9 +185,9 @@ class Collapse extends BaseComponent { this._element.classList.remove(CLASS_NAME_COLLAPSE, CLASS_NAME_SHOW) for (const trigger of this._triggerArray) { - const elem = getElementFromSelector(trigger) + const element = getElementFromSelector(trigger) - if (elem && !this._isShown(elem)) { + if (element && !this._isShown(element)) { this._addAriaAndCollapsedClass([trigger], false) } } @@ -240,7 +240,7 @@ class Collapse extends BaseComponent { _getFirstLevelChildren(selector) { const children = SelectorEngine.find(CLASS_NAME_DEEPER_CHILDREN, this._config.parent) // remove children if greater depth - return SelectorEngine.find(selector, this._config.parent).filter(elem => !children.includes(elem)) + return SelectorEngine.find(selector, this._config.parent).filter(element => !children.includes(element)) } _addAriaAndCollapsedClass(triggerArray, isOpen) { @@ -248,14 +248,14 @@ class Collapse extends BaseComponent { return } - for (const elem of triggerArray) { + for (const element of triggerArray) { if (isOpen) { - elem.classList.remove(CLASS_NAME_COLLAPSED) + element.classList.remove(CLASS_NAME_COLLAPSED) } else { - elem.classList.add(CLASS_NAME_COLLAPSED) + element.classList.add(CLASS_NAME_COLLAPSED) } - elem.setAttribute('aria-expanded', isOpen) + element.setAttribute('aria-expanded', isOpen) } } diff --git a/js/src/dom/event-handler.js b/js/src/dom/event-handler.js index 64e52ed958..09f2d4d8f2 100644 --- a/js/src/dom/event-handler.js +++ b/js/src/dom/event-handler.js @@ -134,9 +134,9 @@ function findHandler(events, handler, delegationSelector = null) { return null } -function normalizeParams(originalTypeEvent, handler, delegationFn) { +function normalizeParameters(originalTypeEvent, handler, delegationFunction) { const delegation = typeof handler === 'string' - const originalHandler = delegation ? delegationFn : handler + const originalHandler = delegation ? delegationFunction : handler let typeEvent = getTypeEvent(originalTypeEvent) if (!nativeEvents.has(typeEvent)) { @@ -146,20 +146,20 @@ function normalizeParams(originalTypeEvent, handler, delegationFn) { return [delegation, originalHandler, typeEvent] } -function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) { +function addHandler(element, originalTypeEvent, handler, delegationFunction, oneOff) { if (typeof originalTypeEvent !== 'string' || !element) { return } if (!handler) { - handler = delegationFn - delegationFn = null + handler = delegationFunction + delegationFunction = null } // in case of mouseenter or mouseleave wrap the handler within a function that checks for its DOM position // this prevents the handler from being dispatched the same way as mouseover or mouseout does if (customEventsRegex.test(originalTypeEvent)) { - const wrapFn = fn => { + const wrapFunction = fn => { return function (event) { if (!event.relatedTarget || (event.relatedTarget !== event.delegateTarget && !event.delegateTarget.contains(event.relatedTarget))) { return fn.call(this, event) @@ -167,27 +167,27 @@ function addHandler(element, originalTypeEvent, handler, delegationFn, oneOff) { } } - if (delegationFn) { - delegationFn = wrapFn(delegationFn) + if (delegationFunction) { + delegationFunction = wrapFunction(delegationFunction) } else { - handler = wrapFn(handler) + handler = wrapFunction(handler) } } - const [delegation, originalHandler, typeEvent] = normalizeParams(originalTypeEvent, handler, delegationFn) + const [delegation, originalHandler, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationFunction) const events = getEvent(element) const handlers = events[typeEvent] || (events[typeEvent] = {}) - const previousFn = findHandler(handlers, originalHandler, delegation ? handler : null) + const previousFunction = findHandler(handlers, originalHandler, delegation ? handler : null) - if (previousFn) { - previousFn.oneOff = previousFn.oneOff && oneOff + if (previousFunction) { + previousFunction.oneOff = previousFunction.oneOff && oneOff return } const uid = getUidEvent(originalHandler, originalTypeEvent.replace(namespaceRegex, '')) const fn = delegation ? - bootstrapDelegationHandler(element, handler, delegationFn) : + bootstrapDelegationHandler(element, handler, delegationFunction) : bootstrapHandler(element, handler) fn.delegationSelector = delegation ? handler : null @@ -228,20 +228,20 @@ function getTypeEvent(event) { } const EventHandler = { - on(element, event, handler, delegationFn) { - addHandler(element, event, handler, delegationFn, false) + on(element, event, handler, delegationFunction) { + addHandler(element, event, handler, delegationFunction, false) }, - one(element, event, handler, delegationFn) { - addHandler(element, event, handler, delegationFn, true) + one(element, event, handler, delegationFunction) { + addHandler(element, event, handler, delegationFunction, true) }, - off(element, originalTypeEvent, handler, delegationFn) { + off(element, originalTypeEvent, handler, delegationFunction) { if (typeof originalTypeEvent !== 'string' || !element) { return } - const [delegation, originalHandler, typeEvent] = normalizeParams(originalTypeEvent, handler, delegationFn) + const [delegation, originalHandler, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationFunction) const inNamespace = typeEvent !== originalTypeEvent const events = getEvent(element) const isNamespace = originalTypeEvent.startsWith('.') diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js index a3e9e192ae..e3ee293c7d 100644 --- a/js/src/dom/manipulator.js +++ b/js/src/dom/manipulator.js @@ -5,24 +5,24 @@ * -------------------------------------------------------------------------- */ -function normalizeData(val) { - if (val === 'true') { +function normalizeData(value) { + if (value === 'true') { return true } - if (val === 'false') { + if (value === 'false') { return false } - if (val === Number(val).toString()) { - return Number(val) + if (value === Number(value).toString()) { + return Number(value) } - if (val === '' || val === 'null') { + if (value === '' || value === 'null') { return null } - return val + return value } function normalizeDataKey(key) { diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 674150e016..9baa8d3a1a 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -136,8 +136,8 @@ class Dropdown extends BaseComponent { // only needed because of broken event delegation on iOS // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) { - for (const elem of [].concat(...document.body.children)) { - EventHandler.on(elem, 'mouseover', noop) + for (const element of [].concat(...document.body.children)) { + EventHandler.on(element, 'mouseover', noop) } } @@ -186,8 +186,8 @@ class Dropdown extends BaseComponent { // If this is a touch-enabled device we remove the extra // empty mouseover listeners we added for iOS support if ('ontouchstart' in document.documentElement) { - for (const elem of [].concat(...document.body.children)) { - EventHandler.off(elem, 'mouseover', noop) + for (const element of [].concat(...document.body.children)) { + EventHandler.off(element, 'mouseover', noop) } } @@ -271,7 +271,7 @@ class Dropdown extends BaseComponent { const { offset } = this._config if (typeof offset === 'string') { - return offset.split(',').map(val => Number.parseInt(val, 10)) + return offset.split(',').map(value => Number.parseInt(value, 10)) } if (typeof offset === 'function') { @@ -314,7 +314,7 @@ class Dropdown extends BaseComponent { } _selectMenuItem({ key, target }) { - const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(el => isVisible(el)) + const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(element => isVisible(element)) if (!items.length) { return diff --git a/js/src/modal.js b/js/src/modal.js index e06cf75164..ae7369a529 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -369,9 +369,9 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function ( }) // avoid conflict when clicking modal toggler while another one is open - const allReadyOpen = SelectorEngine.findOne(OPEN_SELECTOR) - if (allReadyOpen) { - Modal.getInstance(allReadyOpen).hide() + const alreadyOpen = SelectorEngine.findOne(OPEN_SELECTOR) + if (alreadyOpen) { + Modal.getInstance(alreadyOpen).hide() } const data = Modal.getOrCreateInstance(target) diff --git a/js/src/offcanvas.js b/js/src/offcanvas.js index db65340391..2735a9c2ae 100644 --- a/js/src/offcanvas.js +++ b/js/src/offcanvas.js @@ -238,8 +238,8 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function ( }) EventHandler.on(window, EVENT_LOAD_DATA_API, () => { - for (const el of SelectorEngine.find(OPEN_SELECTOR)) { - Offcanvas.getOrCreateInstance(el).show() + for (const selector of SelectorEngine.find(OPEN_SELECTOR)) { + Offcanvas.getOrCreateInstance(selector).show() } }) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index aa54371e7e..32f9cb91c2 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -254,12 +254,12 @@ class Tooltip extends BaseComponent { } const complete = () => { - const prevHoverState = this._isHovered + const previousHoverState = this._isHovered this._isHovered = false EventHandler.trigger(this._element, this.constructor.Event.SHOWN) - if (prevHoverState) { + if (previousHoverState) { this._leave() } } @@ -408,7 +408,7 @@ class Tooltip extends BaseComponent { const { offset } = this._config if (typeof offset === 'string') { - return offset.split(',').map(val => Number.parseInt(val, 10)) + return offset.split(',').map(value => Number.parseInt(value, 10)) } if (typeof offset === 'function') { @@ -572,9 +572,9 @@ class Tooltip extends BaseComponent { _getConfig(config) { const dataAttributes = Manipulator.getDataAttributes(this._element) - for (const dataAttr of Object.keys(dataAttributes)) { - if (DISALLOWED_ATTRIBUTES.has(dataAttr)) { - delete dataAttributes[dataAttr] + for (const dataAttribute of Object.keys(dataAttributes)) { + if (DISALLOWED_ATTRIBUTES.has(dataAttribute)) { + delete dataAttributes[dataAttribute] } } diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 5a7a680355..1db61ae707 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -82,13 +82,13 @@ export const DefaultAllowlist = { ul: [] } -export function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) { +export function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) { if (!unsafeHtml.length) { return unsafeHtml } - if (sanitizeFn && typeof sanitizeFn === 'function') { - return sanitizeFn(unsafeHtml) + if (sanitizeFunction && typeof sanitizeFunction === 'function') { + return sanitizeFunction(unsafeHtml) } const domParser = new window.DOMParser() diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index b81d4b2372..86a2bca01f 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -61,39 +61,39 @@ class ScrollBarHelper { this._element.style.overflow = 'hidden' } - _setElementAttributes(selector, styleProp, callback) { + _setElementAttributes(selector, styleProperty, callback) { const scrollbarWidth = this.getWidth() const manipulationCallBack = element => { if (element !== this._element && window.innerWidth > element.clientWidth + scrollbarWidth) { return } - this._saveInitialAttribute(element, styleProp) - const calculatedValue = window.getComputedStyle(element).getPropertyValue(styleProp) - element.style.setProperty(styleProp, `${callback(Number.parseFloat(calculatedValue))}px`) + this._saveInitialAttribute(element, styleProperty) + const calculatedValue = window.getComputedStyle(element).getPropertyValue(styleProperty) + element.style.setProperty(styleProperty, `${callback(Number.parseFloat(calculatedValue))}px`) } this._applyManipulationCallback(selector, manipulationCallBack) } - _saveInitialAttribute(element, styleProp) { - const actualValue = element.style.getPropertyValue(styleProp) + _saveInitialAttribute(element, styleProperty) { + const actualValue = element.style.getPropertyValue(styleProperty) if (actualValue) { - Manipulator.setDataAttribute(element, styleProp, actualValue) + Manipulator.setDataAttribute(element, styleProperty, actualValue) } } - _resetElementAttributes(selector, styleProp) { + _resetElementAttributes(selector, styleProperty) { const manipulationCallBack = element => { - const value = Manipulator.getDataAttribute(element, styleProp) + const value = Manipulator.getDataAttribute(element, styleProperty) // We only want to remove the property if the value is `null`; the value can also be zero if (value === null) { - element.style.removeProperty(styleProp) + element.style.removeProperty(styleProperty) return } - Manipulator.removeDataAttribute(element, styleProp) - element.style.setProperty(styleProp, value) + Manipulator.removeDataAttribute(element, styleProperty) + element.style.setProperty(styleProperty, value) } this._applyManipulationCallback(selector, manipulationCallBack) |