Commit 91de6e25 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Toggle help modal

parent 7f153077
...@@ -2,34 +2,37 @@ class @Shortcuts ...@@ -2,34 +2,37 @@ class @Shortcuts
constructor: -> constructor: ->
@enabledHelp = [] @enabledHelp = []
Mousetrap.reset() Mousetrap.reset()
Mousetrap.bind('?', @selectiveHelp) Mousetrap.bind('?', @onToggleHelp)
Mousetrap.bind('s', Shortcuts.focusSearch) Mousetrap.bind('s', Shortcuts.focusSearch)
Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview) Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview)
Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL? Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL?
selectiveHelp: (e) => onToggleHelp: (e) =>
Shortcuts.showHelp(e, @enabledHelp) e.preventDefault()
@toggleHelp(@enabledHelp)
toggleMarkdownPreview: (e) => toggleMarkdownPreview: (e) =>
$(document).triggerHandler('markdown-preview:toggle', [e]) $(document).triggerHandler('markdown-preview:toggle', [e])
@showHelp: (e, location) -> toggleHelp: (location) ->
if $('#modal-shortcuts').length > 0 $modal = $('#modal-shortcuts')
$('#modal-shortcuts').modal('show')
else if $modal.length
url = '/help/shortcuts' $modal.modal('toggle')
url = gon.relative_url_root + url if gon.relative_url_root? return
$.ajax(
url: url, url = '/help/shortcuts'
dataType: 'script', url = gon.relative_url_root + url if gon.relative_url_root?
success: (e) -> $.ajax(
if location and location.length > 0 url: url,
$(l).show() for l in location dataType: 'script',
else success: (e) ->
$('.hidden-shortcut').show() if location and location.length > 0
$('.js-more-help-button').remove() $(l).show() for l in location
) else
e.preventDefault() $('.hidden-shortcut').show()
$('.js-more-help-button').remove()
)
@focusSearch: (e) -> @focusSearch: (e) ->
$('#search').focus() $('#search').focus()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment