diff --git a/js/src/alert.js b/js/src/alert.js index 420aa84a30..2b967145f6 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -189,6 +189,6 @@ const Alert = (() => { return Alert -})($) +})(Util.jQuery) export default Alert diff --git a/js/src/button.js b/js/src/button.js index 9227da9516..87e724346f 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -1,4 +1,6 @@ import $ from 'jquery' +import Util from './util' + /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.2): button.js @@ -182,6 +184,6 @@ const Button = (() => { return Button -})($) +})(Util.jQuery) export default Button diff --git a/js/src/carousel.js b/js/src/carousel.js index 964f7fda6e..b5cbf98b48 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -519,6 +519,6 @@ const Carousel = (() => { return Carousel -})($) +})(Util.jQuery) export default Carousel diff --git a/js/src/collapse.js b/js/src/collapse.js index 8e84d7b59e..9a21eb7d81 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -404,6 +404,6 @@ const Collapse = (() => { return Collapse -})($) +})(Util.jQuery) export default Collapse diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 8fdddd6897..48f87c5aa1 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -445,6 +445,6 @@ const Dropdown = (() => { return Dropdown -})($, Popper) +})(Util.jQuery, Popper) export default Dropdown diff --git a/js/src/index.js b/js/src/index.js index f30b94c576..1697a709b7 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -33,7 +33,7 @@ import Util from './util' 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.jQuery) export { Util, diff --git a/js/src/modal.js b/js/src/modal.js index 07fdc9f4fc..cb7bef0ce3 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -585,6 +585,6 @@ const Modal = (() => { return Modal -})($) +})(Util.jQuery) export default Modal diff --git a/js/src/popover.js b/js/src/popover.js index ff697d85ac..28cb511fc8 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -1,5 +1,6 @@ import $ from 'jquery' import Tooltip from './tooltip' +import Util from './util' /** @@ -189,6 +190,6 @@ const Popover = (() => { return Popover -})($) +})(Util.jQuery) export default Popover diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index a0e24dd229..12667cc957 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -335,6 +335,6 @@ const ScrollSpy = (() => { return ScrollSpy -})($) +})(Util.jQuery) export default ScrollSpy diff --git a/js/src/tab.js b/js/src/tab.js index 982121cc00..f1d9ec0c82 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -282,6 +282,6 @@ const Tab = (() => { return Tab -})($) +})(Util.jQuery) export default Tab diff --git a/js/src/tooltip.js b/js/src/tooltip.js index ee721a19d0..39ef2594b9 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -728,6 +728,6 @@ const Tooltip = (() => { return Tooltip -})($, Popper) +})(Util.jQuery, Popper) export default Tooltip diff --git a/js/src/util.js b/js/src/util.js index 16d114b1ab..e3e7797931 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -154,6 +154,10 @@ const Util = (() => { } } } + }, + + get jQuery() { + return window.jQuery || window.$ } } diff --git a/js/tests/index.html b/js/tests/index.html index 2383fce6e6..0385b8a2ba 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -119,6 +119,7 @@ +
diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js new file mode 100644 index 0000000000..c3412041eb --- /dev/null +++ b/js/tests/unit/util.js @@ -0,0 +1,19 @@ +$(function () { + 'use strict' + + QUnit.module('Util') + + QUnit.test('Util.jQuery should find window.jQuery if window.$ is not available', function (assert) { + assert.expect(1) + delete window.$ + assert.strictEqual(Util.jQuery, window.jQuery) + window.$ = Util.jQuery + }) + + QUnit.test('Util.jQuery should find window.$ if window.jQuery is not available', function (assert) { + assert.expect(1) + delete window.jQuery + assert.strictEqual(Util.jQuery, window.$) + window.jQuery = Util.jQuery + }) +})