diff options
| author | Johann-S <[email protected]> | 2019-08-02 15:51:05 +0200 |
|---|---|---|
| committer | Johann-S <[email protected]> | 2019-08-02 16:50:05 +0200 |
| commit | 8b2b490f9b58a02494fe8567d6ce5b9c11a9bf65 (patch) | |
| tree | fca5d7d55bb5f2932eda48f4594b4a839b0a8987 /js/src/util | |
| parent | 1ebb8e7d9b4bd52c7fc088aeaec12ab9bcb240c6 (diff) | |
| download | bootstrap-8b2b490f9b58a02494fe8567d6ce5b9c11a9bf65.tar.xz bootstrap-8b2b490f9b58a02494fe8567d6ce5b9c11a9bf65.zip | |
add a way to disable jQuery detection
Diffstat (limited to 'js/src/util')
| -rw-r--r-- | js/src/util/index.js | 13 | ||||
| -rw-r--r-- | js/src/util/index.spec.js | 33 |
2 files changed, 44 insertions, 2 deletions
diff --git a/js/src/util/index.js b/js/src/util/index.js index 537b391dc..746ee608b 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -8,7 +8,6 @@ const MAX_UID = 1000000 const MILLISECONDS_MULTIPLIER = 1000 const TRANSITION_END = 'transitionend' -const { jQuery } = window // Shoutout AngusCroll (https://goo.gl/pxwQGp) const toType = obj => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()) @@ -176,8 +175,18 @@ const noop = () => function () {} const reflow = element => element.offsetHeight +const getjQuery = () => { + const { jQuery } = window + + if (jQuery && !document.body.hasAttribute('data-no-jquery')) { + return jQuery + } + + return null +} + export { - jQuery, + getjQuery, TRANSITION_END, getUID, getSelectorFromElement, diff --git a/js/src/util/index.spec.js b/js/src/util/index.spec.js index b667c270e..9512c2fe0 100644 --- a/js/src/util/index.spec.js +++ b/js/src/util/index.spec.js @@ -346,4 +346,37 @@ describe('Util', () => { expect(Util.reflow(div)).toEqual(0) }) }) + + describe('getjQuery', () => { + const fakejQuery = { trigger() {} } + + beforeEach(() => { + Object.defineProperty(window, 'jQuery', { + value: fakejQuery, + writable: true + }) + }) + + afterEach(() => { + window.jQuery = undefined + }) + + it('should return jQuery object when present', () => { + expect(Util.getjQuery()).toEqual(fakejQuery) + }) + + it('should not return jQuery object when present if data-no-jquery', () => { + document.body.setAttribute('data-no-jquery', '') + + expect(window.jQuery).toEqual(fakejQuery) + expect(Util.getjQuery()).toEqual(null) + + document.body.removeAttribute('data-no-jquery') + }) + + it('should not return jQuery if not present', () => { + window.jQuery = undefined + expect(Util.getjQuery()).toEqual(null) + }) + }) }) |
