From 536c53c16cafcde3250e8d062aeb04c1590c1418 Mon Sep 17 00:00:00 2001 From: nlipka Date: Thu, 18 Feb 2021 11:37:20 +0100 Subject: add some space --- js/src/alert.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 3a018a638..8fc3f12a8 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -126,6 +126,7 @@ class Alert extends BaseComponent { * Data Api implementation * ------------------------------------------------------------------------ */ + EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert())) /** -- cgit v1.2.3 From 48a95f7280735d6f8962fe8b17975b03e351710c Mon Sep 17 00:00:00 2001 From: alpadev <2838324+alpadev@users.noreply.github.com> Date: Tue, 2 Mar 2021 15:55:44 +0100 Subject: refactor: use a Map instead of an Object in dom/data (#32180) Co-authored-by: XhmikosR Co-authored-by: Rohit Sharma --- js/src/alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 8fc3f12a8..d10e6c8da 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -98,7 +98,7 @@ class Alert extends BaseComponent { static jQueryInterface(config) { return this.each(function () { - let data = Data.getData(this, DATA_KEY) + let data = Data.get(this, DATA_KEY) if (!data) { data = new Alert(this) -- cgit v1.2.3 From 220139a89ffc3864bbb6e1b35471667318eadc1f Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 23 Mar 2021 18:26:54 +0200 Subject: Release v5.0.0-beta3 (#33439) --- js/src/alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index d10e6c8da..a25c44ec3 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-beta2): alert.js + * Bootstrap (v5.0.0-beta3): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From bf0936748602c8109fd916c64b4560799fa1c3f8 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 5 May 2021 22:32:12 +0300 Subject: Release v5.0.0 (#33647) * Bump version to 5.0.0 * Fix npm tag * Dist --- js/src/alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index a25c44ec3..884041580 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-beta3): alert.js + * Bootstrap (v5.0.0): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From 90b1a6907ed7bb3397fe6bd223f09eb12122d7a3 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Sun, 11 Apr 2021 02:27:18 +0300 Subject: Merge js-components 'transitionend' listener callbacks into one method --- js/src/alert.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 884041580..8d0838737 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -7,9 +7,7 @@ import { defineJQueryPlugin, - emulateTransitionEnd, - getElementFromSelector, - getTransitionDurationFromElement + getElementFromSelector } from './util/index' import Data from './dom/data' import EventHandler from './dom/event-handler' @@ -75,15 +73,8 @@ class Alert extends BaseComponent { _removeElement(element) { element.classList.remove(CLASS_NAME_SHOW) - if (!element.classList.contains(CLASS_NAME_FADE)) { - this._destroyElement(element) - return - } - - const transitionDuration = getTransitionDurationFromElement(element) - - EventHandler.one(element, 'transitionend', () => this._destroyElement(element)) - emulateTransitionEnd(element, transitionDuration) + const isAnimated = element.classList.contains(CLASS_NAME_FADE) + this._queueCallback(() => this._destroyElement(element), element, isAnimated) } _destroyElement(element) { -- cgit v1.2.3 From 9fe36edf683af02574bf6bbd6c9b27de93bd31b1 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Tue, 11 May 2021 10:49:30 +0300 Subject: Extract static `DATA_KEY` & `EVENT_KEY` to base-component (#33635) * Force each plugin that extends base-components to implement a static method `NAME()` * Remove redundant `NAME` argument from 'Utils.defineJQueryPlugin' & fix test --- js/src/alert.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 8d0838737..db58d7426 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -43,8 +43,8 @@ const CLASS_NAME_SHOW = 'show' class Alert extends BaseComponent { // Getters - static get DATA_KEY() { - return DATA_KEY + static get NAME() { + return NAME } // Public @@ -127,6 +127,6 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDi * add .Alert to jQuery only if jQuery is present */ -defineJQueryPlugin(NAME, Alert) +defineJQueryPlugin(Alert) export default Alert -- cgit v1.2.3 From 58b1be927f43c779377e478df2d119f2ddf956ca Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 13 May 2021 19:22:20 +0300 Subject: Release v5.0.1 (#33972) * Bump version to 5.0.1. * Dist --- js/src/alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index db58d7426..87cc7e731 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0): alert.js + * Bootstrap (v5.0.1): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From 544d9ac3cf5b7a501524c1bab9570f4b46b8e7e4 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Tue, 25 May 2021 18:30:38 +0300 Subject: Change `element.parentNode.removeChild(element)` to `element.remove()` (#34071) --- js/src/alert.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 87cc7e731..679a90cdb 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -78,9 +78,7 @@ class Alert extends BaseComponent { } _destroyElement(element) { - if (element.parentNode) { - element.parentNode.removeChild(element) - } + element.remove() EventHandler.trigger(element, EVENT_CLOSED) } -- cgit v1.2.3 From c98657b8303150bfda3bdea750055b83a29b27a3 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Thu, 3 Jun 2021 18:53:27 +0300 Subject: Add `getOrCreateInstance` method in base-component (#33276) Co-authored-by: Rohit Sharma Co-authored-by: XhmikosR --- js/src/alert.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 679a90cdb..e5e5e2a5d 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -9,7 +9,6 @@ import { defineJQueryPlugin, getElementFromSelector } from './util/index' -import Data from './dom/data' import EventHandler from './dom/event-handler' import BaseComponent from './base-component' @@ -87,11 +86,7 @@ class Alert extends BaseComponent { static jQueryInterface(config) { return this.each(function () { - let data = Data.get(this, DATA_KEY) - - if (!data) { - data = new Alert(this) - } + const data = Alert.getOrCreateInstance(this) if (config === 'close') { data[config](this) -- cgit v1.2.3 From 688bce4fa695cc360a0d084e34f029b0c192b223 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 22 Jun 2021 21:29:16 +0300 Subject: Release v5.0.2 (#34276) * Bump version to v5.0.2. * Dist --- js/src/alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index e5e5e2a5d..75dbec71b 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.1): alert.js + * Bootstrap (v5.0.2): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3 From 70dd7f6ff51a0bd3b09b0de3640b0517b8b08f64 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Mon, 28 Jun 2021 16:34:47 +0300 Subject: Changes to Alert component to match the others (#33402) Alert.js: Refactor code to match the other components * Use this._element * Remove handleDismiss method and keep its functionality on event * Change JqueryInterface to be more generic * Correct docs to be aligned with code, and add undocumented functionality * Update alerts.md Co-authored-by: XhmikosR --- js/src/alert.js | 69 ++++++++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 37 deletions(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 75dbec71b..0bbe62af5 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -7,7 +7,8 @@ import { defineJQueryPlugin, - getElementFromSelector + getElementFromSelector, + isDisabled } from './util/index' import EventHandler from './dom/event-handler' import BaseComponent from './base-component' @@ -48,38 +49,24 @@ class Alert extends BaseComponent { // Public - close(element) { - const rootElement = element ? this._getRootElement(element) : this._element - const customEvent = this._triggerCloseEvent(rootElement) + close() { + const closeEvent = EventHandler.trigger(this._element, EVENT_CLOSE) - if (customEvent === null || customEvent.defaultPrevented) { + if (closeEvent.defaultPrevented) { return } - this._removeElement(rootElement) - } - - // Private - - _getRootElement(element) { - return getElementFromSelector(element) || element.closest(`.${CLASS_NAME_ALERT}`) - } + this._element.classList.remove(CLASS_NAME_SHOW) - _triggerCloseEvent(element) { - return EventHandler.trigger(element, EVENT_CLOSE) + const isAnimated = this._element.classList.contains(CLASS_NAME_FADE) + this._queueCallback(() => this._destroyElement(), this._element, isAnimated) } - _removeElement(element) { - element.classList.remove(CLASS_NAME_SHOW) - - const isAnimated = element.classList.contains(CLASS_NAME_FADE) - this._queueCallback(() => this._destroyElement(element), element, isAnimated) - } - - _destroyElement(element) { - element.remove() - - EventHandler.trigger(element, EVENT_CLOSED) + // Private + _destroyElement() { + this._element.remove() + EventHandler.trigger(this._element, EVENT_CLOSED) + this.dispose() } // Static @@ -88,20 +75,16 @@ class Alert extends BaseComponent { return this.each(function () { const data = Alert.getOrCreateInstance(this) - if (config === 'close') { - data[config](this) + if (typeof config !== 'string') { + return } - }) - } - static handleDismiss(alertInstance) { - return function (event) { - if (event) { - event.preventDefault() + if (data[config] === undefined || config.startsWith('_') || config === 'constructor') { + throw new TypeError(`No method named "${config}"`) } - alertInstance.close(this) - } + data[config](this) + }) } } @@ -111,7 +94,19 @@ class Alert extends BaseComponent { * ------------------------------------------------------------------------ */ -EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert())) +EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, function (event) { + if (['A', 'AREA'].includes(this.tagName)) { + event.preventDefault() + } + + if (isDisabled(this)) { + return + } + + const target = getElementFromSelector(this) || this.closest(`.${CLASS_NAME_ALERT}`) + const alert = Alert.getOrCreateInstance(target) + alert.close() +}) /** * ------------------------------------------------------------------------ -- cgit v1.2.3 From 4bfd8a2cbcb10610b4078cefa45756b4a96301a0 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Wed, 28 Jul 2021 17:39:32 +0300 Subject: Use a streamlined way to trigger component dismiss (#34170) * use a streamlined way to trigger component dismiss * add documentation Co-authored-by: XhmikosR --- js/src/alert.js | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 0bbe62af5..66c0bee0f 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -5,13 +5,10 @@ * -------------------------------------------------------------------------- */ -import { - defineJQueryPlugin, - getElementFromSelector, - isDisabled -} from './util/index' +import { defineJQueryPlugin } from './util/index' import EventHandler from './dom/event-handler' import BaseComponent from './base-component' +import { enableDismissTrigger } from './util/component-functions' /** * ------------------------------------------------------------------------ @@ -22,15 +19,9 @@ import BaseComponent from './base-component' const NAME = 'alert' const DATA_KEY = 'bs.alert' const EVENT_KEY = `.${DATA_KEY}` -const DATA_API_KEY = '.data-api' - -const SELECTOR_DISMISS = '[data-bs-dismiss="alert"]' const EVENT_CLOSE = `close${EVENT_KEY}` const EVENT_CLOSED = `closed${EVENT_KEY}` -const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}` - -const CLASS_NAME_ALERT = 'alert' const CLASS_NAME_FADE = 'fade' const CLASS_NAME_SHOW = 'show' @@ -94,20 +85,7 @@ class Alert extends BaseComponent { * ------------------------------------------------------------------------ */ -EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, function (event) { - if (['A', 'AREA'].includes(this.tagName)) { - event.preventDefault() - } - - if (isDisabled(this)) { - return - } - - const target = getElementFromSelector(this) || this.closest(`.${CLASS_NAME_ALERT}`) - const alert = Alert.getOrCreateInstance(target) - alert.close() -}) - +enableDismissTrigger(Alert, 'close') /** * ------------------------------------------------------------------------ * jQuery -- cgit v1.2.3 From f20fece3a8cdd0e76a42c2737524b7652bf54d26 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 4 Aug 2021 18:41:51 +0300 Subject: Prepare v5.1.0. (#34674) --- js/src/alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src/alert.js') diff --git a/js/src/alert.js b/js/src/alert.js index 66c0bee0f..601078fc6 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,6 +1,6 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.2): alert.js + * Bootstrap (v5.1.0): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ -- cgit v1.2.3