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
|
|
|
|
|
|
|
# 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>"
|
|
|
|
window.autocompleteEmoji = {data, template}
|
2012-10-10 00:16:52 +02:00
|
|
|
|
|
|
|
# Team Members
|
2012-10-16 13:01:40 +02:00
|
|
|
url = '';
|
|
|
|
params = {private_token: '', page: 1}
|
|
|
|
window.autocompleteMembers = {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.
|
|
|
|
window.setupGfmAutoComplete = ->
|
|
|
|
$input = $('.js-gfm-input')
|
2012-10-10 00:16:52 +02:00
|
|
|
|
2012-10-16 13:01:40 +02:00
|
|
|
# Emoji
|
|
|
|
$input.atWho ':',
|
|
|
|
data: autocompleteEmoji.data,
|
|
|
|
tpl: autocompleteEmoji.template
|
2012-10-10 00:16:52 +02:00
|
|
|
|
2012-10-16 13:01:40 +02:00
|
|
|
# Team Members
|
|
|
|
$input.atWho '@', (query, callback) ->
|
2012-10-10 00:16:52 +02:00
|
|
|
(getMoreMembers = ->
|
2012-10-16 13:01:40 +02:00
|
|
|
$.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()
|
2012-10-10 00:16:52 +02:00
|
|
|
|
|
|
|
# so the next request gets the next page
|
2012-10-16 13:01:40 +02:00
|
|
|
autocompleteMembers.params.page += 1
|
|
|
|
).call()
|