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)
|
2016-03-07 09:35:26 -05:00
|
|
|
Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview)
|
2016-01-19 14:25:27 -05:00
|
|
|
Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL?
|
2014-08-21 04:14:31 -04:00
|
|
|
|
|
|
|
selectiveHelp: (e) =>
|
|
|
|
Shortcuts.showHelp(e, @enabledHelp)
|
2015-12-27 20:34:46 -05:00
|
|
|
|
2016-03-07 09:35:26 -05:00
|
|
|
toggleMarkdownPreview: (e) =>
|
|
|
|
$(document).triggerHandler('markdown-preview:toggle', [e])
|
|
|
|
|
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
|
2016-02-29 03:11:00 -05:00
|
|
|
url = '/help/shortcuts'
|
|
|
|
url = gon.relative_url_root + url if gon.relative_url_root?
|
2013-06-30 15:10:52 -04:00
|
|
|
$.ajax(
|
2016-02-29 03:11:00 -05:00
|
|
|
url: url,
|
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()
|
2016-03-07 09:35:26 -05:00
|
|
|
|
|
|
|
Mousetrap.stopCallback = (->
|
|
|
|
defaultStopCallback = Mousetrap.stopCallback
|
|
|
|
|
|
|
|
return (e, element, combo) ->
|
|
|
|
# allowed shortcuts if textarea, input, contenteditable are focused
|
|
|
|
if ['ctrl+shift+p', 'command+shift+p'].indexOf(combo) != -1
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
return defaultStopCallback.apply(@, arguments)
|
|
|
|
)()
|