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

54 lines
1.4 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()
2016-06-02 11:05:42 +05:30
Mousetrap.bind('?', @onToggleHelp)
2015-04-26 12:48:37 +05:30
Mousetrap.bind('s', Shortcuts.focusSearch)
2016-06-02 11:05:42 +05:30
Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview)
2016-01-29 22:53:50 +05:30
Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL?
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
onToggleHelp: (e) =>
e.preventDefault()
@toggleHelp(@enabledHelp)
2016-06-02 11:05:42 +05:30
toggleMarkdownPreview: (e) =>
$(document).triggerHandler('markdown-preview:toggle', [e])
toggleHelp: (location) ->
$modal = $('#modal-shortcuts')
if $modal.length
$modal.modal('toggle')
return
$.ajax(
url: gon.shortcuts_path,
dataType: 'script',
success: (e) ->
if location and location.length > 0
$(l).show() for l in location
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
@focusSearch: (e) ->
$('#search').focus()
e.preventDefault()
$(document).on 'click.more_help', '.js-more-help-button', (e) ->
$(@).remove()
$('.hidden-shortcut').show()
e.preventDefault()
2016-06-02 11:05:42 +05:30
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)
)()