0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Add Util.jQuery which will detect jQuery instead of relying on global $ (#24513)

This commit is contained in:
Johann-S 2017-10-23 09:35:27 +02:00 committed by XhmikosR
parent 0d71a8a738
commit 1487c3a994
14 changed files with 38 additions and 11 deletions

View File

@ -189,6 +189,6 @@ const Alert = (() => {
return Alert
})($)
})(Util.jQuery)
export default Alert

View File

@ -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

View File

@ -519,6 +519,6 @@ const Carousel = (() => {
return Carousel
})($)
})(Util.jQuery)
export default Carousel

View File

@ -404,6 +404,6 @@ const Collapse = (() => {
return Collapse
})($)
})(Util.jQuery)
export default Collapse

View File

@ -445,6 +445,6 @@ const Dropdown = (() => {
return Dropdown
})($, Popper)
})(Util.jQuery, Popper)
export default Dropdown

View File

@ -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,

View File

@ -585,6 +585,6 @@ const Modal = (() => {
return Modal
})($)
})(Util.jQuery)
export default Modal

View File

@ -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

View File

@ -335,6 +335,6 @@ const ScrollSpy = (() => {
return ScrollSpy
})($)
})(Util.jQuery)
export default ScrollSpy

View File

@ -282,6 +282,6 @@ const Tab = (() => {
return Tab
})($)
})(Util.jQuery)
export default Tab

View File

@ -728,6 +728,6 @@ const Tooltip = (() => {
return Tooltip
})($, Popper)
})(Util.jQuery, Popper)
export default Tooltip

View File

@ -154,6 +154,10 @@ const Util = (() => {
}
}
}
},
get jQuery() {
return window.jQuery || window.$
}
}

View File

@ -119,6 +119,7 @@
<script src="unit/tab.js"></script>
<script src="unit/tooltip.js"></script>
<script src="unit/popover.js"></script>
<script src="unit/util.js"></script>
</head>
<body>
<div id="qunit-container">

19
js/tests/unit/util.js Normal file
View File

@ -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
})
})