debian-mirror-gitlab/app/assets/javascripts/shortcuts.js.coffee

38 lines
1 KiB
CoffeeScript
Raw Normal View History

2015-04-26 12:48:37 +05:30
class @Shortcuts
2014-09-02 18:07:02 +05:30
constructor: ->
2015-04-26 12:48:37 +05:30
@enabledHelp = []
Mousetrap.reset()
Mousetrap.bind('?', @selectiveHelp)
Mousetrap.bind('s', Shortcuts.focusSearch)
2016-01-29 22:53:50 +05:30
Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL?
2015-04-26 12:48:37 +05:30
selectiveHelp: (e) =>
Shortcuts.showHelp(e, @enabledHelp)
2015-04-26 12:48:37 +05:30
@showHelp: (e, location) ->
2014-09-02 18:07:02 +05:30
if $('#modal-shortcuts').length > 0
$('#modal-shortcuts').modal('show')
else
2016-04-02 18:10:28 +05:30
url = '/help/shortcuts'
url = gon.relative_url_root + url if gon.relative_url_root?
2014-09-02 18:07:02 +05:30
$.ajax(
2016-04-02 18:10:28 +05:30
url: url,
2015-04-26 12:48:37 +05:30
dataType: 'script',
success: (e) ->
if location and location.length > 0
$(l).show() for l in location
2015-04-26 12:48:37 +05:30
else
$('.hidden-shortcut').show()
$('.js-more-help-button').remove()
2014-09-02 18:07:02 +05:30
)
2015-04-26 12:48:37 +05:30
e.preventDefault()
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
@focusSearch: (e) ->
$('#search').focus()
e.preventDefault()
$(document).on 'click.more_help', '.js-more-help-button', (e) ->
$(@).remove()
$('.hidden-shortcut').show()
e.preventDefault()