]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
.collapse('hide') on hidden uninit-ed collapsible no longer shows it; fixes #15315
authorChris Rebert <code@rebertia.com>
Fri, 6 Mar 2015 11:05:30 +0000 (03:05 -0800)
committerChris Rebert <code@rebertia.com>
Fri, 6 Mar 2015 14:58:48 +0000 (06:58 -0800)
Thanks to @peterblazejewicz & @Nikita240
Adds unit tests based on #14417
X-Ref: #14282
Closes #15807

js/collapse.js
js/tests/unit/collapse.js

index 834f4f6b818405fd69d004d33d1e49ba5e5f4c8e..0394165198d253f40520b4b3d18d736a56669aaa 100644 (file)
       var data    = $this.data('bs.collapse')
       var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
 
-      if (!data && options.toggle && option == 'show') options.toggle = false
+      if (!data && options.toggle && /show|hide/.test(option)) options.toggle = false
       if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
       if (typeof option == 'string') data[option]()
     })
index 68c4bce253274a56bea2243ecc979cfc3c5cbaa3..40f586c2ec35390e6b72157f625e040074325e6c 100644 (file)
@@ -147,7 +147,7 @@ $(function () {
     $target.click()
   })
 
-  QUnit.test('should not close a collapse when initialized with "show" if already shown', function (assert) {
+  QUnit.test('should not close a collapse when initialized with "show" option if already shown', function (assert) {
     assert.expect(0)
     var done = assert.async()
 
@@ -162,7 +162,7 @@ $(function () {
     setTimeout(done, 0)
   })
 
-  QUnit.test('should open a collapse when initialized with "show" if not already shown', function (assert) {
+  QUnit.test('should open a collapse when initialized with "show" option if not already shown', function (assert) {
     assert.expect(1)
     var done = assert.async()
 
@@ -177,6 +177,34 @@ $(function () {
     setTimeout(done, 0)
   })
 
+  QUnit.test('should not show a collapse when initialized with "hide" option if already hidden', function (assert) {
+    assert.expect(0)
+    var done = assert.async()
+
+    $('<div class="collapse"></div>')
+      .appendTo('#qunit-fixture')
+      .on('show.bs.collapse', function () {
+        assert.ok(false, 'showing a previously-uninitialized hidden collapse when the "hide" method is called')
+      })
+      .bootstrapCollapse('hide')
+
+    setTimeout(done, 0)
+  })
+
+  QUnit.test('should hide a collapse when initialized with "hide" option if not already hidden', function (assert) {
+    assert.expect(1)
+    var done = assert.async()
+
+    $('<div class="collapse in"></div>')
+      .appendTo('#qunit-fixture')
+      .on('hide.bs.collapse', function () {
+        assert.ok(true, 'hiding a previously-uninitialized shown collapse when the "hide" method is called')
+      })
+      .bootstrapCollapse('hide')
+
+    setTimeout(done, 0)
+  })
+
   QUnit.test('should remove "collapsed" class from active accordion target', function (assert) {
     assert.expect(3)
     var done = assert.async()