From 86de1d3875d50fdea6fac0a5353a8da3804366ba Mon Sep 17 00:00:00 2001 From: Johann-S Date: Fri, 1 Mar 2019 14:52:43 +0100 Subject: [PATCH] fix jquery detection --- js/src/index.js | 18 ------------------ js/src/util.js | 18 ++++++++++++++++++ js/tests/unit/util.js | 5 +++++ 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/js/src/index.js b/js/src/index.js index c4a4d4b1f4..327de242b2 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -1,4 +1,3 @@ -import $ from 'jquery' import Alert from './alert' import Button from './button' import Carousel from './carousel' @@ -19,23 +18,6 @@ import Util from './util' * -------------------------------------------------------------------------- */ -(() => { - if (typeof $ === 'undefined') { - throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.') - } - - const version = $.fn.jquery.split(' ')[0].split('.') - const minMajor = 1 - const ltMajor = 2 - const minMinor = 9 - const minPatch = 1 - const maxMajor = 4 - - if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) { - throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0') - } -})() - export { Util, Alert, diff --git a/js/src/util.js b/js/src/util.js index d459aa266b..43121b4c9e 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -169,9 +169,27 @@ const Util = { } return Util.findShadowRoot(element.parentNode) + }, + + jQueryDetection() { + if (typeof $ === 'undefined') { + throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.') + } + + const version = $.fn.jquery.split(' ')[0].split('.') + const minMajor = 1 + const ltMajor = 2 + const minMinor = 9 + const minPatch = 1 + const maxMajor = 4 + + if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) { + throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0') + } } } +Util.jQueryDetection() setTransitionEndSupport() export default Util diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js index 858fee6f4d..e7e22cea97 100644 --- a/js/tests/unit/util.js +++ b/js/tests/unit/util.js @@ -160,4 +160,9 @@ $(function () { sandbox.restore() } }) + + QUnit.test('Util.jQueryDetection should detect jQuery', function (assert) { + assert.expect(0) + Util.jQueryDetection() + }) })