BigW Consortium Gitlab

shortcuts.js.coffee 767 Bytes
Newer Older
1
class @Shortcuts
2
  constructor: ->
3 4 5 6 7 8 9 10 11
    @enabledHelp = []
    Mousetrap.reset()
    Mousetrap.bind('?', @selectiveHelp)
    Mousetrap.bind('s', Shortcuts.focusSearch)

  selectiveHelp: (e) =>
    Shortcuts.showHelp(e, @enabledHelp)
      
  @showHelp: (e, location) ->
12 13 14 15 16
    if $('#modal-shortcuts').length > 0
      $('#modal-shortcuts').modal('show')
    else
      $.ajax(
        url: '/help/shortcuts',
17 18 19 20 21 22 23 24
        dataType: 'script',
        success: (e) ->
          if location and location.length > 0
            for l in location
              $(l).show()
          else
            $('.hidden-shortcut').show()
            $('.js-more-help-button').remove()
25
      )
26
      e.preventDefault()
27

28 29 30
  @focusSearch: (e) ->
    $('#search').focus()
    e.preventDefault()