Tooltips can now override the default options

This commit is contained in:
Ben Ogle
2013-11-22 15:02:57 -08:00
parent 5910b05344
commit 3f75512de2

View File

@@ -22,6 +22,7 @@ tooltipDefaults =
container: 'body'
html: true
placement: 'auto top'
viewportPadding: 2
modifiers =
cmd: ''
@@ -60,16 +61,20 @@ getKeystroke = (bindings) ->
"<span class=\"keystroke\">#{replaceModifiers(bindings[0].keystroke)}</span>"
else
''
jQuery.fn.setTooltip = (title, {command, commandElement}={}) ->
# options from http://getbootstrap.com/javascript/#tooltips
jQuery.fn.setTooltip = (tooltipOptions, {command, commandElement}={}) ->
atom.requireWithGlobals('bootstrap/js/tooltip', {jQuery})
tooltipOptions = {title: tooltipOptions} if _.isString(tooltipOptions)
bindings = if commandElement
atom.keymap.keyBindingsForCommandMatchingElement(command, commandElement)
else
atom.keymap.keyBindingsForCommand(command)
this.tooltip(jQuery.extend(tooltipDefaults, {title: "#{title} #{getKeystroke(bindings)}"}))
tooltipOptions.title = "#{tooltipOptions.title} #{getKeystroke(bindings)}"
this.tooltip(jQuery.extend(tooltipDefaults, tooltipOptions))
jQuery.fn.setTooltip.getKeystroke = getKeystroke
jQuery.fn.setTooltip.replaceModifiers = replaceModifiers