]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Fix Carousel's touch option to not add touch listeners when set to false (#28046)
authorJohann-S <johann.servoire@gmail.com>
Mon, 14 Jan 2019 16:53:54 +0000 (17:53 +0100)
committerXhmikosR <xhmikosr@gmail.com>
Mon, 14 Jan 2019 16:53:54 +0000 (18:53 +0200)
js/src/carousel.js
js/tests/unit/carousel.js

index a43d86b18974f47b19d834e1651b6fa089df5130..06c20b5093a5094f6bfe568688c36cf3ced55542 100644 (file)
@@ -268,7 +268,9 @@ class Carousel {
         .on(Event.MOUSELEAVE, (event) => this.cycle(event))
     }
 
-    this._addTouchEventListeners()
+    if (this._config.touch) {
+      this._addTouchEventListeners()
+    }
   }
 
   _addTouchEventListeners() {
index 6c28b672145e402339c75e3731f7a4d1a0f2c54c..0d2a0f327104f2fef5b3cea35f98db20c79f92d7 100644 (file)
@@ -948,7 +948,7 @@ $(function () {
     $textArea.trigger(eventKeyDown)
   })
 
-  QUnit.test('Should not go to the next item when the carousel is not visible', function (assert) {
+  QUnit.test('should not go to the next item when the carousel is not visible', function (assert) {
     assert.expect(2)
     var done = assert.async()
     var html = '<div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">' +
@@ -985,7 +985,7 @@ $(function () {
     }, 80)
   })
 
-  QUnit.test('Should not go to the next item when the parent of the carousel is not visible', function (assert) {
+  QUnit.test('should not go to the next item when the parent of the carousel is not visible', function (assert) {
     assert.expect(2)
     var done = assert.async()
     var html = '<div id="parent" style="display: none;">' +
@@ -1317,4 +1317,17 @@ $(function () {
       done()
     }, 5)
   })
+
+  QUnit.test('should not add touch event listeners when touch option set to false', function (assert) {
+    assert.expect(1)
+
+    var spy = sinon.spy(Carousel.prototype, '_addTouchEventListeners')
+    var $carousel = $('<div class="carousel" data-ride="carousel" data-touch="false"></div>')
+
+    $carousel.appendTo('#qunit-fixture')
+    $carousel.bootstrapCarousel()
+
+    assert.strictEqual(spy.called, false)
+    spy.restore()
+  })
 })