gitlab-org--gitlab-foss/app/assets/javascripts/gfm_auto_complete.js.coffee

81 lines
2.1 KiB
CoffeeScript
Raw Normal View History

# Creates the variables for setting up GFM auto-completion
2012-11-21 14:02:03 -05:00
window.GitLab ?= {}
2012-12-10 18:04:47 -05:00
GitLab.GfmAutoComplete =
dataSource: ''
# Emoji
2012-12-10 18:04:47 -05:00
Emoji:
template: '<li>${name} <img alt="${name}" height="20" src="${path}" width="20" /></li>'
# Team Members
2012-12-10 18:04:47 -05:00
Members:
template: '<li>${username} <small>${title}</small></li>'
2012-12-10 18:04:47 -05:00
# Issues and MergeRequests
Issues:
template: '<li><small>${id}</small> ${title}</li>'
2012-12-10 18:04:47 -05:00
# Add GFM auto-completion to all input fields, that accept GFM input.
setup: ->
input = $('.js-gfm-input')
# Emoji
input.atwho
at: ':'
displayTpl: @Emoji.template
insertTpl: ':${name}:'
2012-12-10 18:04:47 -05:00
# Team Members
input.atwho
at: '@'
displayTpl: @Members.template
insertTpl: '${atwho-at}${username}'
searchKey: 'search'
callbacks:
beforeSave: (members) ->
$.map members, (m) ->
title = m.name
title += " (#{m.count})" if m.count
username: m.username
title: sanitize(title)
search: sanitize("#{m.username} #{m.name}")
input.atwho
at: '#'
alias: 'issues'
searchKey: 'search'
displayTpl: @Issues.template
insertTpl: '${atwho-at}${id}'
callbacks:
beforeSave: (issues) ->
$.map issues, (i) ->
id: i.iid
title: sanitize(i.title)
search: "#{i.iid} #{i.title}"
2012-12-10 18:04:47 -05:00
input.atwho
at: '!'
alias: 'mergerequests'
searchKey: 'search'
displayTpl: @Issues.template
insertTpl: '${atwho-at}${id}'
callbacks:
beforeSave: (merges) ->
$.map merges, (m) ->
id: m.iid
title: sanitize(m.title)
search: "#{m.iid} #{m.title}"
if @dataSource
$.getJSON(@dataSource).done (data) ->
# load members
input.atwho 'load', '@', data.members
# load issues
input.atwho 'load', 'issues', data.issues
# load merge requests
input.atwho 'load', 'mergerequests', data.mergerequests
# load emojis
input.atwho 'load', ':', data.emojis