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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
44817726
Commit
44817726
authored
Mar 23, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes empty menu when typing on search input for the very first time
parent
4fcd7ba9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
51 deletions
+69
-51
app/assets/javascripts/search_autocomplete.js.coffee
app/assets/javascripts/search_autocomplete.js.coffee
+65
-50
app/views/layouts/_search.html.haml
app/views/layouts/_search.html.haml
+4
-1
No files found.
app/assets/javascripts/search_autocomplete.js.coffee
View file @
44817726
...
@@ -31,6 +31,8 @@ class @SearchAutocomplete
...
@@ -31,6 +31,8 @@ class @SearchAutocomplete
@
saveOriginalState
()
@
saveOriginalState
()
@
createAutocomplete
()
@
searchInput
.
addClass
(
'disabled'
)
@
searchInput
.
addClass
(
'disabled'
)
@
autocomplete
=
false
@
autocomplete
=
false
...
@@ -43,6 +45,57 @@ class @SearchAutocomplete
...
@@ -43,6 +45,57 @@ class @SearchAutocomplete
saveOriginalState
:
->
saveOriginalState
:
->
@
originalState
=
@
serializeState
()
@
originalState
=
@
serializeState
()
createAutocomplete
:
->
@
searchInput
.
glDropdown
filterInputBlur
:
false
filterable
:
true
filterRemote
:
true
highlight
:
true
filterInput
:
'input#search'
search
:
fields
:
[
'text'
]
data
:
@
getData
.
bind
(
@
)
getData
:
(
term
,
callback
)
->
_this
=
@
# Ensure this is not called when autocomplete is disabled because
# this method still will be called because `GitLabDropdownFilter` is triggering this on keyup
return
if
@
autocomplete
is
false
# Do not trigger request if input is empty
return
if
@
searchInput
.
val
()
is
''
# Prevent multiple ajax calls
return
if
@
loadingSuggestions
@
loadingSuggestions
=
true
jqXHR
=
$
.
get
(
@
autocompletePath
,
{
project_id
:
@
projectId
project_ref
:
@
projectRef
term
:
term
},
(
response
)
->
data
=
[]
# List results
for
suggestion
in
response
# Add group header before list each group
if
lastCategory
isnt
suggestion
.
category
data
.
push
header
:
suggestion
.
category
lastCategory
=
suggestion
.
category
data
.
push
text
:
suggestion
.
label
url
:
suggestion
.
url
callback
(
data
)
).
always
->
_this
.
loadingSuggestions
=
false
serializeState
:
->
serializeState
:
->
{
{
# Search Criteria
# Search Criteria
...
@@ -57,7 +110,8 @@ class @SearchAutocomplete
...
@@ -57,7 +110,8 @@ class @SearchAutocomplete
}
}
bindEvents
:
->
bindEvents
:
->
@
searchInput
.
on
'keydown'
,
@
onSearchInputKeyDown
@
searchInput
.
on
'keyup'
,
@
onSearchInputKeyUp
@
searchInput
.
on
'click'
,
@
onSearchInputClick
@
searchInput
.
on
'focus'
,
@
onSearchInputFocus
@
searchInput
.
on
'focus'
,
@
onSearchInputFocus
@
searchInput
.
on
'blur'
,
@
onSearchInputBlur
@
searchInput
.
on
'blur'
,
@
onSearchInputBlur
@
clearInput
.
on
'click'
,
@
onRemoveLocationClick
@
clearInput
.
on
'click'
,
@
onRemoveLocationClick
...
@@ -67,53 +121,7 @@ class @SearchAutocomplete
...
@@ -67,53 +121,7 @@ class @SearchAutocomplete
dropdownMenu
=
@
dropdown
.
find
(
'.dropdown-menu'
)
dropdownMenu
=
@
dropdown
.
find
(
'.dropdown-menu'
)
_this
=
@
_this
=
@
loading
=
false
@
loadingSuggestions
=
false
@
searchInput
.
glDropdown
filterInputBlur
:
false
filterable
:
true
filterRemote
:
true
highlight
:
true
filterInput
:
'input#search'
search
:
fields
:
[
'text'
]
data
:
(
term
,
callback
)
->
# Ensure this is not called when autocomplete is disabled because
# this method still will be called because `GitLabDropdownFilter` is triggering this on keyup
return
if
_this
.
autocomplete
is
false
# Do not trigger request if input is empty
return
if
_this
.
searchInput
.
val
()
is
''
# Prevent multiple ajax calls
return
if
loading
loading
=
true
jqXHR
=
$
.
get
(
_this
.
autocompletePath
,
{
project_id
:
_this
.
projectId
project_ref
:
_this
.
projectRef
term
:
term
},
(
response
)
->
data
=
[]
# List results
for
suggestion
in
response
# Add group header before list each group
if
lastCategory
isnt
suggestion
.
category
data
.
push
header
:
suggestion
.
category
lastCategory
=
suggestion
.
category
data
.
push
text
:
suggestion
.
label
url
:
suggestion
.
url
callback
(
data
)
).
always
->
loading
=
false
@
dropdown
.
addClass
(
'open'
)
@
dropdown
.
addClass
(
'open'
)
@
searchInput
.
removeClass
(
'disabled'
)
@
searchInput
.
removeClass
(
'disabled'
)
...
@@ -122,7 +130,7 @@ class @SearchAutocomplete
...
@@ -122,7 +130,7 @@ class @SearchAutocomplete
onDropdownOpen
:
(
e
)
=>
onDropdownOpen
:
(
e
)
=>
@
dropdown
.
dropdown
(
'toggle'
)
@
dropdown
.
dropdown
(
'toggle'
)
onSearchInputKey
Down
:
(
e
)
=>
onSearchInputKey
Up
:
(
e
)
=>
switch
e
.
keyCode
switch
e
.
keyCode
when
KEYCODE
.
BACKSPACE
when
KEYCODE
.
BACKSPACE
if
e
.
currentTarget
.
value
is
''
if
e
.
currentTarget
.
value
is
''
...
@@ -139,11 +147,18 @@ class @SearchAutocomplete
...
@@ -139,11 +147,18 @@ class @SearchAutocomplete
if
@
badgePresent
()
if
@
badgePresent
()
@
disableAutocomplete
()
@
disableAutocomplete
()
else
else
@
enableAutocomplete
()
# We should display the menu only when input is not empty
if
@
searchInput
.
val
()
isnt
''
@
enableAutocomplete
()
# Avoid falsy value to be returned
# Avoid falsy value to be returned
return
return
onSearchInputClick
:
=>
if
(
@
searchInput
.
val
()
is
''
)
@
disableAutocomplete
()
onSearchInputFocus
:
=>
onSearchInputFocus
:
=>
@
wrap
.
addClass
(
'search-active'
)
@
wrap
.
addClass
(
'search-active'
)
...
...
app/views/layouts/_search.html.haml
View file @
44817726
...
@@ -15,7 +15,10 @@
...
@@ -15,7 +15,10 @@
.dropdown
{
data:
{
url:
search_autocomplete_path
}
}
.dropdown
{
data:
{
url:
search_autocomplete_path
}
}
=
search_field_tag
"search"
,
nil
,
placeholder:
'Search'
,
class:
"search-input dropdown-menu-toggle"
,
spellcheck:
false
,
tabindex:
"1"
,
autocomplete:
'off'
,
data:
{
toggle:
'dropdown'
}
=
search_field_tag
"search"
,
nil
,
placeholder:
'Search'
,
class:
"search-input dropdown-menu-toggle"
,
spellcheck:
false
,
tabindex:
"1"
,
autocomplete:
'off'
,
data:
{
toggle:
'dropdown'
}
.dropdown-menu.dropdown-select
.dropdown-menu.dropdown-select
=
dropdown_content
=
dropdown_content
do
%li
%a
.is-focused
Loading...
=
dropdown_loading
=
dropdown_loading
%i
.search-icon
%i
.search-icon
%i
.clear-icon.js-clear-input
%i
.clear-icon.js-clear-input
...
...
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