Skip to content

Commit 54ff7ad

Browse files
committed
when another tooltip trigger is clicked, only close the previous tooltip if it does not contain the trigger. slc ref #9801
1 parent ac593cb commit 54ff7ad

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"AnythingSlider": "1.8.17",
1717
"chosen": "0.9.11",
1818
"jquery-form": "3.46.0",
19-
"fullcalendar": "http://arshaw.com/fullcalendar/downloads/fullcalendar-2.0.0.zip",
19+
"fullcalendar": "https://github.com/arshaw/fullcalendar/releases/download/v2.0.0/fullcalendar-2.0.0.zip",
2020
"jquery-placeholder": "2.0.7",
2121
"prefixfree": "",
2222
"select2": "3.4.3",

src/pat/tooltip.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,15 @@ define([
213213
var $trigger = event.data,
214214
$container = tooltip.getContainer($trigger),
215215
namespace = $container.attr("id");
216-
$container.css("visibility", "hidden");
217-
$container.parents().add(window).off("." + namespace);
218-
tooltip.removeHideEvents($trigger);
219-
tooltip.setupShowEvents($trigger);
220-
$trigger.removeClass("active").addClass("inactive");
221-
$trigger.trigger("pat-update", {pattern: "tooltip", hidden: true});
216+
// when another tooltip trigger is clicked, only close the previous tooltip if it does not contain the trigger
217+
if (event.type !== "pat-tooltip-click" || $container.has(event.target).length <= 0) {
218+
$container.css("visibility", "hidden");
219+
$container.parents().add(window).off("." + namespace);
220+
tooltip.removeHideEvents($trigger);
221+
tooltip.setupShowEvents($trigger);
222+
$trigger.removeClass("active").addClass("inactive");
223+
$trigger.trigger("pat-update", {pattern: "tooltip", hidden: true});
224+
}
222225
},
223226

224227
onDestroy: function(event) {

tests/specs/pat/tooltip.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,43 @@ define(["pat-tooltip", "pat-inject"], function(pattern, inject) {
252252
});
253253
});
254254
});
255+
256+
describe("A tooltip that opens on click and contains another tooltip trigger", function () {
257+
beforeEach(function() {
258+
utils.createTooltip({
259+
data: "trigger: click; source: content",
260+
href: "#tooltip-content"
261+
});
262+
$("<div />", {
263+
"id": "tooltip-content"
264+
}).appendTo($("div#lab"));
265+
$("<a/>", {
266+
"id": "nested-tooltip",
267+
"href": "#nested-tooltip-content",
268+
"title": "nested tooltip title attribute",
269+
"data-pat-tooltip": "trigger: click; source: content",
270+
"class": "pat-tooltip"
271+
}).appendTo($("div#tooltip-content"));
272+
});
273+
afterEach(function() {
274+
utils.removeTooltip();
275+
});
276+
it("will not close if the contained trigger is clicked", function () {
277+
runs(function () {
278+
spyOn(pattern, "show").andCallThrough();
279+
var $el = $("a#tooltip");
280+
pattern.init($el);
281+
pattern.init($("a#nested-tooltip"));
282+
$el.trigger(utils.click);
283+
expect(pattern.show).toHaveBeenCalled();
284+
});
285+
waits(100); // hide events get registered 50 ms after show
286+
runs(function () {
287+
$(".tooltip-container a#nested-tooltip").trigger(utils.click);
288+
expect($(".tooltip-container a#nested-tooltip").css("visibility")).toBe("visible");
289+
});
290+
});
291+
});
255292
});
256293
});
257294
// jshint indent: 4, browser: true, jquery: true, quotmark: double

0 commit comments

Comments
 (0)