]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
fix(util): use querySelector for ids
authorJohann-S <johann.servoire@gmail.com>
Sat, 11 Aug 2018 20:40:47 +0000 (22:40 +0200)
committerJohann-S <johann.servoire@gmail.com>
Sun, 12 Aug 2018 15:01:01 +0000 (17:01 +0200)
js/src/util.js
js/tests/unit/util.js

index 3008c227851a2c26b6be026a301fa9f1811ff9e3..8165ab46f6bbb5356e9b5c125fa83eb22c348bfc 100644 (file)
@@ -84,7 +84,7 @@ const Util = (($) => {
       }
 
       const validSelector = selector
-      if (selector.charAt(0) === '#') {
+      if (selector.charAt(0) === '#' && selector.indexOf(',') === -1) {
         selector = selector.substr(1)
         method = 'getElementById'
       }
index 49252701a501bf1256b7433e82c66b41fa24c88c..4f44c29073f23c373c60f24c2261281820e0fc4f 100644 (file)
@@ -32,6 +32,19 @@ $(function () {
     assert.ok(spy.called)
   })
 
+  QUnit.test('Util.getSelectorFromElement should use querySelector when there are multi ids', function (assert) {
+    assert.expect(2)
+
+    var spy = sinon.spy(document, 'querySelector')
+
+    var $el = $('<div data-target="#j7, #j8"></div>').appendTo($('#qunit-fixture'))
+    $('<div id="j7" />').appendTo($('#qunit-fixture'))
+    $('<div id="j8" />').appendTo($('#qunit-fixture'))
+
+    assert.strictEqual(Util.getSelectorFromElement($el[0]), '#j7, #j8')
+    assert.ok(spy.called)
+  })
+
   QUnit.test('Util.typeCheckConfig should thrown an error when a bad config is passed', function (assert) {
     assert.expect(1)
     var namePlugin = 'collapse'