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