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/index.js') 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/index.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'js/src/util/index.js') 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 } -- 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/index.js') 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 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/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) * -------------------------------------------------------------------------- */ -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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}` -- 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/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) * -------------------------------------------------------------------------- */ -- 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/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) * -------------------------------------------------------------------------- */ -- 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/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) * -------------------------------------------------------------------------- */ -- 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 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'js/src/util/index.js') 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) => { -- 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/index.js | 43 ------------------------------------------- 1 file changed, 43 deletions(-) (limited to 'js/src/util/index.js') 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/index.js') 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/index.js') 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/index.js') 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 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/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) * -------------------------------------------------------------------------- */ -- 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/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) * -------------------------------------------------------------------------- */ -- 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/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) * -------------------------------------------------------------------------- */ -- 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/index.js') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/util/index.js') 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) => { -- cgit v1.2.3