Replace keystrokes in tooltips

This commit is contained in:
Ben Ogle
2013-11-21 16:53:38 -08:00
parent 01c141eec6
commit 18399aa264
2 changed files with 49 additions and 2 deletions

View File

@@ -22,9 +22,39 @@ tooltipDefaults =
container: 'body'
html: true
modifiers =
cmd: ''
option: ''
ctrl: ''
shift: ''
left: ''
right: ''
up: ''
down: ''
replaceKey = (key) ->
if modifiers[key]
modifiers[key]
else if key.length == 1 and key == key.toUpperCase() and key.toUpperCase() != key.toLowerCase()
[modifiers.shift, key.toUpperCase()]
else if key.length == 1
key.toUpperCase()
else
key
replaceModifiersInSingleKeystroke = (keystroke) ->
keys = keystroke.split('-')
keys = _.flatten(replaceKey(key) for key in keys)
keys.join('')
replaceModifiers = (keystroke) ->
keystrokes = keystroke.split(' ')
keystrokes = (replaceModifiersInSingleKeystroke(stroke) for stroke in keystrokes)
keystrokes.join(' ')
getKeystroke = (bindings) ->
if bindings?.length
"<span class=\"keystroke\">#{bindings[0].keystroke}</span>"
"<span class=\"keystroke\">#{replaceModifiers(bindings[0].keystroke)}</span>"
else
''
@@ -38,4 +68,7 @@ jQuery.fn.setTooltip = (title, {command, commandElement}={}) ->
this.tooltip(jQuery.extend(tooltipDefaults, {title: "#{title} #{getKeystroke(bindings)}"}))
jQuery.fn.setTooltip.getKeystroke = getKeystroke
jQuery.fn.setTooltip.replaceModifiers = replaceModifiers
module.exports = spacePen