Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,13 @@ class Carousel {
}

const move = (event) => {
if (!this._pointerEvent) {
event.preventDefault()
event.preventDefault()

// ensure swiping with one touch and not pinching
if (event.originalEvent.touches && event.originalEvent.touches.length > 1) {
this.touchDeltaX = 0
} else {
this.touchDeltaX = event.originalEvent.touches[0].clientX - this.touchStartX
}
// ensure swiping with one touch and not pinching
if (event.originalEvent.touches && event.originalEvent.touches.length > 1) {
this.touchDeltaX = 0
} else {
this.touchDeltaX = event.originalEvent.touches[0].clientX - this.touchStartX
}
}

Expand All @@ -307,7 +305,6 @@ class Carousel {
}

this._handleSwipe()

if (this._config.pause === 'hover') {
// If it's a touch-enabled device, mouseenter/leave are fired as
// part of the mouse compatibility events on first tap - the carousel
Expand Down
4 changes: 2 additions & 2 deletions js/tests/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ if (bundle) {
emitWarning: false,
global: {
statements: 90,
branches: 84,
functions: 87,
branches: 86,
functions: 89,
lines: 90
}
}
Expand Down
44 changes: 44 additions & 0 deletions js/tests/unit/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,4 +1226,48 @@ $(function () {
done()
})
})

QUnit.test('should not call _slide if the carousel is sliding', function (assert) {
assert.expect(1)

var carouselHTML = '<div class="carousel" data-interval="false"></div>'
var $carousel = $(carouselHTML)
$carousel.appendTo('#qunit-fixture')
$carousel.bootstrapCarousel()

var carousel = $carousel.data('bs.carousel')

var spy = sinon.spy(carousel, '_slide')

carousel._isSliding = true

carousel.next()

assert.strictEqual(spy.called, false)
})

QUnit.test('should call next when the page is visible', function (assert) {
assert.expect(1)

var carouselHTML = '<div class="carousel" data-interval="false"></div>'
var $carousel = $(carouselHTML)
$carousel.appendTo('#qunit-fixture')
$carousel.bootstrapCarousel()

var carousel = $carousel.data('bs.carousel')

var spy = sinon.spy(carousel, 'next')
var sandbox = sinon.createSandbox()

sandbox.replaceGetter(document, 'hidden', function () {
return false
})
sandbox.stub($carousel, 'is').returns(true)
sandbox.stub($carousel, 'css').returns('block')

carousel.nextWhenVisible()

assert.strictEqual(spy.called, true)
sandbox.restore()
})
})