Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 52 lines (41 sloc) 1.628 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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.GitLab.AutoComplete.Emoji = {data, template}

# Team Members
url = '';
params = {private_token: '', page: 1}
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')

  # Emoji
  input.atWho ':',
    data: GitLab.AutoComplete.Emoji.data,
    tpl: GitLab.AutoComplete.Emoji.template

  # Team Members
  input.atWho '@', (query, callback) ->
    (getMoreMembers = ->
      $.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()

      # so the next request gets the next page
      GitLab.AutoComplete.Members.params.page += 1
    ).call()
Something went wrong with that request. Please try again.