2012-10-16 07:01:40 -04:00
|
|
|
# Creates the variables for setting up GFM auto-completion
|
2012-10-09 18:16:52 -04:00
|
|
|
|
2012-11-21 14:02:03 -05:00
|
|
|
window.GitLab ?= {}
|
|
|
|
window.GitLab.AutoComplete ?= {}
|
|
|
|
|
2012-10-09 18:16:52 -04:00
|
|
|
# Emoji
|
2012-10-16 07:01:40 -04:00
|
|
|
data = []
|
|
|
|
template = "<li data-value='${insert}'>${name} <img alt='${name}' height='20' src='${image}' width='20' /></li>"
|
2012-11-21 14:02:03 -05:00
|
|
|
window.GitLab.AutoComplete.Emoji = {data, template}
|
2012-10-09 18:16:52 -04:00
|
|
|
|
|
|
|
# Team Members
|
2012-10-16 07:01:40 -04:00
|
|
|
url = '';
|
|
|
|
params = {private_token: '', page: 1}
|
2012-11-21 14:02:03 -05:00
|
|
|
window.GitLab.AutoComplete.Members = {data, url, params}
|
2012-10-09 18:16:52 -04:00
|
|
|
|
2012-10-16 07:01:40 -04:00
|
|
|
# Add GFM auto-completion to all input fields, that accept GFM input.
|
|
|
|
window.setupGfmAutoComplete = ->
|
2012-11-21 14:02:03 -05:00
|
|
|
input = $('.js-gfm-input')
|
2012-10-09 18:16:52 -04:00
|
|
|
|
2012-10-16 07:01:40 -04:00
|
|
|
# Emoji
|
2012-11-21 14:02:03 -05:00
|
|
|
input.atWho ':',
|
|
|
|
data: GitLab.AutoComplete.Emoji.data,
|
|
|
|
tpl: GitLab.AutoComplete.Emoji.template
|
2012-10-09 18:16:52 -04:00
|
|
|
|
2012-10-16 07:01:40 -04:00
|
|
|
# Team Members
|
2012-11-21 14:02:03 -05:00
|
|
|
input.atWho '@', (query, callback) ->
|
2012-10-09 18:16:52 -04:00
|
|
|
(getMoreMembers = ->
|
2012-11-21 14:02:03 -05:00
|
|
|
$.getJSON(GitLab.AutoComplete.Members.url, GitLab.AutoComplete.Members.params)
|
|
|
|
.success (members) ->
|
|
|
|
# pick the data we need
|
|
|
|
newMembersData = $.map(members, (m) -> m.name )
|
|
|
|
|
|
|
|
# add the new page of data to the rest
|
|
|
|
$.merge(GitLab.AutoComplete.Members.data, newMembersData)
|
|
|
|
|
|
|
|
# show the pop-up with a copy of the current data
|
|
|
|
callback(GitLab.AutoComplete.Members.data[..])
|
|
|
|
|
|
|
|
# are we past the last page?
|
|
|
|
if newMembersData.length is 0
|
|
|
|
# set static data and stop callbacks
|
|
|
|
input.atWho '@',
|
|
|
|
data: GitLab.AutoComplete.Members.data
|
|
|
|
callback: null
|
|
|
|
else
|
|
|
|
# get next page
|
|
|
|
getMoreMembers()
|
2012-10-09 18:16:52 -04:00
|
|
|
|
|
|
|
# so the next request gets the next page
|
2012-11-21 14:02:03 -05:00
|
|
|
GitLab.AutoComplete.Members.params.page += 1
|
2012-10-16 07:01:40 -04:00
|
|
|
).call()
|