diff --git a/build/build-plugins.js b/build/build-plugins.js
index abcbc5e2f5..a5f95a9d15 100644
--- a/build/build-plugins.js
+++ b/build/build-plugins.js
@@ -26,6 +26,11 @@ const plugins = [
})
]
const bsPlugins = {
+ Data: path.resolve(__dirname, '../js/src/dom/data.js'),
+ EventHandler: path.resolve(__dirname, '../js/src/dom/eventHandler.js'),
+ Manipulator: path.resolve(__dirname, '../js/src/dom/manipulator.js'),
+ Polyfill: path.resolve(__dirname, '../js/src/dom/polyfill.js'),
+ SelectorEngine: path.resolve(__dirname, '../js/src/dom/selectorEngine.js'),
Alert: path.resolve(__dirname, '../js/src/alert.js'),
Button: path.resolve(__dirname, '../js/src/button.js'),
Carousel: path.resolve(__dirname, '../js/src/carousel.js'),
@@ -41,26 +46,112 @@ const bsPlugins = {
}
const rootPath = TEST ? '../js/coverage/dist/' : '../js/dist/'
+const defaultPluginConfig = {
+ external: [
+ bsPlugins.Data,
+ bsPlugins.EventHandler,
+ bsPlugins.SelectorEngine,
+ bsPlugins.Util
+ ],
+ globals: {
+ [bsPlugins.Data]: 'Data',
+ [bsPlugins.EventHandler]: 'EventHandler',
+ [bsPlugins.SelectorEngine]: 'SelectorEngine',
+ [bsPlugins.Util]: 'Util'
+ }
+}
+
+function getConfigByPluginKey(pluginKey) {
+ if (
+ pluginKey === 'Data' ||
+ pluginKey === 'Manipulator' ||
+ pluginKey === 'Util'
+ ) {
+ return {
+ external: [],
+ globals: {}
+ }
+ }
+
+ if (pluginKey === 'EventHandler' || pluginKey === 'SelectorEngine') {
+ return {
+ external: [
+ bsPlugins.Polyfill,
+ bsPlugins.Util
+ ],
+ globals: {
+ [bsPlugins.Polyfill]: 'Polyfill',
+ [bsPlugins.Util]: 'Util'
+ }
+ }
+ }
+
+ if (pluginKey === 'Polyfill') {
+ return {
+ external: [bsPlugins.Util],
+ globals: {
+ [bsPlugins.Util]: 'Util'
+ }
+ }
+ }
+
+ if (pluginKey === 'Alert' || pluginKey === 'Tab') {
+ return defaultPluginConfig
+ }
+
+ if (
+ pluginKey === 'Button' ||
+ pluginKey === 'Carousel' ||
+ pluginKey === 'Collapse' ||
+ pluginKey === 'Modal' ||
+ pluginKey === 'ScrollSpy'
+ ) {
+ const config = Object.assign(defaultPluginConfig)
+ config.external.push(bsPlugins.Manipulator)
+ config.globals[bsPlugins.Manipulator] = 'Manipulator'
+ return config
+ }
+
+ if (pluginKey === 'Dropdown' || pluginKey === 'Tooltip') {
+ const config = Object.assign(defaultPluginConfig)
+ config.external.push(bsPlugins.Manipulator, 'popper.js')
+ config.globals[bsPlugins.Manipulator] = 'Manipulator'
+ config.globals['popper.js'] = 'Popper'
+ return config
+ }
+
+ if (pluginKey === 'Popover') {
+ return {
+ external: [
+ bsPlugins.Data,
+ bsPlugins.SelectorEngine,
+ bsPlugins.Tooltip,
+ bsPlugins.Util
+ ],
+ globals: {
+ [bsPlugins.Data]: 'Data',
+ [bsPlugins.SelectorEngine]: 'SelectorEngine',
+ [bsPlugins.Tooltip]: 'Tooltip',
+ [bsPlugins.Util]: 'Util'
+ }
+ }
+ }
+}
+
function build(plugin) {
console.log(`Building ${plugin} plugin...`)
- const external = ['jquery', 'popper.js']
- const globals = {
- jquery: 'jQuery', // Ensure we use jQuery which is always available even in noConflict mode
- 'popper.js': 'Popper'
- }
+ const config = getConfigByPluginKey(plugin)
+ const external = config.external
+ const globals = config.globals
- // Do not bundle Util in plugins
- if (plugin !== 'Util') {
- external.push(bsPlugins.Util)
- globals[bsPlugins.Util] = 'Util'
- }
-
- // Do not bundle Tooltip in Popover
- if (plugin === 'Popover') {
- external.push(bsPlugins.Tooltip)
- globals[bsPlugins.Tooltip] = 'Tooltip'
- }
+ const pluginPath = [
+ 'Data',
+ 'EventHandler',
+ 'Manipulator',
+ 'Polyfill',
+ 'SelectorEngine'
+ ].includes(plugin) ? `${rootPath}/dom/` : rootPath
const pluginFilename = `${plugin.toLowerCase()}.js`
@@ -75,7 +166,7 @@ function build(plugin) {
name: plugin,
sourcemap: true,
globals,
- file: path.resolve(__dirname, `${rootPath}${pluginFilename}`)
+ file: path.resolve(__dirname, `${pluginPath}${pluginFilename}`)
})
.then(() => console.log(`Building ${plugin} plugin... Done!`))
.catch((err) => console.error(`${plugin}: ${err}`))
diff --git a/js/src/alert.js b/js/src/alert.js
index bc368ae622..a8d0cc5da9 100644
--- a/js/src/alert.js
+++ b/js/src/alert.js
@@ -140,6 +140,16 @@ class Alert {
})
}
+ static _handleDismiss(alertInstance) {
+ return function (event) {
+ if (event) {
+ event.preventDefault()
+ }
+
+ alertInstance.close(this)
+ }
+ }
+
static _getInstance(element) {
return Data.getData(element, DATA_KEY)
}
diff --git a/js/src/carousel.js b/js/src/carousel.js
index 32a039c49d..9ff7c09e72 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -178,7 +178,7 @@ class Carousel {
this._interval = null
}
- if (this._config.interval && !this._isPaused) {
+ if (this._config && this._config.interval && !this._isPaused) {
this._interval = setInterval(
(document.visibilityState ? this.nextWhenVisible : this.next).bind(this),
this._config.interval
@@ -298,7 +298,7 @@ class Carousel {
}
const end = (event) => {
- if (this._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) {
+ if (this._pointerEvent && PointerType[event.pointerType.toUpperCase()]) {
this.touchDeltaX = event.clientX - this.touchStartX
}
@@ -464,6 +464,14 @@ class Carousel {
activeElement.classList.add(directionalClassName)
nextElement.classList.add(directionalClassName)
+ const nextElementInterval = parseInt(nextElement.getAttribute('data-interval'), 10)
+ if (nextElementInterval) {
+ this._config.defaultInterval = this._config.defaultInterval || this._config.interval
+ this._config.interval = nextElementInterval
+ } else {
+ this._config.interval = this._config.defaultInterval || this._config.interval
+ }
+
const transitionDuration = Util.getTransitionDurationFromElement(activeElement)
EventHandler
diff --git a/js/src/dom/data.js b/js/src/dom/data.js
index 2c11151257..2dfaad91a4 100644
--- a/js/src/dom/data.js
+++ b/js/src/dom/data.js
@@ -1,6 +1,6 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.1.1): dom/data.js
+ * Bootstrap (v4.1.3): dom/data.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
diff --git a/js/src/dom/eventHandler.js b/js/src/dom/eventHandler.js
index 17f6d077a6..259f575ed9 100644
--- a/js/src/dom/eventHandler.js
+++ b/js/src/dom/eventHandler.js
@@ -3,7 +3,7 @@ import Util from '../util'
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.1.1): dom/eventHandler.js
+ * Bootstrap (v4.1.3): dom/eventHandler.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -32,6 +32,7 @@ const EventHandler = (() => {
'keydown', 'keypress', 'keyup',
'orientationchange',
'touchstart', 'touchmove', 'touchend', 'touchcancel',
+ 'pointerdown', 'pointermove', 'pointerup', 'pointerleave', 'pointercancel',
'gesturestart', 'gesturechange', 'gestureend',
'focus', 'blur', 'change', 'reset', 'select', 'submit', 'focusin', 'focusout',
'load', 'unload', 'beforeunload', 'resize', 'move', 'DOMContentLoaded', 'readystatechange',
@@ -314,4 +315,19 @@ const EventHandler = (() => {
}
})()
+/* istanbul ignore next */
+// focusin and focusout polyfill
+if (Polyfill.focusIn) {
+ (() => {
+ function listenerFocus(event) {
+ EventHandler.trigger(event.target, 'focusin')
+ }
+ function listenerBlur(event) {
+ EventHandler.trigger(event.target, 'focusout')
+ }
+ EventHandler.on(document, 'focus', 'input', listenerFocus)
+ EventHandler.on(document, 'blur', 'input', listenerBlur)
+ })()
+}
+
export default EventHandler
diff --git a/js/src/dom/manipulator.js b/js/src/dom/manipulator.js
index db3113f88d..ad14e29148 100644
--- a/js/src/dom/manipulator.js
+++ b/js/src/dom/manipulator.js
@@ -1,6 +1,6 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.1.1): dom/manipulator.js
+ * Bootstrap (v4.1.3): dom/manipulator.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
diff --git a/js/src/dom/polyfill.js b/js/src/dom/polyfill.js
index c0c1139f03..45defb76e7 100644
--- a/js/src/dom/polyfill.js
+++ b/js/src/dom/polyfill.js
@@ -2,7 +2,7 @@ import Util from '../util'
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.1.1): dom/polyfill.js
+ * Bootstrap (v4.1.3): dom/polyfill.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
diff --git a/js/src/dom/selectorEngine.js b/js/src/dom/selectorEngine.js
index 55d2ce4bbc..c2eec95a7e 100644
--- a/js/src/dom/selectorEngine.js
+++ b/js/src/dom/selectorEngine.js
@@ -3,7 +3,7 @@ import Util from '../util'
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.1.1): dom/selectorEngine.js
+ * Bootstrap (v4.1.3): dom/selectorEngine.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 6a4fb9e013..9a22a69916 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -234,7 +234,7 @@ class Dropdown {
Manipulator.toggleClass(this._menu, ClassName.SHOW)
Manipulator.toggleClass(parent, ClassName.SHOW)
- EventHandler.trigger(parent, Event.SHOWN, relatedTarget)
+ EventHandler.trigger(parent, Event.HIDDEN, relatedTarget)
}
dispose() {
diff --git a/js/src/index.js b/js/src/index.js
index 0c662873df..aa35ed07b3 100644
--- a/js/src/index.js
+++ b/js/src/index.js
@@ -3,9 +3,7 @@ import Button from './button'
import Carousel from './carousel'
import Collapse from './collapse'
import Dropdown from './dropdown'
-import EventHandler from './dom/eventHandler'
import Modal from './modal'
-import Polyfill from './dom/polyfill'
import Popover from './popover'
import ScrollSpy from './scrollspy'
import Tab from './tab'
@@ -20,21 +18,6 @@ import Util from './util'
* --------------------------------------------------------------------------
*/
-/* istanbul ignore next */
-// focusin and focusout polyfill
-if (Polyfill.focusIn) {
- (() => {
- function listenerFocus(event) {
- EventHandler.trigger(event.target, 'focusin')
- }
- function listenerBlur(event) {
- EventHandler.trigger(event.target, 'focusout')
- }
- EventHandler.on(document, 'focus', 'input', listenerFocus)
- EventHandler.on(document, 'blur', 'input', listenerBlur)
- })()
-}
-
export {
Util,
Alert,
diff --git a/js/src/modal.js b/js/src/modal.js
index 34aa56606c..8e56fc5b29 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -119,7 +119,7 @@ class Modal {
relatedTarget
})
- if (this._isShown || showEvent.isDefaultPrevented()) {
+ if (this._isShown || showEvent.defaultPrevented) {
return
}
@@ -161,7 +161,7 @@ class Modal {
const hideEvent = EventHandler.trigger(this._element, Event.HIDE)
- if (!this._isShown || hideEvent.isDefaultPrevented()) {
+ if (!this._isShown || hideEvent.defaultPrevented) {
return
}
@@ -282,16 +282,14 @@ class Modal {
}
_enforceFocus() {
- if (this._isShown && this._config.keyboard) {
- EventHandler.on(this._element, Event.KEYDOWN_DISMISS, (event) => {
- if (event.which === ESCAPE_KEYCODE) {
- event.preventDefault()
- this.hide()
- }
- })
- } else if (!this._isShown) {
- EventHandler.off(this._element, Event.KEYDOWN_DISMISS)
- }
+ EventHandler.off(document, Event.FOCUSIN) // guard against infinite focus loop
+ EventHandler.on(document, Event.FOCUSIN, (event) => {
+ if (document !== event.target &&
+ this._element !== event.target &&
+ !this._element.contains(event.target)) {
+ this._element.focus()
+ }
+ })
}
_setEscapeEvent() {
@@ -383,7 +381,7 @@ class Modal {
const backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop)
EventHandler.one(this._backdrop, Util.TRANSITION_END, callback)
- Util.emulateTransitionEnd(backdropTransitionDuration)
+ Util.emulateTransitionEnd(this._backdrop, backdropTransitionDuration)
} else if (!this._isShown && this._backdrop) {
this._backdrop.classList.remove(ClassName.SHOW)
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 29394b9484..93880bb8e4 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -682,8 +682,7 @@ class Tooltip {
}
})
- if (typeof config !== 'undefined' &&
- typeof config.container === 'object' && config.container.jquery) {
+ if (config && typeof config.container === 'object' && config.container.jquery) {
config.container = config.container[0]
}
diff --git a/js/src/util.js b/js/src/util.js
index 7a97411bbf..caa2e63485 100644
--- a/js/src/util.js
+++ b/js/src/util.js
@@ -5,8 +5,6 @@
* --------------------------------------------------------------------------
*/
-import EventHandler from './dom/eventHandler'
-
/**
* ------------------------------------------------------------------------
* Private TransitionEnd Helpers
diff --git a/js/tests/index.html b/js/tests/index.html
index d0ff5b82b6..77c29f8f85 100644
--- a/js/tests/index.html
+++ b/js/tests/index.html
@@ -97,12 +97,12 @@
+
-
diff --git a/js/tests/karma.conf.js b/js/tests/karma.conf.js
index 469a95561f..641ac88949 100644
--- a/js/tests/karma.conf.js
+++ b/js/tests/karma.conf.js
@@ -93,12 +93,12 @@ if (bundle) {
reporters.push('BrowserStack')
files = files.concat([
'node_modules/jquery/dist/jquery.slim.min.js',
+ 'js/coverage/dist/util.js',
+ 'js/coverage/dist/dom/polyfill.js',
'js/coverage/dist/dom/eventHandler.js',
'js/coverage/dist/dom/selectorEngine.js',
'js/coverage/dist/dom/data.js',
'js/coverage/dist/dom/manipulator.js',
- 'js/coverage/dist/util.js',
- 'js/coverage/dist/dom/polyfill.js',
'js/coverage/dist/dom/!(polyfill).js',
'js/coverage/dist/tooltip.js',
'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
@@ -115,12 +115,12 @@ if (bundle) {
)
files = files.concat([
jqueryFile,
+ 'js/coverage/dist/util.js',
+ 'js/coverage/dist/dom/polyfill.js',
'js/coverage/dist/dom/eventHandler.js',
'js/coverage/dist/dom/selectorEngine.js',
'js/coverage/dist/dom/data.js',
'js/coverage/dist/dom/manipulator.js',
- 'js/coverage/dist/util.js',
- 'js/coverage/dist/dom/polyfill.js',
'js/coverage/dist/dom/!(polyfill).js',
'js/coverage/dist/tooltip.js',
'js/coverage/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js
index 9016f61abb..3db83eaa38 100644
--- a/js/tests/unit/carousel.js
+++ b/js/tests/unit/carousel.js
@@ -541,16 +541,19 @@ $(function () {
'‹' +
'›' +
''
- var $carousel = $(templateHTML)
- $carousel.appendTo('body')
+ var $carousel = $(templateHTML).appendTo('#qunit-fixture')
$carousel.bootstrapCarousel(1)
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, 3814)
+ var carousel = Carousel._getInstance($carousel[0])
+ assert.strictEqual(carousel._config.interval, 3814)
+ carousel.dispose()
$carousel.remove()
- $carousel.appendTo('body')
+ $carousel = $carousel.appendTo('#qunit-fixture')
$carousel.bootstrapCarousel(2)
- assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'reverts to default interval if no data-interval is set')
+ carousel = Carousel._getInstance($carousel[0])
+
+ assert.strictEqual(carousel._config.interval, 1814, 'reverts to default interval if no data-interval is set')
$carousel.remove()
})
@@ -1080,7 +1083,7 @@ $(function () {
var $carousel = $(carouselHTML).appendTo('#qunit-fixture')
var $item = $('#item')
$carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
+ var carousel = Carousel._getInstance($carousel[0])
var spy = sinon.spy(carousel, 'prev')
$carousel.one('slid.bs.carousel', function () {
@@ -1122,7 +1125,7 @@ $(function () {
$carousel.appendTo('#qunit-fixture')
var $item = $('#item')
$carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
+ var carousel = Carousel._getInstance($carousel[0])
var spy = sinon.spy(carousel, 'prev')
$carousel.one('slid.bs.carousel', function () {
@@ -1169,7 +1172,7 @@ $(function () {
$carousel.appendTo('#qunit-fixture')
var $item = $('#item')
$carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
+ var carousel = Carousel._getInstance($carousel[0])
var spy = sinon.spy(carousel, 'next')
$carousel.one('slid.bs.carousel', function () {
@@ -1212,7 +1215,7 @@ $(function () {
$carousel.appendTo('#qunit-fixture')
var $item = $('#item')
$carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
+ var carousel = Carousel._getInstance($carousel[0])
var spy = sinon.spy(carousel, 'next')
$carousel.one('slid.bs.carousel', function () {
@@ -1264,7 +1267,7 @@ $(function () {
$carousel.appendTo('#qunit-fixture')
$carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
+ var carousel = Carousel._getInstance($carousel[0])
var spy = sinon.spy(carousel, '_slide')
@@ -1283,7 +1286,7 @@ $(function () {
$carousel.appendTo('#qunit-fixture')
$carousel.bootstrapCarousel()
- var carousel = $carousel.data('bs.carousel')
+ var carousel = Carousel._getInstance($carousel[0])
var spy = sinon.spy(carousel, 'next')
var sandbox = sinon.createSandbox()
diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js
index a9a5773e61..3c1c9d03df 100644
--- a/js/tests/unit/dropdown.js
+++ b/js/tests/unit/dropdown.js
@@ -517,7 +517,7 @@ $(function () {
$(document.body).trigger('click')
})
- $dropdown.trigger('click')
+ $dropdown[0].click()
})
QUnit.test('should fire hide and hidden event without a clickEvent if event type is not click', function (assert) {
@@ -547,12 +547,13 @@ $(function () {
})
.on('shown.bs.dropdown', function () {
assert.ok(true, 'shown was fired')
- $dropdown.trigger($.Event('keydown', {
- which: 27
- }))
+
+ var keyDown = new Event('keydown')
+ keyDown.which = 27
+ $dropdown[0].dispatchEvent(keyDown)
})
- $dropdown.trigger('click')
+ $dropdown[0].click()
})
QUnit.test('should ignore keyboard events within s and