Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
6b92321f
Commit
6b92321f
authored
6 years ago
by
Johann-S
Browse files
Options
Download
Email Patches
Plain Diff
fix(util): use getElementById when it's possible
parent
ae53690a
2 merge requests
!28721
Hot test
,
!27561
Adds font-weight-medium to font weight classes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/src/util.js
+10
-2
js/src/util.js
js/tests/unit/util.js
+12
-0
js/tests/unit/util.js
with
22 additions
and
2 deletions
+22
-2
js/src/util.js
+
10
-
2
View file @
6b92321f
...
...
@@ -77,12 +77,20 @@ const Util = (($) => {
getSelectorFromElement
(
element
)
{
let
selector
=
element
.
getAttribute
(
'
data-target
'
)
let
method
=
'
querySelector
'
if
(
!
selector
||
selector
===
'
#
'
)
{
selector
=
element
.
getAttribute
(
'
href
'
)
||
''
selector
=
(
element
.
getAttribute
(
'
href
'
)
||
''
).
trim
()
}
const
validSelector
=
selector
if
(
selector
.
charAt
(
0
)
===
'
#
'
)
{
selector
=
selector
.
substr
(
1
)
method
=
'
getElementById
'
}
try
{
return
document
.
querySelector
(
selector
)
?
s
elector
:
null
return
document
[
method
]
(
selector
)
?
validS
elector
:
null
}
catch
(
err
)
{
return
null
}
...
...
This diff is collapsed.
Click to expand it.
js/tests/unit/util.js
+
12
-
0
View file @
6b92321f
...
...
@@ -20,6 +20,18 @@ $(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.typeCheckConfig should thrown an error when a bad config is passed
'
,
function
(
assert
)
{
assert
.
expect
(
1
)
var
namePlugin
=
'
collapse
'
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets