diff options
author | Johann-S <johann.servoire@gmail.com> | 2018-08-31 22:00:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-31 22:00:29 +0300 |
commit | a3e45d8ced63369ad6bd29ce45d919b77412a99b (patch) | |
tree | 12a4e8e14043646569f2898ca0b6f0d069aea6ee /js | |
parent | 54d86e6249d90fa8634acd3bc0b78556269edce5 (diff) |
add information about valid selectors (#27137)
Diffstat (limited to 'js')
-rw-r--r-- | js/src/util.js | 9 | ||||
-rw-r--r-- | js/tests/unit/util.js | 25 |
2 files changed, 1 insertions, 33 deletions
diff --git a/js/src/util.js b/js/src/util.js index 8165ab46f6..653598ae2b 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -77,20 +77,13 @@ const Util = (($) => { getSelectorFromElement(element) { let selector = element.getAttribute('data-target') - let method = 'querySelector' if (!selector || selector === '#') { selector = (element.getAttribute('href') || '').trim() } - const validSelector = selector - if (selector.charAt(0) === '#' && selector.indexOf(',') === -1) { - selector = selector.substr(1) - method = 'getElementById' - } - try { - return document[method](selector) ? validSelector : null + return document.querySelector(selector) ? selector : null } catch (err) { return null } diff --git a/js/tests/unit/util.js b/js/tests/unit/util.js index 4f44c29073..37327b8681 100644 --- a/js/tests/unit/util.js +++ b/js/tests/unit/util.js @@ -20,31 +20,6 @@ $(function () { assert.strictEqual(Util.getSelectorFromElement($el2[0]), null) }) - QUnit.test('Util.getSelectorFromElement should use getElementById', function (assert) { - assert.expect(2) - - var spy = sinon.spy(document, 'getElementById') - - var $el = $('<div data-target="#7"></div>').appendTo($('#qunit-fixture')) - $('<div id="7" />').appendTo($('#qunit-fixture')) - - assert.strictEqual(Util.getSelectorFromElement($el[0]), '#7') - 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' |