aboutsummaryrefslogtreecommitdiff
path: root/js/src/carousel.js
diff options
context:
space:
mode:
authorAlexandr Kondrashov <[email protected]>2015-12-08 02:18:32 +0300
committerAlexandr Kondrashov <[email protected]>2015-12-08 02:18:32 +0300
commit5f316e6dc34f57bfbd0ebf922fe5a01cc6bb38c4 (patch)
tree2951782d8d0aadb61dae9122d0f508a75ed8e7eb /js/src/carousel.js
parentc9725926b2f30bed4e37f57c20ef8ffeb2fd233b (diff)
parentafbaf4350560eaf2135fb0dc6dd761ebb746ac40 (diff)
downloadbootstrap-5f316e6dc34f57bfbd0ebf922fe5a01cc6bb38c4.tar.xz
bootstrap-5f316e6dc34f57bfbd0ebf922fe5a01cc6bb38c4.zip
Merge branch 'v4-dev' of https://github.com/twbs/bootstrap into patch-1
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()