From 4fd5539c75515527cb1335c31bbaf76209aab296 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 9 Dec 2021 15:05:50 +0200 Subject: ScrollBar.js. Minor refactoring and add test (#35492) --- js/src/util/scrollbar.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 55b7244ab..187a6694d 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -15,6 +15,8 @@ import { isElement } from './index' const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top' const SELECTOR_STICKY_CONTENT = '.sticky-top' +const PROPERTY_PADDING = 'paddingRight' +const PROPERTY_MARGIN = 'marginRight' /** * Class definition @@ -36,17 +38,17 @@ class ScrollBarHelper { const width = this.getWidth() this._disableOverFlow() // give padding to element to balance the hidden scrollbar width - this._setElementAttributes(this._element, 'paddingRight', calculatedValue => calculatedValue + width) + this._setElementAttributes(this._element, PROPERTY_PADDING, calculatedValue => calculatedValue + width) // trick: We adjust positive paddingRight and negative marginRight to sticky-top elements to keep showing fullwidth - this._setElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight', calculatedValue => calculatedValue + width) - this._setElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight', calculatedValue => calculatedValue - width) + this._setElementAttributes(SELECTOR_FIXED_CONTENT, PROPERTY_PADDING, calculatedValue => calculatedValue + width) + this._setElementAttributes(SELECTOR_STICKY_CONTENT, PROPERTY_MARGIN, calculatedValue => calculatedValue - width) } reset() { this._resetElementAttributes(this._element, 'overflow') - this._resetElementAttributes(this._element, 'paddingRight') - this._resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight') - this._resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight') + this._resetElementAttributes(this._element, PROPERTY_PADDING) + this._resetElementAttributes(SELECTOR_FIXED_CONTENT, PROPERTY_PADDING) + this._resetElementAttributes(SELECTOR_STICKY_CONTENT, PROPERTY_MARGIN) } isOverflowing() { @@ -86,10 +88,11 @@ class ScrollBarHelper { const value = Manipulator.getDataAttribute(element, styleProp) if (typeof value === 'undefined') { element.style.removeProperty(styleProp) - } else { - Manipulator.removeDataAttribute(element, styleProp) - element.style[styleProp] = value + return } + + Manipulator.removeDataAttribute(element, styleProp) + element.style[styleProp] = value } this._applyManipulationCallback(selector, manipulationCallBack) @@ -98,10 +101,11 @@ class ScrollBarHelper { _applyManipulationCallback(selector, callBack) { if (isElement(selector)) { callBack(selector) - } else { - for (const sel of SelectorEngine.find(selector, this._element)) { - callBack(sel) - } + return + } + + for (const sel of SelectorEngine.find(selector, this._element)) { + callBack(sel) } } } -- cgit v1.2.3 From 28a5a72ed56df3cc5efb1d5164376c9c9541e4f0 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 9 Dec 2021 15:49:28 +0200 Subject: Scrollbar - remove margin/padding properties properly (#35388) Co-authored-by: XhmikosR --- js/src/util/scrollbar.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 187a6694d..b81d4b237 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -15,8 +15,8 @@ import { isElement } from './index' const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top' const SELECTOR_STICKY_CONTENT = '.sticky-top' -const PROPERTY_PADDING = 'paddingRight' -const PROPERTY_MARGIN = 'marginRight' +const PROPERTY_PADDING = 'padding-right' +const PROPERTY_MARGIN = 'margin-right' /** * Class definition @@ -69,15 +69,15 @@ class ScrollBarHelper { } this._saveInitialAttribute(element, styleProp) - const calculatedValue = window.getComputedStyle(element)[styleProp] - element.style[styleProp] = `${callback(Number.parseFloat(calculatedValue))}px` + const calculatedValue = window.getComputedStyle(element).getPropertyValue(styleProp) + element.style.setProperty(styleProp, `${callback(Number.parseFloat(calculatedValue))}px`) } this._applyManipulationCallback(selector, manipulationCallBack) } _saveInitialAttribute(element, styleProp) { - const actualValue = element.style[styleProp] + const actualValue = element.style.getPropertyValue(styleProp) if (actualValue) { Manipulator.setDataAttribute(element, styleProp, actualValue) } @@ -86,13 +86,14 @@ class ScrollBarHelper { _resetElementAttributes(selector, styleProp) { const manipulationCallBack = element => { const value = Manipulator.getDataAttribute(element, styleProp) - if (typeof value === 'undefined') { + // 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) return } Manipulator.removeDataAttribute(element, styleProp) - element.style[styleProp] = value + element.style.setProperty(styleProp, value) } this._applyManipulationCallback(selector, manipulationCallBack) -- cgit v1.2.3 From 871c8bdd3fe7218c10aa18dacf0b5c612cfff82c Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 10 Dec 2021 07:48:04 +0200 Subject: util/index.js: minor refactoring (#35510) * rename variables * remove an unused variable * be more explicit * reuse variable --- js/src/util/index.js | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index 0ba6ce6f8..0407100d8 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -10,12 +10,12 @@ const MILLISECONDS_MULTIPLIER = 1000 const TRANSITION_END = 'transitionend' // Shoutout AngusCroll (https://goo.gl/pxwQGp) -const toType = obj => { - if (obj === null || obj === undefined) { - return `${obj}` +const toType = object => { + if (object === null || object === undefined) { + return `${object}` } - return Object.prototype.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase() + return Object.prototype.toString.call(object).match(/\s([a-z]+)/i)[1].toLowerCase() } /** @@ -34,22 +34,22 @@ const getSelector = element => { let selector = element.getAttribute('data-bs-target') if (!selector || selector === '#') { - let hrefAttr = element.getAttribute('href') + let hrefAttribute = element.getAttribute('href') // The only valid content that could double as a selector are IDs or classes, // so everything starting with `#` or `.`. If a "real" URL is used as the selector, // `document.querySelector` will rightfully complain it is invalid. // See https://github.com/twbs/bootstrap/issues/32273 - if (!hrefAttr || (!hrefAttr.includes('#') && !hrefAttr.startsWith('.'))) { + if (!hrefAttribute || (!hrefAttribute.includes('#') && !hrefAttribute.startsWith('.'))) { return null } // Just in case some CMS puts out a full URL with the anchor appended - if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) { - hrefAttr = `#${hrefAttr.split('#')[1]}` + if (hrefAttribute.includes('#') && !hrefAttribute.startsWith('#')) { + hrefAttribute = `#${hrefAttribute.split('#')[1]}` } - selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null + selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null } return selector @@ -98,26 +98,26 @@ const triggerTransitionEnd = element => { element.dispatchEvent(new Event(TRANSITION_END)) } -const isElement = obj => { - if (!obj || typeof obj !== 'object') { +const isElement = object => { + if (!object || typeof object !== 'object') { return false } - if (typeof obj.jquery !== 'undefined') { - obj = obj[0] + if (typeof object.jquery !== 'undefined') { + object = object[0] } - return typeof obj.nodeType !== 'undefined' + return typeof object.nodeType !== 'undefined' } -const getElement = obj => { +const getElement = object => { // it's a jQuery object or a node element - if (isElement(obj)) { - return obj.jquery ? obj[0] : obj + if (isElement(object)) { + return object.jquery ? object[0] : object } - if (typeof obj === 'string' && obj.length > 0) { - return document.querySelector(obj) + if (typeof object === 'string' && object.length > 0) { + return document.querySelector(object) } return null @@ -199,10 +199,8 @@ const reflow = element => { } const getjQuery = () => { - const { jQuery } = window - - if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) { - return jQuery + if (window.jQuery && !document.body.hasAttribute('data-bs-no-jquery')) { + return window.jQuery } return null @@ -291,15 +289,15 @@ const executeAfterTransition = (callback, transitionElement, waitForTransition = * @return {Element|elem} The proper element */ const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => { + const listLength = list.length let index = list.indexOf(activeElement) - // if the element does not exist in the list return an element depending on the direction and if cycle is allowed + // if the element does not exist in the list return an element + // depending on the direction and if cycle is allowed if (index === -1) { - return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0] + return !shouldGetNext && isCycleAllowed ? list[listLength - 1] : list[0] } - const listLength = list.length - index += shouldGetNext ? 1 : -1 if (isCycleAllowed) { -- cgit v1.2.3 From 886b940796b3595a03b44230ca8b78197c5ee1c5 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Fri, 10 Dec 2021 18:18:18 +0200 Subject: Extract Component config functionality to a separate class (#33872) Co-authored-by: XhmikosR --- js/src/util/backdrop.js | 27 ++++++++++++------ js/src/util/config.js | 63 +++++++++++++++++++++++++++++++++++++++++ js/src/util/focustrap.js | 27 +++++++++++------- js/src/util/index.js | 16 +---------- js/src/util/swipe.js | 28 +++++++++++------- js/src/util/template-factory.js | 31 ++++++++++---------- 6 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 js/src/util/config.js (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index fb1b2776b..63f2b581c 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -6,7 +6,8 @@ */ import EventHandler from '../dom/event-handler' -import { execute, executeAfterTransition, getElement, reflow, typeCheckConfig } from './index' +import { execute, executeAfterTransition, getElement, reflow } from './index' +import Config from './config' /** * Constants @@ -37,13 +38,27 @@ const DefaultType = { * Class definition */ -class Backdrop { +class Backdrop extends Config { constructor(config) { + super() this._config = this._getConfig(config) this._isAppended = false this._element = null } + // Getters + static get Default() { + return Default + } + + static get DefaultType() { + return DefaultType + } + + static get NAME() { + return NAME + } + // Public show(callback) { if (!this._config.isVisible) { @@ -104,15 +119,9 @@ class Backdrop { return this._element } - _getConfig(config) { - config = { - ...Default, - ...(typeof config === 'object' ? config : {}) - } - + _configAfterMerge(config) { // use getElement() with the default "body" to get a fresh Element on each instantiation config.rootElement = getElement(config.rootElement) - typeCheckConfig(NAME, config, DefaultType) return config } diff --git a/js/src/util/config.js b/js/src/util/config.js new file mode 100644 index 000000000..19d02955d --- /dev/null +++ b/js/src/util/config.js @@ -0,0 +1,63 @@ +/** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): util/config.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + +import { isElement, toType } from './index' +import Manipulator from '../dom/manipulator' + +/** + * Class definition + */ + +class Config { + // Getters + static get Default() { + return {} + } + + static get DefaultType() { + return {} + } + + static get NAME() { + throw new Error('You have to implement the static method "NAME", for each component!') + } + + _getConfig(config) { + config = this._mergeConfigObj(config) + config = this._configAfterMerge(config) + this._typeCheckConfig(config) + return config + } + + _configAfterMerge(config) { + return config + } + + _mergeConfigObj(config, element) { + return { + ...this.constructor.Default, + ...(isElement(element) ? Manipulator.getDataAttributes(element) : {}), + ...(typeof config === 'object' ? config : {}) + } + } + + _typeCheckConfig(config, configTypes = this.constructor.DefaultType) { + for (const property of Object.keys(configTypes)) { + const expectedTypes = configTypes[property] + const value = config[property] + const valueType = isElement(value) ? 'element' : toType(value) + + if (!new RegExp(expectedTypes).test(valueType)) { + throw new TypeError( + `${this.constructor.NAME.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".` + ) + } + } + } +} + +export default Config diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index a1975f489..46727ecf8 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -7,7 +7,7 @@ import EventHandler from '../dom/event-handler' import SelectorEngine from '../dom/selector-engine' -import { typeCheckConfig } from './index' +import Config from './config' /** * Constants @@ -37,13 +37,27 @@ const DefaultType = { * Class definition */ -class FocusTrap { +class FocusTrap extends Config { constructor(config) { + super() this._config = this._getConfig(config) this._isActive = false this._lastTabNavDirection = null } + // Getters + static get Default() { + return Default + } + + static get DefaultType() { + return DefaultType + } + + static get NAME() { + return NAME + } + // Public activate() { const { trapElement, autofocus } = this._config @@ -99,15 +113,6 @@ class FocusTrap { this._lastTabNavDirection = event.shiftKey ? TAB_NAV_BACKWARD : TAB_NAV_FORWARD } - - _getConfig(config) { - config = { - ...Default, - ...(typeof config === 'object' ? config : {}) - } - typeCheckConfig(NAME, config, DefaultType) - return config - } } export default FocusTrap diff --git a/js/src/util/index.js b/js/src/util/index.js index 0407100d8..8bd614d40 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -123,20 +123,6 @@ const getElement = object => { return null } -const typeCheckConfig = (componentName, config, configTypes) => { - for (const property of Object.keys(configTypes)) { - const expectedTypes = configTypes[property] - const value = config[property] - const valueType = value && isElement(value) ? 'element' : toType(value) - - if (!new RegExp(expectedTypes).test(valueType)) { - throw new TypeError( - `${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".` - ) - } - } -} - const isVisible = element => { if (!isElement(element) || element.getClientRects().length === 0) { return false @@ -327,5 +313,5 @@ export { onDOMContentLoaded, reflow, triggerTransitionEnd, - typeCheckConfig + toType } diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 87a5f7f5a..ac09b6fa1 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -5,8 +5,9 @@ * -------------------------------------------------------------------------- */ +import Config from './config' import EventHandler from '../dom/event-handler' -import { execute, typeCheckConfig } from './index' +import { execute } from './index' /** * Constants @@ -40,8 +41,9 @@ const DefaultType = { * Class definition */ -class Swipe { +class Swipe extends Config { constructor(element, config) { + super() this._element = element if (!element || !Swipe.isSupported()) { @@ -54,6 +56,19 @@ class Swipe { this._initEvents() } + // Getters + static get Default() { + return Default + } + + static get DefaultType() { + return DefaultType + } + + static get NAME() { + return NAME + } + // Public dispose() { EventHandler.off(this._element, EVENT_KEY) @@ -118,15 +133,6 @@ class Swipe { } } - _getConfig(config) { - config = { - ...Default, - ...(typeof config === 'object' ? config : {}) - } - typeCheckConfig(NAME, config, DefaultType) - return config - } - _eventIsPointerPenTouch(event) { return this._supportPointerEvents && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH) } diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index a9cee1086..8a8d4da79 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -6,8 +6,9 @@ */ import { DefaultAllowlist, sanitizeHtml } from './sanitizer' -import { getElement, isElement, typeCheckConfig } from '../util/index' +import { getElement, isElement } from '../util/index' import SelectorEngine from '../dom/selector-engine' +import Config from './config' /** * Constants @@ -44,20 +45,25 @@ const DefaultContentType = { * Class definition */ -class TemplateFactory { +class TemplateFactory extends Config { constructor(config) { + super() this._config = this._getConfig(config) } // Getters - static get NAME() { - return NAME - } - static get Default() { return Default } + static get DefaultType() { + return DefaultType + } + + static get NAME() { + return NAME + } + // Public getContent() { return Object.values(this._config.content) @@ -94,21 +100,14 @@ class TemplateFactory { } // Private - _getConfig(config) { - config = { - ...Default, - ...(typeof config === 'object' ? config : {}) - } - - typeCheckConfig(NAME, config, DefaultType) + _typeCheckConfig(config) { + super._typeCheckConfig(config) this._checkContent(config.content) - - return config } _checkContent(arg) { for (const [selector, content] of Object.entries(arg)) { - typeCheckConfig(NAME, { selector, entry: content }, DefaultContentType) + super._typeCheckConfig({ selector, entry: content }, DefaultContentType) } } -- cgit v1.2.3 From 14c7dc1e886015f2ed845f0f8e88d3597694250f Mon Sep 17 00:00:00 2001 From: Ryan Berliner <22206986+RyanBerliner@users.noreply.github.com> Date: Thu, 13 Jan 2022 03:55:05 -0500 Subject: Fix: `isVisible` function behavior in case of a `
` element, on chrome 97 (#35682) --- js/src/util/index.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index 8bd614d40..4e52fd3eb 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -128,7 +128,26 @@ const isVisible = element => { return false } - return getComputedStyle(element).getPropertyValue('visibility') === 'visible' + const elementIsVisible = getComputedStyle(element).getPropertyValue('visibility') === 'visible' + // Handle `details` element as its content may falsie appear visible when it is closed + const closedDetails = element.closest('details:not([open])') + + if (!closedDetails) { + return elementIsVisible + } + + if (closedDetails !== element) { + const summary = element.closest('summary') + if (summary && summary.parentNode !== closedDetails) { + return false + } + + if (summary === null) { + return false + } + } + + return elementIsVisible } const isDisabled = element => { -- cgit v1.2.3 From 0c3dfe104b520d6ce466f265bf60c6d74785972e Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 9 Oct 2021 21:49:49 +0300 Subject: Remove a few unneeded variables --- js/src/util/focustrap.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 46727ecf8..88fd16b10 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -60,14 +60,12 @@ class FocusTrap extends Config { // Public activate() { - const { trapElement, autofocus } = this._config - if (this._isActive) { return } - if (autofocus) { - trapElement.focus() + if (this._config.autofocus) { + this._config.trapElement.focus() } EventHandler.off(document, EVENT_KEY) // guard against infinite focus loop @@ -88,10 +86,9 @@ class FocusTrap extends Config { // Private _handleFocusin(event) { - const { target } = event const { trapElement } = this._config - if (target === document || target === trapElement || trapElement.contains(target)) { + if (event.target === document || event.target === trapElement || trapElement.contains(event.target)) { return } -- cgit v1.2.3 From 3ac4451d47c41c3153d554eb7b84f558c137995e Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 9 Oct 2021 21:50:21 +0300 Subject: backdrop.js: cache `_getElement` calls --- js/src/util/backdrop.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index 63f2b581c..8f121e5bd 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -68,11 +68,12 @@ class Backdrop extends Config { this._append() + const element = this._getElement() if (this._config.isAnimated) { - reflow(this._getElement()) + reflow(element) } - this._getElement().classList.add(CLASS_NAME_SHOW) + element.classList.add(CLASS_NAME_SHOW) this._emulateAnimation(() => { execute(callback) @@ -130,9 +131,10 @@ class Backdrop extends Config { return } - this._config.rootElement.append(this._getElement()) + const element = this._getElement() + this._config.rootElement.append(element) - EventHandler.on(this._getElement(), EVENT_MOUSEDOWN, () => { + EventHandler.on(element, EVENT_MOUSEDOWN, () => { execute(this._config.clickCallback) }) -- cgit v1.2.3 From 62d86c07f81dfae632742dbf62633e767bac8edd Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Fri, 29 Oct 2021 10:38:35 +0300 Subject: Rename variables --- js/src/util/sanitizer.js | 6 +++--- js/src/util/scrollbar.js | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 5a7a68035..1db61ae70 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 b81d4b237..86a2bca01 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) -- cgit v1.2.3 From 584600bda36ac13ea325617783216d6c6a331c08 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 21 Apr 2022 21:41:43 +0300 Subject: Manipulator: Add JSON parse support (#35077) Support parsing JSON from each component's main element using the `data-bs-config` attribute. The `bs-config` attribute will be reserved and omitted during `getDataAttributes` parsing. With this commit, every component, will create its config object, using: * defaults * data-bs-config * the rest of data attributes * configuration object given during instance initialization Co-authored-by: XhmikosR Co-authored-by: Mark Otto Co-authored-by: Mark Otto --- js/src/util/config.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'js/src/util') diff --git a/js/src/util/config.js b/js/src/util/config.js index 19d02955d..f6c194276 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -38,8 +38,11 @@ class Config { } _mergeConfigObj(config, element) { + const jsonConfig = isElement(element) ? Manipulator.getDataAttribute(element, 'config') : {} // try to parse + return { ...this.constructor.Default, + ...(typeof jsonConfig === 'object' ? jsonConfig : {}), ...(isElement(element) ? Manipulator.getDataAttributes(element) : {}), ...(typeof config === 'object' ? config : {}) } -- cgit v1.2.3 From f7e8ca91e03165abb82d4c82555dc4ef96340cc9 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Fri, 6 May 2022 23:57:58 +0300 Subject: Prepare v5.2.0-beta1 --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/focustrap.js | 2 +- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index 8f121e5bd..31619de71 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/backdrop.js + * Bootstrap (v5.2.0-beta1): util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index bd44c3fdc..f1f0701c5 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/component-functions.js + * Bootstrap (v5.2.0-beta1): util/component-functions.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/config.js b/js/src/util/config.js index f6c194276..1878de330 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/config.js + * Bootstrap (v5.2.0-beta1): util/config.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 88fd16b10..40509c1ba 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/focustrap.js + * Bootstrap (v5.2.0-beta1): util/focustrap.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/index.js b/js/src/util/index.js index 4e52fd3eb..161501e39 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/index.js + * Bootstrap (v5.2.0-beta1): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 1db61ae70..06402d296 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/sanitizer.js + * Bootstrap (v5.2.0-beta1): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 86a2bca01..8b66b76be 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/scrollBar.js + * Bootstrap (v5.2.0-beta1): util/scrollBar.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index ac09b6fa1..66baa3dad 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/swipe.js + * Bootstrap (v5.2.0-beta1): util/swipe.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index 8a8d4da79..39fa450c0 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): util/template-factory.js + * Bootstrap (v5.2.0-beta1): util/template-factory.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From c137d11aa2df111e2a42bc42295576fdd366fd68 Mon Sep 17 00:00:00 2001 From: "louismaxime.piton" Date: Thu, 19 May 2022 15:35:44 +0200 Subject: Re-ordering js default objects --- js/src/util/backdrop.js | 12 ++++++------ js/src/util/focustrap.js | 8 ++++---- js/src/util/swipe.js | 8 ++++---- js/src/util/template-factory.js | 16 ++++++++-------- 4 files changed, 22 insertions(+), 22 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index 31619de71..bb01fbb99 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -20,18 +20,18 @@ const EVENT_MOUSEDOWN = `mousedown.bs.${NAME}` const Default = { className: 'modal-backdrop', - isVisible: true, // if false, we use the backdrop helper without adding any element to the dom + clickCallback: null, isAnimated: false, - rootElement: 'body', // give the choice to place backdrop under different elements - clickCallback: null + isVisible: true, // if false, we use the backdrop helper without adding any element to the dom + rootElement: 'body' // give the choice to place backdrop under different elements } const DefaultType = { className: 'string', - isVisible: 'boolean', + clickCallback: '(function|null)', isAnimated: 'boolean', - rootElement: '(element|string)', - clickCallback: '(function|null)' + isVisible: 'boolean', + rootElement: '(element|string)' } /** diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 40509c1ba..51dd19f22 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -24,13 +24,13 @@ const TAB_NAV_FORWARD = 'forward' const TAB_NAV_BACKWARD = 'backward' const Default = { - trapElement: null, // The element to trap focus inside of - autofocus: true + autofocus: true, + trapElement: null // The element to trap focus inside of } const DefaultType = { - trapElement: 'element', - autofocus: 'boolean' + autofocus: 'boolean', + trapElement: 'element' } /** diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 66baa3dad..3676b57e6 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -26,15 +26,15 @@ const CLASS_NAME_POINTER_EVENT = 'pointer-event' const SWIPE_THRESHOLD = 40 const Default = { + endCallback: null, leftCallback: null, - rightCallback: null, - endCallback: null + rightCallback: null } const DefaultType = { + endCallback: '(function|null)', leftCallback: '(function|null)', - rightCallback: '(function|null)', - endCallback: '(function|null)' + rightCallback: '(function|null)' } /** diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index 39fa450c0..cc2551c8f 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -17,28 +17,28 @@ import Config from './config' const NAME = 'TemplateFactory' const Default = { - extraClass: '', - template: '
', + allowList: DefaultAllowlist, content: {}, // { selector : text , selector2 : text2 , } + extraClass: '', html: false, sanitize: true, sanitizeFn: null, - allowList: DefaultAllowlist + template: '
' } const DefaultType = { - extraClass: '(string|function)', - template: 'string', + allowList: 'object', content: 'object', + extraClass: '(string|function)', html: 'boolean', sanitize: 'boolean', sanitizeFn: '(null|function)', - allowList: 'object' + template: 'string' } const DefaultContentType = { - selector: '(string|element)', - entry: '(string|element|function|null)' + entry: '(string|element|function|null)', + selector: '(string|element)' } /** -- cgit v1.2.3 From 705d6857ad262c0f1e8e85645a7a0df7b1e14d84 Mon Sep 17 00:00:00 2001 From: Marc Wrobel Date: Mon, 18 Jul 2022 10:02:41 +0200 Subject: Fix typos in code (#36763) Shoutout is correct but has been replaced by its more common form : Shout-out (https://www.merriam-webster.com/dictionary/shout-out). --- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index 161501e39..b02789df5 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -9,7 +9,7 @@ const MAX_UID = 1_000_000 const MILLISECONDS_MULTIPLIER = 1000 const TRANSITION_END = 'transitionend' -// Shoutout AngusCroll (https://goo.gl/pxwQGp) +// Shout-out Angus Croll (https://goo.gl/pxwQGp) const toType = object => { if (object === null || object === undefined) { return `${object}` diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 06402d296..0584df932 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -21,14 +21,14 @@ const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i /** * A pattern that recognizes a commonly useful subset of URLs that are safe. * - * Shoutout to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts + * Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts */ const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^#&/:?]*(?:[#/?]|$))/i /** * A pattern that matches safe data URLs. Only matches image, video and audio types. * - * Shoutout to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts + * Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts */ const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i -- cgit v1.2.3 From edf9c40956d19e6ab3f9151bfe0dfac6be06fa21 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 19 Jul 2022 18:43:58 +0300 Subject: Release v5.2.0 (#36768) * Bump version to 5.2.0 * Dist * Update masthead.html --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/focustrap.js | 2 +- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index bb01fbb99..26c413a83 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/backdrop.js + * Bootstrap (v5.2.0): util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index f1f0701c5..da7a1d715 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/component-functions.js + * Bootstrap (v5.2.0): util/component-functions.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/config.js b/js/src/util/config.js index 1878de330..d700cdb29 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/config.js + * Bootstrap (v5.2.0): util/config.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 51dd19f22..5ffc9fe1c 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/focustrap.js + * Bootstrap (v5.2.0): util/focustrap.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/index.js b/js/src/util/index.js index b02789df5..beae7c977 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/index.js + * Bootstrap (v5.2.0): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 0584df932..23b16a69a 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/sanitizer.js + * Bootstrap (v5.2.0): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 8b66b76be..6ddc063e4 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/scrollBar.js + * Bootstrap (v5.2.0): util/scrollBar.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 3676b57e6..617eba345 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/swipe.js + * Bootstrap (v5.2.0): util/swipe.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index cc2551c8f..92961a53b 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0-beta1): util/template-factory.js + * Bootstrap (v5.2.0): util/template-factory.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From 23e50829f958ea1d741d63e2781716be037e4644 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 7 Sep 2022 18:31:39 +0300 Subject: Release v5.2.1 (#37098) * Bump version to v5.2.1. * Dist --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/focustrap.js | 2 +- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index 26c413a83..a5f4ab55e 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/backdrop.js + * Bootstrap (v5.2.1): util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index da7a1d715..6f7aea5e7 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/component-functions.js + * Bootstrap (v5.2.1): util/component-functions.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/config.js b/js/src/util/config.js index d700cdb29..eb0bacb16 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/config.js + * Bootstrap (v5.2.1): util/config.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 5ffc9fe1c..262832782 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/focustrap.js + * Bootstrap (v5.2.1): util/focustrap.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/index.js b/js/src/util/index.js index beae7c977..39809b1f8 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/index.js + * Bootstrap (v5.2.1): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 23b16a69a..cf0271e6c 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/sanitizer.js + * Bootstrap (v5.2.1): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 6ddc063e4..f4304b2ba 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/scrollBar.js + * Bootstrap (v5.2.1): util/scrollBar.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 617eba345..81d377d29 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/swipe.js + * Bootstrap (v5.2.1): util/swipe.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index 92961a53b..688a27fe7 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.0): util/template-factory.js + * Bootstrap (v5.2.1): util/template-factory.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From 961d5ff9844372a4e294980c667bbe7e0651cdeb Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 3 Oct 2022 10:44:02 +0300 Subject: Release v5.2.2 (#37236) * Bump version to v5.2.2 * Dist --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/focustrap.js | 2 +- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index a5f4ab55e..342f8afc1 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/backdrop.js + * Bootstrap (v5.2.2): util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index 6f7aea5e7..798366b07 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/component-functions.js + * Bootstrap (v5.2.2): util/component-functions.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/config.js b/js/src/util/config.js index eb0bacb16..119a3ea3d 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/config.js + * Bootstrap (v5.2.2): util/config.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 262832782..01ac76683 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/focustrap.js + * Bootstrap (v5.2.2): util/focustrap.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/index.js b/js/src/util/index.js index 39809b1f8..7c2411665 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/index.js + * Bootstrap (v5.2.2): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index cf0271e6c..6a9daa6ce 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/sanitizer.js + * Bootstrap (v5.2.2): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index f4304b2ba..421426d41 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/scrollBar.js + * Bootstrap (v5.2.2): util/scrollBar.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 81d377d29..7fcd65588 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/swipe.js + * Bootstrap (v5.2.2): util/swipe.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index 688a27fe7..c6d52a50d 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.1): util/template-factory.js + * Bootstrap (v5.2.2): util/template-factory.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From 4cb046a6b8b37a0f328fa5b86fbd573ca3f0dc33 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Fri, 7 Oct 2022 15:25:00 +0300 Subject: Boost `execute` function, being able to handle arguments (#36652) --- js/src/util/index.js | 6 ++---- js/src/util/template-factory.js | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index 7c2411665..ad99f85ed 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -249,10 +249,8 @@ const defineJQueryPlugin = plugin => { }) } -const execute = callback => { - if (typeof callback === 'function') { - callback() - } +const execute = (possibleCallback, args = [], defaultValue = possibleCallback) => { + return typeof possibleCallback === 'function' ? possibleCallback(...args) : defaultValue } const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => { diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index c6d52a50d..16ec6c28d 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -6,7 +6,7 @@ */ import { DefaultAllowlist, sanitizeHtml } from './sanitizer' -import { getElement, isElement } from '../util/index' +import { execute, getElement, isElement } from '../util/index' import SelectorEngine from '../dom/selector-engine' import Config from './config' @@ -143,7 +143,7 @@ class TemplateFactory extends Config { } _resolvePossibleFunction(arg) { - return typeof arg === 'function' ? arg(this) : arg + return execute(arg, [this]) } _putElementInTemplate(element, templateElement) { -- cgit v1.2.3 From aa9d32dd153ed16943ad8be5e8795afaad24d0cf Mon Sep 17 00:00:00 2001 From: GeoSot Date: Wed, 26 Oct 2022 08:26:51 +0300 Subject: Use explicit imports in our javascript source files (#36854) --- js/src/util/backdrop.js | 6 +++--- js/src/util/component-functions.js | 4 ++-- js/src/util/config.js | 4 ++-- js/src/util/focustrap.js | 6 +++--- js/src/util/scrollbar.js | 6 +++--- js/src/util/swipe.js | 6 +++--- js/src/util/template-factory.js | 8 ++++---- 7 files changed, 20 insertions(+), 20 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index 342f8afc1..832ba745a 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -5,9 +5,9 @@ * -------------------------------------------------------------------------- */ -import EventHandler from '../dom/event-handler' -import { execute, executeAfterTransition, getElement, reflow } from './index' -import Config from './config' +import EventHandler from '../dom/event-handler.js' +import { execute, executeAfterTransition, getElement, reflow } from './index.js' +import Config from './config.js' /** * Constants diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index 798366b07..2298ac371 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -5,8 +5,8 @@ * -------------------------------------------------------------------------- */ -import EventHandler from '../dom/event-handler' -import { getElementFromSelector, isDisabled } from './index' +import EventHandler from '../dom/event-handler.js' +import { getElementFromSelector, isDisabled } from './index.js' const enableDismissTrigger = (component, method = 'hide') => { const clickEvent = `click.dismiss${component.EVENT_KEY}` diff --git a/js/src/util/config.js b/js/src/util/config.js index 119a3ea3d..f2d24b4ba 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -5,8 +5,8 @@ * -------------------------------------------------------------------------- */ -import { isElement, toType } from './index' -import Manipulator from '../dom/manipulator' +import { isElement, toType } from './index.js' +import Manipulator from '../dom/manipulator.js' /** * Class definition diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 01ac76683..b03d46136 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -5,9 +5,9 @@ * -------------------------------------------------------------------------- */ -import EventHandler from '../dom/event-handler' -import SelectorEngine from '../dom/selector-engine' -import Config from './config' +import EventHandler from '../dom/event-handler.js' +import SelectorEngine from '../dom/selector-engine.js' +import Config from './config.js' /** * Constants diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 421426d41..94a677c9f 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -5,9 +5,9 @@ * -------------------------------------------------------------------------- */ -import SelectorEngine from '../dom/selector-engine' -import Manipulator from '../dom/manipulator' -import { isElement } from './index' +import SelectorEngine from '../dom/selector-engine.js' +import Manipulator from '../dom/manipulator.js' +import { isElement } from './index.js' /** * Constants diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 7fcd65588..3a9139cc0 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -5,9 +5,9 @@ * -------------------------------------------------------------------------- */ -import Config from './config' -import EventHandler from '../dom/event-handler' -import { execute } from './index' +import Config from './config.js' +import EventHandler from '../dom/event-handler.js' +import { execute } from './index.js' /** * Constants diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index 16ec6c28d..9cd12dcdb 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -5,10 +5,10 @@ * -------------------------------------------------------------------------- */ -import { DefaultAllowlist, sanitizeHtml } from './sanitizer' -import { execute, getElement, isElement } from '../util/index' -import SelectorEngine from '../dom/selector-engine' -import Config from './config' +import { DefaultAllowlist, sanitizeHtml } from './sanitizer.js' +import { execute, getElement, isElement } from './index.js' +import SelectorEngine from '../dom/selector-engine.js' +import Config from './config.js' /** * Constants -- cgit v1.2.3 From e81e7cda90026cdb2a05fcdadd2d66f48f0bbdc4 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Sun, 6 Nov 2022 20:31:43 +0200 Subject: Move `getElementFromSelector` & `getSelectorFromElement` to SelectorEngine (#36027) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move `getElementFromSelector` & getSelectorFromElement` inside selector-engine.js, in order to use SelectorEngine methods, avoiding raw querySelector usage * add `getMultipleElementsFromSelector` helper Co-authored-by: Julien Déramond --- js/src/util/component-functions.js | 5 +++-- js/src/util/index.js | 43 -------------------------------------- 2 files changed, 3 insertions(+), 45 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index 2298ac371..6896faf56 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -6,7 +6,8 @@ */ import EventHandler from '../dom/event-handler.js' -import { getElementFromSelector, isDisabled } from './index.js' +import { isDisabled } from './index.js' +import SelectorEngine from '../dom/selector-engine.js' const enableDismissTrigger = (component, method = 'hide') => { const clickEvent = `click.dismiss${component.EVENT_KEY}` @@ -21,7 +22,7 @@ const enableDismissTrigger = (component, method = 'hide') => { return } - const target = getElementFromSelector(this) || this.closest(`.${name}`) + const target = SelectorEngine.getElementFromSelector(this) || this.closest(`.${name}`) const instance = component.getOrCreateInstance(target) // Method argument is left, for Alert and only, as it doesn't implement the 'hide' method diff --git a/js/src/util/index.js b/js/src/util/index.js index ad99f85ed..b92eddba2 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -30,47 +30,6 @@ const getUID = prefix => { return prefix } -const getSelector = element => { - let selector = element.getAttribute('data-bs-target') - - if (!selector || selector === '#') { - let hrefAttribute = element.getAttribute('href') - - // The only valid content that could double as a selector are IDs or classes, - // so everything starting with `#` or `.`. If a "real" URL is used as the selector, - // `document.querySelector` will rightfully complain it is invalid. - // See https://github.com/twbs/bootstrap/issues/32273 - if (!hrefAttribute || (!hrefAttribute.includes('#') && !hrefAttribute.startsWith('.'))) { - return null - } - - // Just in case some CMS puts out a full URL with the anchor appended - if (hrefAttribute.includes('#') && !hrefAttribute.startsWith('#')) { - hrefAttribute = `#${hrefAttribute.split('#')[1]}` - } - - selector = hrefAttribute && hrefAttribute !== '#' ? hrefAttribute.trim() : null - } - - return selector -} - -const getSelectorFromElement = element => { - const selector = getSelector(element) - - if (selector) { - return document.querySelector(selector) ? selector : null - } - - return null -} - -const getElementFromSelector = element => { - const selector = getSelector(element) - - return selector ? document.querySelector(selector) : null -} - const getTransitionDurationFromElement = element => { if (!element) { return 0 @@ -316,10 +275,8 @@ export { executeAfterTransition, findShadowRoot, getElement, - getElementFromSelector, getjQuery, getNextActiveElement, - getSelectorFromElement, getTransitionDurationFromElement, getUID, isDisabled, -- cgit v1.2.3 From ef4e2daa48193463b36fdc297d79c6a002e4ee67 Mon Sep 17 00:00:00 2001 From: Pierre Souchay Date: Mon, 7 Nov 2022 13:43:06 +0100 Subject: Properly escape IDs in getSelector() to handle weird IDs (#35565) (#35566) --- js/src/util/index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index b92eddba2..8c6922173 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -9,6 +9,20 @@ const MAX_UID = 1_000_000 const MILLISECONDS_MULTIPLIER = 1000 const TRANSITION_END = 'transitionend' +/** + * Properly escape IDs selectors to handle weird IDs + * @param {string} selector + * @returns {string} + */ +const parseSelector = selector => { + if (selector && window.CSS && window.CSS.escape) { + // document.querySelector needs escaping to handle IDs (html5+) containing for instance / + selector = selector.replaceAll(/#([^\s"#']+)/g, (match, id) => '#' + CSS.escape(id)) + } + + return selector +} + // Shout-out Angus Croll (https://goo.gl/pxwQGp) const toType = object => { if (object === null || object === undefined) { @@ -76,7 +90,7 @@ const getElement = object => { } if (typeof object === 'string' && object.length > 0) { - return document.querySelector(object) + return document.querySelector(parseSelector(object)) } return null @@ -285,6 +299,7 @@ export { isVisible, noop, onDOMContentLoaded, + parseSelector, reflow, triggerTransitionEnd, toType -- cgit v1.2.3 From 0a484e758666c5ec9bb6e2b5c088de1e778d8fc8 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Fri, 11 Nov 2022 10:40:17 +0200 Subject: fix: change `replaceAll` usage introduced in #35566 (#37473) --- js/src/util/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index 8c6922173..b04fdc120 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -17,7 +17,7 @@ const TRANSITION_END = 'transitionend' const parseSelector = selector => { if (selector && window.CSS && window.CSS.escape) { // document.querySelector needs escaping to handle IDs (html5+) containing for instance / - selector = selector.replaceAll(/#([^\s"#']+)/g, (match, id) => '#' + CSS.escape(id)) + selector = selector.replace(/#([^\s"#']+)/g, (match, id) => '#' + CSS.escape(id)) } return selector -- cgit v1.2.3 From 5208dd10c4f43b304ebeb75dcf508e016515a248 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 12 Nov 2022 10:09:36 +0200 Subject: ESLint: enable prefer-template rule (#37484) --- js/src/util/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index b04fdc120..b3e577b10 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -17,7 +17,7 @@ const TRANSITION_END = 'transitionend' const parseSelector = selector => { if (selector && window.CSS && window.CSS.escape) { // document.querySelector needs escaping to handle IDs (html5+) containing for instance / - selector = selector.replace(/#([^\s"#']+)/g, (match, id) => '#' + CSS.escape(id)) + selector = selector.replace(/#([^\s"#']+)/g, (match, id) => `#${CSS.escape(id)}`) } return selector -- cgit v1.2.3 From 2fde88c20071f1e766703f78a25ebc431da9e1d8 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 13 Nov 2022 09:19:11 +0200 Subject: Use `Object.entries` in more places (#37482) --- js/src/util/config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/config.js b/js/src/util/config.js index f2d24b4ba..9417ab8f8 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -49,8 +49,7 @@ class Config { } _typeCheckConfig(config, configTypes = this.constructor.DefaultType) { - for (const property of Object.keys(configTypes)) { - const expectedTypes = configTypes[property] + for (const [property, expectedTypes] of Object.entries(configTypes)) { const value = config[property] const valueType = isElement(value) ? 'element' : toType(value) -- cgit v1.2.3 From 39589472f709ddf7d614ffd4f0ab1a50e542ac91 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 21 Nov 2022 20:15:33 +0200 Subject: Bump version to 5.2.3 --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/focustrap.js | 2 +- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index 342f8afc1..78279e056 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/backdrop.js + * Bootstrap (v5.2.3): util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index 798366b07..c2f99cceb 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/component-functions.js + * Bootstrap (v5.2.3): util/component-functions.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/config.js b/js/src/util/config.js index 119a3ea3d..1205905f7 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/config.js + * Bootstrap (v5.2.3): util/config.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 01ac76683..ef6916679 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/focustrap.js + * Bootstrap (v5.2.3): util/focustrap.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/index.js b/js/src/util/index.js index 7c2411665..297e57149 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/index.js + * Bootstrap (v5.2.3): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 6a9daa6ce..532869167 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/sanitizer.js + * Bootstrap (v5.2.3): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 421426d41..5cac7b6d1 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/scrollBar.js + * Bootstrap (v5.2.3): util/scrollBar.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 7fcd65588..7126360ce 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/swipe.js + * Bootstrap (v5.2.3): util/swipe.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index c6d52a50d..cf402fa3b 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.2): util/template-factory.js + * Bootstrap (v5.2.3): util/template-factory.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From cf9454caa00872899215603e5e036d9a824b1b11 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 24 Dec 2022 18:37:22 +0200 Subject: Release v5.3.0-alpha1 (#37661) * Bump version to 5.3.0-alpha1 * Dist * Add docs versions updates * Update note in homepage hero Co-authored-by: Mark Otto --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/focustrap.js | 2 +- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index ee560b85e..eab7d40eb 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/backdrop.js + * Bootstrap (v5.3.0-alpha1): util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index 15f2f8c52..f059cc825 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/component-functions.js + * Bootstrap (v5.3.0-alpha1): util/component-functions.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/config.js b/js/src/util/config.js index a37fe52a1..241ea966b 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/config.js + * Bootstrap (v5.3.0-alpha1): util/config.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 1736c4f7c..2f189585a 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/focustrap.js + * Bootstrap (v5.3.0-alpha1): util/focustrap.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/index.js b/js/src/util/index.js index 77de14d3a..cd23835c0 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/index.js + * Bootstrap (v5.3.0-alpha1): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 532869167..30fb3b1a1 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/sanitizer.js + * Bootstrap (v5.3.0-alpha1): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index f6bd9de31..7b01b3596 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/scrollBar.js + * Bootstrap (v5.3.0-alpha1): util/scrollBar.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index fe04a2437..834b02e67 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/swipe.js + * Bootstrap (v5.3.0-alpha1): util/swipe.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index 5046f0e31..82cd8b31c 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.2.3): util/template-factory.js + * Bootstrap (v5.3.0-alpha1): util/template-factory.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From ab049cd4a02650ca95d490217f93bd628f9295a6 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Wed, 22 Mar 2023 09:12:33 +0200 Subject: Remove version comment from JavaScript src files (#38294) --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/focustrap.js | 2 +- js/src/util/index.js | 2 +- js/src/util/sanitizer.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index eab7d40eb..c552aef43 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/backdrop.js + * Bootstrap util/backdrop.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index f059cc825..5eb59b4af 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/component-functions.js + * Bootstrap util/component-functions.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/config.js b/js/src/util/config.js index 241ea966b..95221c1ef 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/config.js + * Bootstrap util/config.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js index 2f189585a..158f3d184 100644 --- a/js/src/util/focustrap.js +++ b/js/src/util/focustrap.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/focustrap.js + * Bootstrap util/focustrap.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/index.js b/js/src/util/index.js index cd23835c0..68b8d8988 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/index.js + * Bootstrap util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 30fb3b1a1..af846a21e 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/sanitizer.js + * Bootstrap util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 7b01b3596..079c9108b 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/scrollBar.js + * Bootstrap util/scrollBar.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 834b02e67..33ca90d8a 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/swipe.js + * Bootstrap util/swipe.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index 82cd8b31c..bd827174b 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.3.0-alpha1): util/template-factory.js + * Bootstrap util/template-factory.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From 06f7c3b6c73580cd05b131bdab4d156a864d418c Mon Sep 17 00:00:00 2001 From: Hannah Issermann Date: Mon, 27 Mar 2023 11:10:25 +0200 Subject: Add js-docs shortcode to ensure consistency between doc and js code (#38316) Co-authored-by: XhmikosR --- js/src/util/sanitizer.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index af846a21e..5a07a67c1 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -16,8 +16,6 @@ const uriAttributes = new Set([ 'xlink:href' ]) -const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i - /** * A pattern that recognizes a commonly useful subset of URLs that are safe. * @@ -48,6 +46,9 @@ const allowedAttribute = (attribute, allowedAttributeList) => { .some(regex => regex.test(attributeName)) } +// js-docs-start allow-list +const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i + export const DefaultAllowlist = { // Global attributes allowed on any supplied element below. '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN], @@ -81,6 +82,7 @@ export const DefaultAllowlist = { u: [], ul: [] } +// js-docs-end allow-list export function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) { if (!unsafeHtml.length) { -- cgit v1.2.3 From ae43f0c48bf7acede8a325b24197001fe2b2f416 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 29 Mar 2023 20:49:30 +0300 Subject: Tweak and re-organize ESLint config (#38369) * Tweak and re-organize ESLint config * merge individual configs to the root config * enable more eslint-plugin-import rules * lint markdown files * Lint --- js/src/util/backdrop.js | 2 +- js/src/util/component-functions.js | 2 +- js/src/util/config.js | 2 +- js/src/util/scrollbar.js | 2 +- js/src/util/swipe.js | 2 +- js/src/util/template-factory.js | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index c552aef43..0d478e98d 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -6,8 +6,8 @@ */ import EventHandler from '../dom/event-handler.js' -import { execute, executeAfterTransition, getElement, reflow } from './index.js' import Config from './config.js' +import { execute, executeAfterTransition, getElement, reflow } from './index.js' /** * Constants diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js index 5eb59b4af..4be828f83 100644 --- a/js/src/util/component-functions.js +++ b/js/src/util/component-functions.js @@ -6,8 +6,8 @@ */ import EventHandler from '../dom/event-handler.js' -import { isDisabled } from './index.js' import SelectorEngine from '../dom/selector-engine.js' +import { isDisabled } from './index.js' const enableDismissTrigger = (component, method = 'hide') => { const clickEvent = `click.dismiss${component.EVENT_KEY}` diff --git a/js/src/util/config.js b/js/src/util/config.js index 95221c1ef..a2b4bfba0 100644 --- a/js/src/util/config.js +++ b/js/src/util/config.js @@ -5,8 +5,8 @@ * -------------------------------------------------------------------------- */ -import { isElement, toType } from './index.js' import Manipulator from '../dom/manipulator.js' +import { isElement, toType } from './index.js' /** * Class definition diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js index 079c9108b..413f178da 100644 --- a/js/src/util/scrollbar.js +++ b/js/src/util/scrollbar.js @@ -5,8 +5,8 @@ * -------------------------------------------------------------------------- */ -import SelectorEngine from '../dom/selector-engine.js' import Manipulator from '../dom/manipulator.js' +import SelectorEngine from '../dom/selector-engine.js' import { isElement } from './index.js' /** diff --git a/js/src/util/swipe.js b/js/src/util/swipe.js index 33ca90d8a..d2f708711 100644 --- a/js/src/util/swipe.js +++ b/js/src/util/swipe.js @@ -5,8 +5,8 @@ * -------------------------------------------------------------------------- */ -import Config from './config.js' import EventHandler from '../dom/event-handler.js' +import Config from './config.js' import { execute } from './index.js' /** diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index bd827174b..f73589bcc 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -5,10 +5,10 @@ * -------------------------------------------------------------------------- */ -import { DefaultAllowlist, sanitizeHtml } from './sanitizer.js' -import { execute, getElement, isElement } from './index.js' import SelectorEngine from '../dom/selector-engine.js' import Config from './config.js' +import { DefaultAllowlist, sanitizeHtml } from './sanitizer.js' +import { execute, getElement, isElement } from './index.js' /** * Constants -- cgit v1.2.3 From d5dee316f7f53521e7ece23f10200fe566b9c565 Mon Sep 17 00:00:00 2001 From: Kyle Tsang <6854874+kyletsang@users.noreply.github.com> Date: Sun, 30 Apr 2023 14:33:09 -0700 Subject: Update URL sanitizer to allow more protocols (#38531) Co-authored-by: XhmikosR --- js/src/util/sanitizer.js | 78 ++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 42 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 5a07a67c1..d2b08082c 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -5,47 +5,6 @@ * -------------------------------------------------------------------------- */ -const uriAttributes = new Set([ - 'background', - 'cite', - 'href', - 'itemtype', - 'longdesc', - 'poster', - 'src', - 'xlink:href' -]) - -/** - * A pattern that recognizes a commonly useful subset of URLs that are safe. - * - * Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts - */ -const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^#&/:?]*(?:[#/?]|$))/i - -/** - * A pattern that matches safe data URLs. Only matches image, video and audio types. - * - * Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts - */ -const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i - -const allowedAttribute = (attribute, allowedAttributeList) => { - const attributeName = attribute.nodeName.toLowerCase() - - if (allowedAttributeList.includes(attributeName)) { - if (uriAttributes.has(attributeName)) { - return Boolean(SAFE_URL_PATTERN.test(attribute.nodeValue) || DATA_URL_PATTERN.test(attribute.nodeValue)) - } - - return true - } - - // Check if a regular expression validates the attribute. - return allowedAttributeList.filter(attributeRegex => attributeRegex instanceof RegExp) - .some(regex => regex.test(attributeName)) -} - // js-docs-start allow-list const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i @@ -84,6 +43,42 @@ export const DefaultAllowlist = { } // js-docs-end allow-list +const uriAttributes = new Set([ + 'background', + 'cite', + 'href', + 'itemtype', + 'longdesc', + 'poster', + 'src', + 'xlink:href' +]) + +/** + * A pattern that recognizes URLs that are safe wrt. XSS in URL navigation + * contexts. + * + * Shout-out to Angular https://github.com/angular/angular/blob/15.2.8/packages/core/src/sanitization/url_sanitizer.ts#L38 + */ +// eslint-disable-next-line unicorn/better-regex +const SAFE_URL_PATTERN = /^(?!javascript:)(?:[a-z0-9+.-]+:|[^&:/?#]*(?:[/?#]|$))/i + +const allowedAttribute = (attribute, allowedAttributeList) => { + const attributeName = attribute.nodeName.toLowerCase() + + if (allowedAttributeList.includes(attributeName)) { + if (uriAttributes.has(attributeName)) { + return Boolean(SAFE_URL_PATTERN.test(attribute.nodeValue)) + } + + return true + } + + // Check if a regular expression validates the attribute. + return allowedAttributeList.filter(attributeRegex => attributeRegex instanceof RegExp) + .some(regex => regex.test(attributeName)) +} + export function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) { if (!unsafeHtml.length) { return unsafeHtml @@ -102,7 +97,6 @@ export function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) { if (!Object.keys(allowList).includes(elementName)) { element.remove() - continue } -- cgit v1.2.3 From b9f92d70c98e6254893dc326c414f275577f0687 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Wed, 15 Nov 2023 08:38:27 +0100 Subject: Allow `
`, `
` and `
` in JS sanitizer (#39376) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Julien Déramond --- js/src/util/sanitizer.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'js/src/util') diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index d2b08082c..3d2883aff 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -17,7 +17,10 @@ export const DefaultAllowlist = { br: [], col: [], code: [], + dd: [], div: [], + dl: [], + dt: [], em: [], hr: [], h1: [], -- cgit v1.2.3 From 40c6d8a4bc9813e5c54cf7753b1f0785fed92715 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 21:46:52 +0200 Subject: Build(deps-dev): Bump eslint-config-xo from 0.43.1 to 0.44.0 (#39651) * Build(deps-dev): Bump eslint-config-xo from 0.43.1 to 0.44.0 Bumps [eslint-config-xo](https://github.com/xojs/eslint-config-xo) from 0.43.1 to 0.44.0. - [Release notes](https://github.com/xojs/eslint-config-xo/releases) - [Commits](https://github.com/xojs/eslint-config-xo/compare/v0.43.1...v0.44.0) --- updated-dependencies: - dependency-name: eslint-config-xo dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Update .eslintrc.json * Update .eslintrc.json * autofix --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: XhmikosR --- js/src/util/backdrop.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'js/src/util') diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index 0d478e98d..82b54900e 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -7,7 +7,9 @@ import EventHandler from '../dom/event-handler.js' import Config from './config.js' -import { execute, executeAfterTransition, getElement, reflow } from './index.js' +import { + execute, executeAfterTransition, getElement, reflow +} from './index.js' /** * Constants -- cgit v1.2.3 From 4219af2c0ef1bccb0408128ef4d34f3cea7a6da5 Mon Sep 17 00:00:00 2001 From: Caleb Albritton Date: Mon, 18 Mar 2024 04:32:49 -0400 Subject: Fix broken comment link for reflow hack (#39791) --- js/src/util/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index 68b8d8988..2adf19e3b 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -170,7 +170,7 @@ const noop = () => {} * @param {HTMLElement} element * @return void * - * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation + * @see https://www.harrytheo.com/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation */ const reflow = element => { element.offsetHeight // eslint-disable-line no-unused-expressions -- cgit v1.2.3 From 16d80a4ff7b42da57215783cc8ff85d6f0627630 Mon Sep 17 00:00:00 2001 From: Nathan Sarang-Walters Date: Thu, 18 Jul 2024 22:05:21 -0700 Subject: Fix `this` reference for JavaScript functions (#38725) --- js/src/util/index.js | 2 +- js/src/util/template-factory.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index 2adf19e3b..c271cc536 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -223,7 +223,7 @@ const defineJQueryPlugin = plugin => { } const execute = (possibleCallback, args = [], defaultValue = possibleCallback) => { - return typeof possibleCallback === 'function' ? possibleCallback(...args) : defaultValue + return typeof possibleCallback === 'function' ? possibleCallback.call(...args) : defaultValue } const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => { diff --git a/js/src/util/template-factory.js b/js/src/util/template-factory.js index f73589bcc..6d1532b4d 100644 --- a/js/src/util/template-factory.js +++ b/js/src/util/template-factory.js @@ -143,7 +143,7 @@ class TemplateFactory extends Config { } _resolvePossibleFunction(arg) { - return execute(arg, [this]) + return execute(arg, [undefined, this]) } _putElementInTemplate(element, templateElement) { -- cgit v1.2.3