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