Commit 3e800c3b authored by Riyad Preukschas's avatar Riyad Preukschas

Refactor GFM JS naming and access

parent 1cda6246
# Creates the variables for setting up GFM auto-completion # Creates the variables for setting up GFM auto-completion
window.GitLab ?= {} window.GitLab ?= {}
window.GitLab.AutoComplete ?= {} GitLab.GfmAutoComplete ?= {}
# Emoji # Emoji
data = [] data = []
template = "<li data-value='${insert}'>${name} <img alt='${name}' height='20' src='${image}' width='20' /></li>" template = "<li data-value='${insert}'>${name} <img alt='${name}' height='20' src='${image}' width='20' /></li>"
window.GitLab.AutoComplete.Emoji = {data, template} GitLab.GfmAutoComplete.Emoji = {data, template}
# Team Members # Team Members
data = []
url = ''; url = '';
params = {private_token: '', page: 1} params = {private_token: '', page: 1}
window.GitLab.AutoComplete.Members = {data, url, params} GitLab.GfmAutoComplete.Members = {data, url, params}
# Add GFM auto-completion to all input fields, that accept GFM input. # Add GFM auto-completion to all input fields, that accept GFM input.
window.setupGfmAutoComplete = -> GitLab.GfmAutoComplete.setup = ->
input = $('.js-gfm-input') input = $('.js-gfm-input')
# Emoji # Emoji
input.atWho ':', input.atWho ':',
data: GitLab.AutoComplete.Emoji.data, data: GitLab.GfmAutoComplete.Emoji.data,
tpl: GitLab.AutoComplete.Emoji.template tpl: GitLab.GfmAutoComplete.Emoji.template
# Team Members # Team Members
input.atWho '@', (query, callback) -> input.atWho '@', (query, callback) ->
(getMoreMembers = -> (getMoreMembers = ->
$.getJSON(GitLab.AutoComplete.Members.url, GitLab.AutoComplete.Members.params) $.getJSON(GitLab.GfmAutoComplete.Members.url, GitLab.GfmAutoComplete.Members.params)
.success (members) -> .success (members) ->
# pick the data we need # pick the data we need
newMembersData = $.map(members, (m) -> m.name ) newMembersData = $.map(members, (m) -> m.name )
# add the new page of data to the rest # add the new page of data to the rest
$.merge(GitLab.AutoComplete.Members.data, newMembersData) $.merge(GitLab.GfmAutoComplete.Members.data, newMembersData)
# show the pop-up with a copy of the current data # show the pop-up with a copy of the current data
callback(GitLab.AutoComplete.Members.data[..]) callback(GitLab.GfmAutoComplete.Members.data[..])
# are we past the last page? # are we past the last page?
if newMembersData.length is 0 if newMembersData.length is 0
# set static data and stop callbacks # set static data and stop callbacks
input.atWho '@', input.atWho '@',
data: GitLab.AutoComplete.Members.data data: GitLab.GfmAutoComplete.Members.data
callback: null callback: null
else else
# get next page # get next page
getMoreMembers() getMoreMembers()
# so the next request gets the next page # so the next request gets the next page
GitLab.AutoComplete.Members.params.page += 1 GitLab.GfmAutoComplete.Members.params.page += 1
).call() ).call()
...@@ -5,7 +5,7 @@ function switchToNewIssue(){ ...@@ -5,7 +5,7 @@ function switchToNewIssue(){
$("#new_issue_dialog").show("fade", { direction: "right" }, 150); $("#new_issue_dialog").show("fade", { direction: "right" }, 150);
$('.top-tabs .add_new').hide(); $('.top-tabs .add_new').hide();
disableButtonIfEmptyField("#issue_title", ".save-btn"); disableButtonIfEmptyField("#issue_title", ".save-btn");
setupGfmAutoComplete(); GitLab.GfmAutoComplete.setup();
}); });
} }
...@@ -16,7 +16,7 @@ function switchToEditIssue(){ ...@@ -16,7 +16,7 @@ function switchToEditIssue(){
$("#edit_issue_dialog").show("fade", { direction: "right" }, 150); $("#edit_issue_dialog").show("fade", { direction: "right" }, 150);
$('.add_new').hide(); $('.add_new').hide();
disableButtonIfEmptyField("#issue_title", ".save-btn"); disableButtonIfEmptyField("#issue_title", ".save-btn");
setupGfmAutoComplete(); GitLab.GfmAutoComplete.setup();
}); });
} }
......
:javascript :javascript
$(function() { $(function() {
GitLab.AutoComplete.Members.url = "#{ "/api/v2/projects/#{@project.code}/members" if @project }"; GitLab.GfmAutoComplete.Members.url = "#{ "/api/v2/projects/#{@project.code}/members" if @project }";
GitLab.AutoComplete.Members.params.private_token = "#{current_user.private_token}"; GitLab.GfmAutoComplete.Members.params.private_token = "#{current_user.private_token}";
GitLab.AutoComplete.Emoji.data = #{raw emoji_autocomplete_source}; GitLab.GfmAutoComplete.Emoji.data = #{raw emoji_autocomplete_source};
// convert the list so that the items have the right format for completion // convert the list so that the items have the right format for completion
GitLab.AutoComplete.Emoji.data = $.map(GitLab.AutoComplete.Emoji.data, function(value) { GitLab.GfmAutoComplete.Emoji.data = $.map(GitLab.GfmAutoComplete.Emoji.data, function(value) {
return { return {
name: value, name: value,
insert: value+':', insert: value+':',
...@@ -13,5 +13,5 @@ ...@@ -13,5 +13,5 @@
} }
}); });
setupGfmAutoComplete(); GitLab.GfmAutoComplete.setup();
}); });
...@@ -10,5 +10,5 @@ ...@@ -10,5 +10,5 @@
- else - else
:plain :plain
$(".note-form-holder").replaceWith("#{escape_javascript(render 'form')}"); $(".note-form-holder").replaceWith("#{escape_javascript(render 'form')}");
setupGfmAutoComplete();
GitLab.GfmAutoComplete.setup();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment