From 1487c3a9947b0eb55c61b5d93ff9f0c69a812aeb Mon Sep 17 00:00:00 2001 From: Johann-S Date: Mon, 23 Oct 2017 09:35:27 +0200 Subject: Add `Util.jQuery` which will detect jQuery instead of relying on global `$` (#24513) --- js/src/alert.js | 2 +- js/src/button.js | 4 +++- js/src/carousel.js | 2 +- js/src/collapse.js | 2 +- js/src/dropdown.js | 2 +- js/src/index.js | 2 +- js/src/modal.js | 2 +- js/src/popover.js | 3 ++- js/src/scrollspy.js | 2 +- js/src/tab.js | 2 +- js/src/tooltip.js | 2 +- js/src/util.js | 4 ++++ js/tests/index.html | 1 + js/tests/unit/util.js | 19 +++++++++++++++++++ 14 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 js/tests/unit/util.js (limited to 'js') diff --git a/js/src/alert.js b/js/src/alert.js index 420aa84a3..2b967145f 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 9227da951..87e724346 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 964f7fda6..b5cbf98b4 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 8e84d7b59..9a21eb7d8 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 8fdddd689..48f87c5aa 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 f30b94c57..1697a709b 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 07fdc9f4f..cb7bef0ce 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 ff697d85a..28cb511fc 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 a0e24dd22..12667cc95 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 982121cc0..f1d9ec0c8 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 ee721a19d..39ef2594b 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 16d114b1a..e3e779793 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 2383fce6e..0385b8a2b 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 000000000..c3412041e --- /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 + }) +}) -- cgit v1.2.3 From ca4ad8bee8000617c2ae1a08afe7af1103058776 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 23 Oct 2017 10:45:27 +0300 Subject: Clean up transitionEnd properties. (#24511) We don't support Opera 12, and Firefox's property was the unprefixed one. --- js/src/util.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'js') diff --git a/js/src/util.js b/js/src/util.js index e3e779793..1fa55494e 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -22,8 +22,6 @@ const Util = (() => { const TransitionEndEvent = { WebkitTransition : 'webkitTransitionEnd', - MozTransition : 'transitionend', - OTransition : 'oTransitionEnd otransitionend', transition : 'transitionend' } -- cgit v1.2.3 From 62fbb23ee61999e362cd8ade6073732a46466077 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 24 Oct 2017 10:12:45 +0200 Subject: Change Rollup config to wrap our dist files with jQuery instead of $ --- js/src/alert.js | 4 ++-- js/src/button.js | 5 ++--- js/src/carousel.js | 4 ++-- js/src/collapse.js | 4 ++-- js/src/dropdown.js | 4 ++-- js/src/index.js | 4 ++-- js/src/modal.js | 4 ++-- js/src/popover.js | 5 ++--- js/src/scrollspy.js | 4 ++-- js/src/tab.js | 4 ++-- js/src/tooltip.js | 4 ++-- js/src/util.js | 6 +----- js/tests/index.html | 1 - js/tests/unit/util.js | 19 ------------------- 14 files changed, 23 insertions(+), 49 deletions(-) delete mode 100644 js/tests/unit/util.js (limited to 'js') diff --git a/js/src/alert.js b/js/src/alert.js index 2b967145f..8d52e1591 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -9,7 +9,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Alert = (() => { +const Alert = (($) => { /** @@ -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 87e724346..5632998a3 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -1,5 +1,4 @@ import $ from 'jquery' -import Util from './util' /** * -------------------------------------------------------------------------- @@ -8,7 +7,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Button = (() => { +const Button = (($) => { /** @@ -184,6 +183,6 @@ const Button = (() => { return Button -})(Util.jQuery) +})($) export default Button diff --git a/js/src/carousel.js b/js/src/carousel.js index b5cbf98b4..10ed2203e 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -9,7 +9,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Carousel = (() => { +const Carousel = (($) => { /** @@ -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 9a21eb7d8..f907aec54 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -9,7 +9,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Collapse = (() => { +const Collapse = (($) => { /** @@ -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 48f87c5aa..e3331ac18 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -10,7 +10,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Dropdown = (() => { +const Dropdown = (($) => { /** * Check for Popper dependency @@ -445,6 +445,6 @@ const Dropdown = (() => { return Dropdown -})(Util.jQuery, Popper) +})($, Popper) export default Dropdown diff --git a/js/src/index.js b/js/src/index.js index 1697a709b..51d09b4e2 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -18,7 +18,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -(() => { +(($) => { if (typeof $ === 'undefined') { throw new Error('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.') } @@ -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 cb7bef0ce..95565aabc 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -9,7 +9,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Modal = (() => { +const Modal = (($) => { /** @@ -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 28cb511fc..4fb96a792 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -1,6 +1,5 @@ import $ from 'jquery' import Tooltip from './tooltip' -import Util from './util' /** @@ -10,7 +9,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Popover = (() => { +const Popover = (($) => { /** @@ -190,6 +189,6 @@ const Popover = (() => { return Popover -})(Util.jQuery) +})($) export default Popover diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 12667cc95..3a13d954a 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -9,7 +9,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const ScrollSpy = (() => { +const ScrollSpy = (($) => { /** @@ -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 f1d9ec0c8..1d4178687 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -9,7 +9,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Tab = (() => { +const Tab = (($) => { /** @@ -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 39ef2594b..a3fc93c91 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -10,7 +10,7 @@ import Util from './util' * -------------------------------------------------------------------------- */ -const Tooltip = (() => { +const Tooltip = (($) => { /** * Check for Popper dependency @@ -728,6 +728,6 @@ const Tooltip = (() => { return Tooltip -})(Util.jQuery, Popper) +})($, Popper) export default Tooltip diff --git a/js/src/util.js b/js/src/util.js index 1fa55494e..71f93a7c5 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -7,7 +7,7 @@ import $ from 'jquery' * -------------------------------------------------------------------------- */ -const Util = (() => { +const Util = (($) => { /** @@ -152,10 +152,6 @@ const Util = (() => { } } } - }, - - get jQuery() { - return window.jQuery || window.$ } } diff --git a/js/tests/index.html b/js/tests/index.html index 0385b8a2b..2383fce6e 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -119,7 +119,6 @@ -
diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js deleted file mode 100644 index c3412041e..000000000 --- a/js/tests/unit/util.js +++ /dev/null @@ -1,19 +0,0 @@ -$(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 - }) -}) -- cgit v1.2.3 From 988327032d6b76fdb70075feb7254bcb053ec117 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Wed, 25 Oct 2017 09:32:21 +0200 Subject: Add unit tests for util.js --- js/tests/index.html | 1 + js/tests/unit/util.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 js/tests/unit/util.js (limited to 'js') diff --git a/js/tests/index.html b/js/tests/index.html index 2383fce6e..0385b8a2b 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 000000000..372c6e3f7 --- /dev/null +++ b/js/tests/unit/util.js @@ -0,0 +1,57 @@ +$(function () { + 'use strict' + + QUnit.module('util') + + QUnit.test('Util.getSelectorFromElement should return the correct element', function (assert) { + assert.expect(2) + var $el = $('
').appendTo($('#qunit-fixture')) + assert.strictEqual(Util.getSelectorFromElement($el[0]), 'body') + + // not found element + var $el2 = $('
').appendTo($('#qunit-fixture')) + assert.strictEqual(Util.getSelectorFromElement($el2[0]), null) + }) + + QUnit.test('Util.typeCheckConfig should thrown an error when a bad config is passed', function (assert) { + assert.expect(1) + var namePlugin = 'collapse' + var defaultType = { + toggle : 'boolean', + parent : '(string|element)' + } + var config = { + toggle: true, + parent: 777 + } + + try { + Util.typeCheckConfig(namePlugin, config, defaultType) + } catch (e) { + assert.strictEqual(e.message, 'COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".') + } + }) + + QUnit.test('Util.isElement should check if we passed an element or not', function (assert) { + assert.expect(3) + var $div = $('
').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.isElement($div), 1) + assert.strictEqual(Util.isElement($div[0]), 1) + assert.strictEqual(typeof Util.isElement({}) === 'undefined', true) + }) + + QUnit.test('Util.getUID should generate a new id uniq', function (assert) { + assert.expect(2) + var id = Util.getUID('test') + var id2 = Util.getUID('test') + + assert.ok(id !== id2, id + ' !== ' + id2) + + id = Util.getUID('test') + $('
').appendTo($('#qunit-fixture')) + + id2 = Util.getUID('test') + assert.ok(id !== id2, id + ' !== ' + id2) + }) +}) -- cgit v1.2.3