Fix GFM JS code style

This commit is contained in:
Riyad Preukschas 2012-11-21 20:02:03 +01:00
parent 0046409970
commit 1cda62465f
2 changed files with 32 additions and 28 deletions

View file

@ -1,47 +1,51 @@
# Creates the variables for setting up GFM auto-completion
window.GitLab ?= {}
window.GitLab.AutoComplete ?= {}
# Emoji
data = []
template = "<li data-value='${insert}'>${name} <img alt='${name}' height='20' src='${image}' width='20' /></li>"
window.autocompleteEmoji = {data, template}
window.GitLab.AutoComplete.Emoji = {data, template}
# Team Members
url = '';
params = {private_token: '', page: 1}
window.autocompleteMembers = {data, url, params}
window.GitLab.AutoComplete.Members = {data, url, params}
# Add GFM auto-completion to all input fields, that accept GFM input.
window.setupGfmAutoComplete = ->
$input = $('.js-gfm-input')
input = $('.js-gfm-input')
# Emoji
$input.atWho ':',
data: autocompleteEmoji.data,
tpl: autocompleteEmoji.template
input.atWho ':',
data: GitLab.AutoComplete.Emoji.data,
tpl: GitLab.AutoComplete.Emoji.template
# Team Members
$input.atWho '@', (query, callback) ->
input.atWho '@', (query, callback) ->
(getMoreMembers = ->
$.getJSON(autocompleteMembers.url, autocompleteMembers.params).success (members) ->
# pick the data we need
newMembersData = $.map members, (m) -> m.name
$.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 autocompleteMembers.data, newMembersData
# 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 autocompleteMembers.data[..]
# 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: autocompleteMembers.data
callback: null
else
# get next page
getMoreMembers()
# 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()
# so the next request gets the next page
autocompleteMembers.params.page += 1
GitLab.AutoComplete.Members.params.page += 1
).call()

View file

@ -1,11 +1,11 @@
:javascript
$(function() {
autocompleteMembers.url = "#{ "/api/v2/projects/#{@project.code}/members" if @project }";
autocompleteMembers.params.private_token = "#{current_user.private_token}";
GitLab.AutoComplete.Members.url = "#{ "/api/v2/projects/#{@project.code}/members" if @project }";
GitLab.AutoComplete.Members.params.private_token = "#{current_user.private_token}";
autocompleteEmoji.data = #{raw emoji_autocomplete_source};
GitLab.AutoComplete.Emoji.data = #{raw emoji_autocomplete_source};
// convert the list so that the items have the right format for completion
autocompleteEmoji.data = $.map(autocompleteEmoji.data, function(value) {
GitLab.AutoComplete.Emoji.data = $.map(GitLab.AutoComplete.Emoji.data, function(value) {
return {
name: value,
insert: value+':',