aboutsummaryrefslogtreecommitdiff
path: root/js/src/carousel.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/carousel.js')
-rw-r--r--js/src/carousel.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index efacd9494..3abb06466 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -3,7 +3,7 @@ import Util from './util'
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.0.0): carousel.js
+ * Bootstrap (v4.0.0-alpha): carousel.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -18,7 +18,7 @@ const Carousel = (($) => {
*/
const NAME = 'carousel'
- const VERSION = '4.0.0'
+ const VERSION = '4.0.0-alpha'
const DATA_KEY = 'bs.carousel'
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
@@ -119,6 +119,13 @@ const Carousel = (($) => {
}
}
+ nextWhenVisible() {
+ // Don't call next when the page isn't visible
+ if (!document.hidden) {
+ this.next()
+ }
+ }
+
prev() {
if (!this._isSliding) {
this._slide(Direction.PREVIOUS)
@@ -152,7 +159,7 @@ const Carousel = (($) => {
if (this._config.interval && !this._isPaused) {
this._interval = setInterval(
- $.proxy(this.next, this), this._config.interval
+ $.proxy(document.visibilityState ? this.nextWhenVisible : this.next, this), this._config.interval
)
}
}
@@ -390,10 +397,11 @@ const Carousel = (($) => {
if (typeof config === 'number') {
data.to(config)
-
- } else if (action) {
+ } else if (typeof action === 'string') {
+ if (data[action] === undefined) {
+ throw new Error(`No method named "${action}"`)
+ }
data[action]()
-
} else if (_config.interval) {
data.pause()
data.cycle()