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
6ab12777
Commit
6ab12777
authored
Jun 27, 2017
by
winh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce addClassIfElementExists utility
parent
a61eda78
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
10 deletions
+46
-10
app/assets/javascripts/filtered_search/dropdown_user.js
app/assets/javascripts/filtered_search/dropdown_user.js
+2
-5
app/assets/javascripts/filtered_search/filtered_search_manager.js
...ts/javascripts/filtered_search/filtered_search_manager.js
+2
-5
app/assets/javascripts/lib/utils/dom_utils.js
app/assets/javascripts/lib/utils/dom_utils.js
+7
-0
spec/javascripts/lib/utils/dom_utils_spec.js
spec/javascripts/lib/utils/dom_utils_spec.js
+35
-0
No files found.
app/assets/javascripts/filtered_search/dropdown_user.js
View file @
6ab12777
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
AjaxFilter
from
'
~/droplab/plugins/ajax_filter
'
;
import
AjaxFilter
from
'
~/droplab/plugins/ajax_filter
'
;
import
'
./filtered_search_dropdown
'
;
import
'
./filtered_search_dropdown
'
;
import
{
addClassIfElementExists
}
from
'
../lib/utils/dom_utils
'
;
class
DropdownUser
extends
gl
.
FilteredSearchDropdown
{
class
DropdownUser
extends
gl
.
FilteredSearchDropdown
{
constructor
(
droplab
,
dropdown
,
input
,
tokenKeys
,
filter
)
{
constructor
(
droplab
,
dropdown
,
input
,
tokenKeys
,
filter
)
{
...
@@ -32,11 +33,7 @@ class DropdownUser extends gl.FilteredSearchDropdown {
...
@@ -32,11 +33,7 @@ class DropdownUser extends gl.FilteredSearchDropdown {
}
}
hideCurrentUser
()
{
hideCurrentUser
()
{
const
currentUserItem
=
this
.
dropdown
.
querySelector
(
'
.js-current-user
'
);
addClassIfElementExists
(
this
.
dropdown
.
querySelector
(
'
.js-current-user
'
),
'
hidden
'
);
if
(
currentUserItem
)
{
currentUserItem
.
classList
.
add
(
'
hidden
'
);
}
}
}
itemClicked
(
e
)
{
itemClicked
(
e
)
{
...
...
app/assets/javascripts/filtered_search/filtered_search_manager.js
View file @
6ab12777
...
@@ -3,6 +3,7 @@ import RecentSearchesRoot from './recent_searches_root';
...
@@ -3,6 +3,7 @@ import RecentSearchesRoot from './recent_searches_root';
import
RecentSearchesStore
from
'
./stores/recent_searches_store
'
;
import
RecentSearchesStore
from
'
./stores/recent_searches_store
'
;
import
RecentSearchesService
from
'
./services/recent_searches_service
'
;
import
RecentSearchesService
from
'
./services/recent_searches_service
'
;
import
eventHub
from
'
./event_hub
'
;
import
eventHub
from
'
./event_hub
'
;
import
{
addClassIfElementExists
}
from
'
../lib/utils/dom_utils
'
;
class
FilteredSearchManager
{
class
FilteredSearchManager
{
constructor
(
page
)
{
constructor
(
page
)
{
...
@@ -227,11 +228,7 @@ class FilteredSearchManager {
...
@@ -227,11 +228,7 @@ class FilteredSearchManager {
}
}
addInputContainerFocus
()
{
addInputContainerFocus
()
{
const
inputContainer
=
this
.
filteredSearchInput
.
closest
(
'
.filtered-search-box
'
);
addClassIfElementExists
(
this
.
filteredSearchInput
.
closest
(
'
.filtered-search-box
'
),
'
focus
'
);
if
(
inputContainer
)
{
inputContainer
.
classList
.
add
(
'
focus
'
);
}
}
}
removeInputContainerFocus
(
e
)
{
removeInputContainerFocus
(
e
)
{
...
...
app/assets/javascripts/lib/utils/dom_utils.js
0 → 100644
View file @
6ab12777
/* eslint-disable import/prefer-default-export */
export
const
addClassIfElementExists
=
(
element
,
className
)
=>
{
if
(
element
)
{
element
.
classList
.
add
(
className
);
}
};
spec/javascripts/lib/utils/dom_utils_spec.js
0 → 100644
View file @
6ab12777
import
{
addClassIfElementExists
}
from
'
~/lib/utils/dom_utils
'
;
describe
(
'
DOM Utils
'
,
()
=>
{
describe
(
'
addClassIfElementExists
'
,
()
=>
{
const
className
=
'
biology
'
;
const
fixture
=
`
<div class="parent">
<div class="child"></div>
</div>
`
;
let
parentElement
;
beforeEach
(()
=>
{
setFixtures
(
fixture
);
parentElement
=
document
.
querySelector
(
'
.parent
'
);
});
it
(
'
adds class if element exists
'
,
()
=>
{
const
childElement
=
parentElement
.
querySelector
(
'
.child
'
);
expect
(
childElement
).
not
.
toBe
(
null
);
addClassIfElementExists
(
childElement
,
className
);
expect
(
childElement
.
classList
).
toContain
(
className
);
});
it
(
'
does not throw if element does not exist
'
,
()
=>
{
const
childElement
=
parentElement
.
querySelector
(
'
.other-child
'
);
expect
(
childElement
).
toBe
(
null
);
addClassIfElementExists
(
childElement
,
className
);
});
});
});
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