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
57c134c3
Commit
57c134c3
authored
Oct 16, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup coffeescript code for mentions auto-complete
parent
ec1bccb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
51 deletions
+41
-51
app/assets/javascripts/gfm_auto_complete.js.coffee
app/assets/javascripts/gfm_auto_complete.js.coffee
+37
-47
app/views/layouts/_init_auto_complete.html.haml
app/views/layouts/_init_auto_complete.html.haml
+4
-4
No files found.
app/assets/javascripts/gfm_auto_complete.js.coffee
View file @
57c134c3
# Creates the variables for setting up GFM auto-completion
###
Creates the variables for setting up GFM auto-completion
###
# Emoji
window
.
autocompleteEmojiData
=
[];
window
.
autocompleteEmojiTemplate
=
"<li data-value='${insert}'>${name} <img alt='${name}' height='20' src='${image}' width='20' /></li>"
;
data
=
[]
template
=
"<li data-value='${insert}'>${name} <img alt='${name}' height='20' src='${image}' width='20' /></li>"
window
.
autocompleteEmoji
=
{
data
,
template
}
# Team Members
window
.
autocompleteMembersUrl
=
""
;
window
.
autocompleteMembersParams
=
private_token
:
""
page
:
1
window
.
autocompleteMembersData
=
[];
url
=
''
;
params
=
{
private_token
:
''
,
page
:
1
}
window
.
autocompleteMembers
=
{
data
,
url
,
params
}
# Add GFM auto-completion to all input fields, that accept GFM input.
window
.
setupGfmAutoComplete
=
->
$input
=
$
(
'.js-gfm-input'
)
# Emoji
$input
.
atWho
':'
,
data
:
autocompleteEmoji
.
data
,
tpl
:
autocompleteEmoji
.
template
###
Add GFM auto-completion to all input fields, that accept GFM input.
###
window
.
setupGfmAutoComplete
=
->
###
Emoji
###
$
(
'.js-gfm-input'
).
atWho
':'
,
data
:
autocompleteEmojiData
,
tpl
:
autocompleteEmojiTemplate
###
Team Members
###
$
(
'.js-gfm-input'
).
atWho
'@'
,
(
query
,
callback
)
->
# Team Members
$input
.
atWho
'@'
,
(
query
,
callback
)
->
(
getMoreMembers
=
->
$
.
getJSON
(
autocompleteMembersUrl
,
autocompleteMembersParams
)
.
success
(
members
)
->
# pick the data we need
newMembersData
=
$
.
map
members
,
(
m
)
->
m
.
name
# add the new page of data to the rest
$
.
merge
autocompleteMembersData
,
newMembersData
# show the pop-up with a copy of the current data
callback
autocompleteMembersData
[..]
# are we past the last page?
if
newMembersData
.
length
==
0
# set static data and stop callbacks
$
(
'.js-gfm-input'
).
atWho
'@'
,
data
:
autocompleteMembersData
callback
:
null
else
# get next page
getMoreMembers
()
$
.
getJSON
(
autocompleteMembers
.
url
,
autocompleteMembers
.
params
).
success
(
members
)
->
# pick the data we need
newMembersData
=
$
.
map
members
,
(
m
)
->
m
.
name
# add the new page of data to the rest
$
.
merge
autocompleteMembers
.
data
,
newMembersData
# show the pop-up with a copy of the current data
callback
autocompleteMembers
.
data
[..]
# are we past the last page?
if
newMembersData
.
length
is
0
# set static data and stop callbacks
$input
.
atWho
'@'
,
data
:
autocompleteMembers
.
data
callback
:
null
else
# get next page
getMoreMembers
()
# so the next request gets the next page
autocompleteMembers
Params
.
page
+=
1
;
).
call
()
;
autocompleteMembers
.
params
.
page
+=
1
).
call
()
app/views/layouts/_init_auto_complete.html.haml
View file @
57c134c3
:javascript
$
(
function
()
{
autocompleteMembers
U
rl
=
"
#{
"/api/v2/projects/#{@project.code}/members"
if
@project
}
"
;
autocompleteMembers
Params
.
private_token
=
"
#{
current_user
.
authentication
_token
}
"
;
autocompleteMembers
.
u
rl
=
"
#{
"/api/v2/projects/#{@project.code}/members"
if
@project
}
"
;
autocompleteMembers
.
params
.
private_token
=
"
#{
current_user
.
private
_token
}
"
;
autocompleteEmoji
D
ata
=
#{
raw
emoji_autocomplete_source
}
;
autocompleteEmoji
.
d
ata
=
#{
raw
emoji_autocomplete_source
}
;
// convert the list so that the items have the right format for completion
autocompleteEmoji
Data
=
$
.
map
(
autocompleteEmojiD
ata
,
function
(
value
)
{
autocompleteEmoji
.
data
=
$
.
map
(
autocompleteEmoji
.
d
ata
,
function
(
value
)
{
return
{
name
:
value
,
insert
:
value
+
'
:
'
,
...
...
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