Remove space-pen-extensions

Move the last remaining feature into the tooltip manager.
This commit is contained in:
Nathan Sobo
2015-09-04 11:44:22 -06:00
parent 239da56130
commit 69664fc77b
3 changed files with 8 additions and 68 deletions

View File

@@ -1,6 +1,6 @@
path = require 'path'
_ = require 'underscore-plus'
{View, $, $$} = require '../src/space-pen-extensions'
{View, $, $$} = require 'space-pen'
grim = require 'grim'
marked = require 'marked'
@@ -200,7 +200,6 @@ class AtomReporter extends View
specComplete: (spec) ->
specSummaryElement = $("#spec-summary-#{spec.id}")
specSummaryElement.removeClass('pending')
specSummaryElement.setTooltip(title: spec.getFullName(), container: '.spec-reporter')
results = spec.results()
if results.skipped

View File

@@ -1,64 +0,0 @@
_ = require 'underscore-plus'
SpacePen = require 'space-pen'
jQuery = SpacePen.jQuery
tooltipDefaults =
delay:
show: 1000
hide: 100
container: 'body'
html: true
placement: 'auto top'
viewportPadding: 2
humanizeKeystrokes = (keystroke) ->
keystrokes = keystroke.split(' ')
keystrokes = (_.humanizeKeystroke(stroke) for stroke in keystrokes)
keystrokes.join(' ')
getKeystroke = (bindings) ->
if bindings?.length
"<span class=\"keystroke\">#{humanizeKeystrokes(bindings[0].keystrokes)}</span>"
else
''
requireBootstrapTooltip = _.once ->
atom.requireWithGlobals('bootstrap/js/tooltip', {jQuery})
# options from http://getbootstrap.com/javascript/#tooltips
jQuery.fn.setTooltip = (tooltipOptions, {command, commandElement}={}) ->
requireBootstrapTooltip()
tooltipOptions = {title: tooltipOptions} if _.isString(tooltipOptions)
if commandElement
bindings = atom.keymaps.findKeyBindings(command: command, target: commandElement[0])
else if command
bindings = atom.keymaps.findKeyBindings(command: command)
tooltipOptions.title = "#{tooltipOptions.title} #{getKeystroke(bindings)}"
@tooltip(jQuery.extend({}, tooltipDefaults, tooltipOptions))
jQuery.fn.hideTooltip = ->
tip = @data('bs.tooltip')
if tip
tip.leave(currentTarget: this)
tip.hide()
jQuery.fn.destroyTooltip = ->
@hideTooltip()
requireBootstrapTooltip()
@tooltip('destroy')
# Hide tooltips when window is resized
jQuery(document.body).on 'show.bs.tooltip', ({target}) ->
windowHandler = -> jQuery(target).hideTooltip()
jQuery(window).one('resize', windowHandler)
jQuery(target).one 'hide.bs.tooltip', ->
jQuery(window).off('resize', windowHandler)
jQuery.fn.setTooltip.getKeystroke = getKeystroke
jQuery.fn.setTooltip.humanizeKeystrokes = humanizeKeystrokes
module.exports = SpacePen

View File

@@ -1,6 +1,6 @@
_ = require 'underscore-plus'
{Disposable} = require 'event-kit'
{$} = require './space-pen-extensions'
{$} = require 'space-pen'
# Essential: Associates tooltips with HTML elements or selectors.
#
@@ -86,13 +86,18 @@ class TooltipManager
$target = $(target)
$target.tooltip(_.defaults(options, @defaults))
new Disposable ->
removeTooltipOnWindowResize = -> disposable.dispose()
window.addEventListener('resize', removeTooltipOnWindowResize)
disposable = new Disposable ->
window.removeEventListener('resize', removeTooltipOnWindowResize)
tooltip = $target.data('bs.tooltip')
if tooltip?
tooltip.leave(currentTarget: target)
tooltip.hide()
$target.tooltip('destroy')
disposable
humanizeKeystrokes = (keystroke) ->
keystrokes = keystroke.split(' ')
keystrokes = (_.humanizeKeystroke(stroke) for stroke in keystrokes)