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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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
Show 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,32 +45,7 @@ class @SearchAutocomplete
...
@@ -43,32 +45,7 @@ class @SearchAutocomplete
saveOriginalState
:
->
saveOriginalState
:
->
@
originalState
=
@
serializeState
()
@
originalState
=
@
serializeState
()
serializeState
:
->
createAutocomplete
:
->
{
# Search Criteria
project_id
:
@
projectInputEl
.
val
()
group_id
:
@
groupInputEl
.
val
()
search_code
:
@
searchCodeInputEl
.
val
()
repository_ref
:
@
repositoryInputEl
.
val
()
scope
:
@
scopeInputEl
.
val
()
# Location badge
_location
:
$
.
trim
(
@
locationText
.
text
())
}
bindEvents
:
->
@
searchInput
.
on
'keydown'
,
@
onSearchInputKeyDown
@
searchInput
.
on
'focus'
,
@
onSearchInputFocus
@
searchInput
.
on
'blur'
,
@
onSearchInputBlur
@
clearInput
.
on
'click'
,
@
onRemoveLocationClick
enableAutocomplete
:
->
return
if
@
autocomplete
dropdownMenu
=
@
dropdown
.
find
(
'.dropdown-menu'
)
_this
=
@
loading
=
false
@
searchInput
.
glDropdown
@
searchInput
.
glDropdown
filterInputBlur
:
false
filterInputBlur
:
false
filterable
:
true
filterable
:
true
...
@@ -77,22 +54,26 @@ class @SearchAutocomplete
...
@@ -77,22 +54,26 @@ class @SearchAutocomplete
filterInput
:
'input#search'
filterInput
:
'input#search'
search
:
search
:
fields
:
[
'text'
]
fields
:
[
'text'
]
data
:
(
term
,
callback
)
->
data
:
@
getData
.
bind
(
@
)
getData
:
(
term
,
callback
)
->
_this
=
@
# Ensure this is not called when autocomplete is disabled because
# Ensure this is not called when autocomplete is disabled because
# this method still will be called because `GitLabDropdownFilter` is triggering this on keyup
# this method still will be called because `GitLabDropdownFilter` is triggering this on keyup
return
if
_this
.
autocomplete
is
false
return
if
@
autocomplete
is
false
# Do not trigger request if input is empty
# Do not trigger request if input is empty
return
if
_this
.
searchInput
.
val
()
is
''
return
if
@
searchInput
.
val
()
is
''
# Prevent multiple ajax calls
# Prevent multiple ajax calls
return
if
loading
return
if
@
loadingSuggestions
loading
=
true
@
loadingSuggestions
=
true
jqXHR
=
$
.
get
(
_this
.
autocompletePath
,
{
jqXHR
=
$
.
get
(
@
autocompletePath
,
{
project_id
:
_this
.
projectId
project_id
:
@
projectId
project_ref
:
_this
.
projectRef
project_ref
:
@
projectRef
term
:
term
term
:
term
},
(
response
)
->
},
(
response
)
->
data
=
[]
data
=
[]
...
@@ -113,7 +94,34 @@ class @SearchAutocomplete
...
@@ -113,7 +94,34 @@ class @SearchAutocomplete
callback
(
data
)
callback
(
data
)
).
always
->
).
always
->
loading
=
false
_this
.
loadingSuggestions
=
false
serializeState
:
->
{
# Search Criteria
project_id
:
@
projectInputEl
.
val
()
group_id
:
@
groupInputEl
.
val
()
search_code
:
@
searchCodeInputEl
.
val
()
repository_ref
:
@
repositoryInputEl
.
val
()
scope
:
@
scopeInputEl
.
val
()
# Location badge
_location
:
$
.
trim
(
@
locationText
.
text
())
}
bindEvents
:
->
@
searchInput
.
on
'keyup'
,
@
onSearchInputKeyUp
@
searchInput
.
on
'click'
,
@
onSearchInputClick
@
searchInput
.
on
'focus'
,
@
onSearchInputFocus
@
searchInput
.
on
'blur'
,
@
onSearchInputBlur
@
clearInput
.
on
'click'
,
@
onRemoveLocationClick
enableAutocomplete
:
->
return
if
@
autocomplete
dropdownMenu
=
@
dropdown
.
find
(
'.dropdown-menu'
)
_this
=
@
@
loadingSuggestions
=
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
# We should display the menu only when input is not empty
if
@
searchInput
.
val
()
isnt
''
@
enableAutocomplete
()
@
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