From 108b00dae02d24fa8de3461f35340155998cd0ed Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 7 Sep 2015 19:24:23 -0600 Subject: [PATCH] Support jQuery wrappers being passed to tooltip manager Not my favorite feature, but required for backward-compatibility. --- spec/tooltip-manager-spec.coffee | 18 ++++++++++++++++++ src/tooltip-manager.coffee | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/tooltip-manager-spec.coffee b/spec/tooltip-manager-spec.coffee index 7badc3a8e..ec30ef2e3 100644 --- a/spec/tooltip-manager-spec.coffee +++ b/spec/tooltip-manager-spec.coffee @@ -28,6 +28,24 @@ describe "TooltipManager", -> hover element, -> expect(document.body.querySelector(".tooltip")).toHaveText("Title") + it "allows jQuery elements to be passed as the target", -> + element2 = document.createElement('div') + jasmine.attachToDOM(element2) + + fakeJqueryWrapper = [element, element2] + fakeJqueryWrapper.jquery = 'any-version' + disposable = manager.add fakeJqueryWrapper, title: "Title" + + hover element, -> expect(document.body.querySelector(".tooltip")).toHaveText("Title") + expect(document.body.querySelector(".tooltip")).toBeNull() + hover element2, -> expect(document.body.querySelector(".tooltip")).toHaveText("Title") + expect(document.body.querySelector(".tooltip")).toBeNull() + + disposable.dispose() + + hover element, -> expect(document.body.querySelector(".tooltip")).toBeNull() + hover element2, -> expect(document.body.querySelector(".tooltip")).toBeNull() + describe "when a selector is specified", -> it "creates a tooltip when hovering over a descendant of the target that matches the selector", -> child = document.createElement('div') diff --git a/src/tooltip-manager.coffee b/src/tooltip-manager.coffee index f91ea76dd..21b8b07c6 100644 --- a/src/tooltip-manager.coffee +++ b/src/tooltip-manager.coffee @@ -1,5 +1,5 @@ _ = require 'underscore-plus' -{Disposable} = require 'event-kit' +{Disposable, CompositeDisposable} = require 'event-kit' Tooltip = null # Essential: Associates tooltips with HTML elements or selectors. @@ -71,6 +71,11 @@ class TooltipManager # Returns a {Disposable} on which `.dispose()` can be called to remove the # tooltip. add: (target, options) -> + if target.jquery + disposable = new CompositeDisposable + disposable.add @add(element, options) for element in target + return disposable + Tooltip ?= require './tooltip' {keyBindingCommand, keyBindingTarget} = options