diff options
| author | Johann-S <[email protected]> | 2017-08-23 12:03:50 +0200 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-02-20 22:05:45 +0200 |
| commit | 2970d14dd91bf1f5f236766c856e81c297fa1390 (patch) | |
| tree | 36e6b14473bd1973e2fcf44a00badad0e645dfc3 /js/src | |
| parent | a3398fffd6e5b73a6a2cc2a1fc454ab199b2bf82 (diff) | |
| download | bootstrap-2970d14dd91bf1f5f236766c856e81c297fa1390.tar.xz bootstrap-2970d14dd91bf1f5f236766c856e81c297fa1390.zip | |
Remove jQuery from alert.js and add .alert only if jQuery is available
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/alert.js | 27 | ||||
| -rw-r--r-- | js/src/dom/data.js | 6 | ||||
| -rw-r--r-- | js/src/dom/eventHandler.js | 5 | ||||
| -rw-r--r-- | js/src/dom/selectorEngine.js | 11 |
4 files changed, 21 insertions, 28 deletions
diff --git a/js/src/alert.js b/js/src/alert.js index 5e99f6d01..c530b2996 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -85,8 +85,7 @@ class Alert { let parent = false if (selector) { - const tmpSelected = SelectorEngine.find(selector) - parent = tmpSelected[0] + parent = SelectorEngine.find(selector)[0] } if (!parent) { @@ -136,16 +135,6 @@ class Alert { } }) } - - static _handleDismiss(alertInstance) { - return function (event) { - if (event) { - event.preventDefault() - } - - alertInstance.close(this) - } - } } /** @@ -159,13 +148,17 @@ EventHandler.on(document, Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleD * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ + * add .alert to jQuery only if jQuery is present */ -$.fn[NAME] = Alert._jQueryInterface -$.fn[NAME].Constructor = Alert -$.fn[NAME].noConflict = () => { - $.fn[NAME] = JQUERY_NO_CONFLICT - return Alert._jQueryInterface +if (typeof window.$ !== 'undefined' || typeof window.jQuery !== 'undefined') { + const $ = window.$ || window.jQuery + $.fn[NAME] = Alert._jQueryInterface + $.fn[NAME].Constructor = Alert + $.fn[NAME].noConflict = () => { + $.fn[NAME] = JQUERY_NO_CONFLICT + return Alert._jQueryInterface + } } export default Alert diff --git a/js/src/dom/data.js b/js/src/dom/data.js index bbe807aac..51ebb8d3f 100644 --- a/js/src/dom/data.js +++ b/js/src/dom/data.js @@ -10,7 +10,7 @@ const mapData = (() => { return { set(element, key, data) { let id - if (element.key === undefined) { + if (typeof element.key === 'undefined') { element.key = { key, id @@ -20,14 +20,14 @@ const mapData = (() => { storeData[id] = data }, get(element, key) { - if (element.key === undefined || element.key !== key) { + if (typeof element.key === 'undefined' || element.key !== key) { return null } const keyProperties = element.key return storeData[keyProperties.id] }, delete(element, key) { - if (element.key === undefined || element.key !== key) { + if (typeof element.key === 'undefined' || element.key !== key) { return } const keyProperties = element.key diff --git a/js/src/dom/eventHandler.js b/js/src/dom/eventHandler.js index ae3ccafad..bcaefd59c 100644 --- a/js/src/dom/eventHandler.js +++ b/js/src/dom/eventHandler.js @@ -19,7 +19,8 @@ if (typeof window.CustomEvent !== 'function') { window.CustomEvent = (event, params) => { params = params || { bubbles: false, - cancelable: false + cancelable: false, + detail: null } const evt = document.createEvent('CustomEvent') evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail) @@ -101,6 +102,8 @@ function bootstrapDelegationHandler(selector, fn) { } } } + // To please ESLint + return null } } diff --git a/js/src/dom/selectorEngine.js b/js/src/dom/selectorEngine.js index 1b33bf62d..f6f3fe82f 100644 --- a/js/src/dom/selectorEngine.js +++ b/js/src/dom/selectorEngine.js @@ -16,9 +16,8 @@ if (!Element.prototype.matches) { } // closest polyfill (see: https://mzl.la/2vXggaI) -let fnClosest = null if (!Element.prototype.closest) { - fnClosest = (element, selector) => { + Element.prototype.closest = (element, selector) => { let ancestor = element if (!document.documentElement.contains(element)) { return null @@ -34,12 +33,10 @@ if (!Element.prototype.closest) { return null } -} else { - fnClosest = (element, selector) => { - return element.closest(selector) - } } +const fnClosest = Element.prototype.closest + const SelectorEngine = { matches(element, selector) { return fnMatches.call(element, selector) @@ -59,7 +56,7 @@ const SelectorEngine = { }, closest(element, selector) { - return fnClosest(element, selector) + return fnClosest.call(element, selector) } } |
