Skip to content

Commit

Permalink
Only enable pause: hover for non-touch browsers
Browse files Browse the repository at this point in the history
Fixes #11967.
  • Loading branch information
hnrch02 committed Sep 23, 2014
1 parent 4a3931d commit c37c1a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
this.$active =
this.$items = null

this.options.pause == 'hover' && this.$element
this.options.pause == 'hover' && !('ontouchstart' in document.documentElement) && this.$element
.on('mouseenter.bs.carousel', $.proxy(this.pause, this))
.on('mouseleave.bs.carousel', $.proxy(this.cycle, this))
}
Expand Down
22 changes: 22 additions & 0 deletions js/tests/unit/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,26 @@ $(function () {

strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active')
})

test('should only add mouseenter and mouseleave listeners when not on mobile', function () {
var isMobile = 'ontouchstart' in document.documentElement
var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false" data-pause="hover">'
+ '<div class="carousel-inner">'
+ '<div id="first" class="item active">'
+ '<img alt="">'
+ '</div>'
+ '<div id="second" class="item">'
+ '<img alt="">'
+ '</div>'
+ '<div id="third" class="item">'
+ '<img alt="">'
+ '</div>'
+ '</div>'
+ '</div>'
var $template = $(templateHTML).bootstrapCarousel()

$.each(['mouseover', 'mouseout'], function (i, type) {
strictEqual(type in $._data($template[0], 'events'), !isMobile, 'does' + (isMobile ? ' not' : '') + ' listen for ' + type + ' events')
})
})
})

0 comments on commit c37c1a6

Please sign in to comment.