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

35 lines
881 B
CoffeeScript
Raw Normal View History

2014-08-21 08:14:31 +00:00
class @Shortcuts
2013-06-30 19:10:52 +00:00
constructor: ->
2014-08-21 08:14:31 +00:00
@enabledHelp = []
Mousetrap.reset()
Mousetrap.bind('?', @selectiveHelp)
Mousetrap.bind('s', Shortcuts.focusSearch)
selectiveHelp: (e) =>
Shortcuts.showHelp(e, @enabledHelp)
2014-08-21 08:14:31 +00:00
@showHelp: (e, location) ->
2013-06-30 19:10:52 +00:00
if $('#modal-shortcuts').length > 0
$('#modal-shortcuts').modal('show')
else
$.ajax(
url: '/help/shortcuts',
2014-08-21 08:14:31 +00:00
dataType: 'script',
success: (e) ->
if location and location.length > 0
$(l).show() for l in location
2014-08-21 08:14:31 +00:00
else
$('.hidden-shortcut').show()
$('.js-more-help-button').remove()
2013-06-30 19:10:52 +00:00
)
2014-08-21 08:14:31 +00:00
e.preventDefault()
2013-06-30 19:10:52 +00:00
2014-08-21 08:14:31 +00:00
@focusSearch: (e) ->
$('#search').focus()
e.preventDefault()
$(document).on 'click.more_help', '.js-more-help-button', (e) ->
$(@).remove()
$('.hidden-shortcut').show()
e.preventDefault()