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
Boxiang Sun
gitlab-ce
Commits
b4593a1b
Commit
b4593a1b
authored
Mar 18, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multiple ajax calls and plugin instantiation
parent
9008457a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
17 deletions
+38
-17
app/assets/javascripts/search_autocomplete.js.coffee
app/assets/javascripts/search_autocomplete.js.coffee
+38
-17
No files found.
app/assets/javascripts/search_autocomplete.js.coffee
View file @
b4593a1b
...
...
@@ -33,6 +33,7 @@ class @SearchAutocomplete
@
saveOriginalState
()
@
searchInput
.
addClass
(
'disabled'
)
@
autocomplete
=
false
@
bindEvents
()
...
...
@@ -61,8 +62,12 @@ class @SearchAutocomplete
@
searchInput
.
on
'blur'
,
@
onSearchInputBlur
enableAutocomplete
:
->
return
if
@
autocomplete
dropdownMenu
=
@
dropdown
.
find
(
'.dropdown-menu'
)
_this
=
@
loading
=
false
@
searchInput
.
glDropdown
filterInputBlur
:
false
filterable
:
true
...
...
@@ -72,7 +77,19 @@ class @SearchAutocomplete
search
:
fields
:
[
'text'
]
data
:
(
term
,
callback
)
->
$
.
get
(
_this
.
autocompletePath
,
{
# 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
...
...
@@ -99,7 +116,8 @@ class @SearchAutocomplete
text
:
item
.
label
url
:
item
.
url
callback
(
data
)
)
).
always
->
loading
=
false
@
dropdown
.
addClass
(
'open'
)
@
searchInput
.
removeClass
(
'disabled'
)
...
...
@@ -109,23 +127,26 @@ class @SearchAutocomplete
@
dropdown
.
dropdown
(
'toggle'
)
onSearchInputKeyDown
:
(
e
)
=>
# Remove tag when pressing backspace and input search is empty
if
e
.
keyCode
is
KEYCODE
.
BACKSPACE
and
e
.
currentTarget
.
value
is
''
@
removeLocationBadge
()
@
searchInput
.
focus
()
switch
e
.
keyCode
when
KEYCODE
.
BACKSPACE
if
e
.
currentTarget
.
value
is
''
@
removeLocationBadge
()
@
searchInput
.
focus
()
when
KEYCODE
.
ESCAPE
if
@
badgePresent
()
else
@
restoreOriginalState
()
else
if
e
.
keyCode
is
KEYCODE
.
ESCAPE
@
searchInput
.
val
(
''
)
@
restoreOriginalState
()
else
# Create new autocomplete if it hasn't been created yet and there's no badge
if
@
autocomplete
is
undefined
if
!
@
badgePresent
()
@
enableAutocomplete
()
# If after restoring there's a badge
@
disableAutocomplete
()
if
@
badgePresent
()
else
# There's a badge
if
@
badgePresent
()
@
disableAutocomplete
()
else
@
enableAutocomplete
()
# Avoid falsy value to be returned
return
onSearchInputFocus
:
=>
@
wrap
.
addClass
(
'search-active'
)
...
...
@@ -193,6 +214,6 @@ class @SearchAutocomplete
@
resetSearchState
()
disableAutocomplete
:
->
if
@
autocomplete
?
if
@
autocomplete
@
searchInput
.
addClass
(
'disabled'
)
@
autocomplete
=
null
@
autocomplete
=
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