Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a9137659
Commit
a9137659
authored
Jul 09, 2020
by
Mark Florian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify data attribute checking
parent
815a177b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
app/assets/javascripts/lib/utils/dom_utils.js
app/assets/javascripts/lib/utils/dom_utils.js
+3
-4
spec/frontend/lib/utils/dom_utils_spec.js
spec/frontend/lib/utils/dom_utils_spec.js
+11
-1
No files found.
app/assets/javascripts/lib/utils/dom_utils.js
View file @
a9137659
import
{
has
}
from
'
lodash
'
;
import
{
isInIssuePage
,
isInMRPage
,
isInEpicPage
}
from
'
./common_utils
'
;
import
{
dasherize
,
convertToSnakeCase
}
from
'
./text_utility
'
;
export
const
addClassIfElementExists
=
(
element
,
className
)
=>
{
if
(
element
)
{
...
...
@@ -41,10 +41,9 @@ export const toggleContainerClasses = (containerEl, classList) => {
* @param {string[]} names - The dataset (i.e., camelCase) names to inspect
* @returns {Object.<string, boolean>}
*/
export
const
parseBooleanDataAttributes
=
(
element
,
names
)
=>
export
const
parseBooleanDataAttributes
=
(
{
dataset
}
,
names
)
=>
names
.
reduce
((
acc
,
name
)
=>
{
const
attributeName
=
`data-
${
dasherize
(
convertToSnakeCase
(
name
))}
`
;
acc
[
name
]
=
element
.
hasAttribute
(
attributeName
);
acc
[
name
]
=
has
(
dataset
,
name
);
return
acc
;
},
{});
spec/frontend/lib/utils/dom_utils_spec.js
View file @
a9137659
...
...
@@ -140,13 +140,23 @@ describe('DOM Utils', () => {
it
(
'
correctly parses boolean-like data attributes
'
,
()
=>
{
expect
(
parseBooleanDataAttributes
(
element
,
[
'
fooBar
'
,
'
foobar
'
,
'
baz
'
,
'
qux
'
,
'
doesNotExist
'
]),
parseBooleanDataAttributes
(
element
,
[
'
fooBar
'
,
'
foobar
'
,
'
baz
'
,
'
qux
'
,
'
doesNotExist
'
,
'
toString
'
,
]),
).
toEqual
({
fooBar
:
true
,
foobar
:
false
,
baz
:
true
,
qux
:
true
,
doesNotExist
:
false
,
// Ensure prototype properties aren't false positives
toString
:
false
,
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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