Skip to content

Commit 96f2aa4

Browse files
committed
Tooltip: Check if event exists before checking properties in open(). Fixes #8626 - Programatically opening a tooltip with out giving an event results in a javascript error.
1 parent f417a92 commit 96f2aa4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/unit/tooltip/tooltip_methods.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ test( "open/close", function() {
2929
$.fx.off = false;
3030
});
3131

32+
// #8626 - Calling open() without an event
33+
test( "open/close with tracking", function() {
34+
expect( 3 );
35+
$.fx.off = true;
36+
var tooltip,
37+
element = $( "#tooltipped1" ).tooltip({ track: true });
38+
equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
39+
40+
element.tooltip( "open" );
41+
tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
42+
ok( tooltip.is( ":visible" ) );
43+
44+
element.tooltip( "close" );
45+
ok( tooltip.is( ":hidden" ) );
46+
$.fx.off = false;
47+
});
48+
3249
test( "enable/disable", function() {
3350
expect( 7 );
3451
$.fx.off = true;

ui/jquery.ui.tooltip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ $.widget( "ui.tooltip", {
216216
positionOption.of = event;
217217
tooltip.position( positionOption );
218218
}
219-
if ( this.options.track && /^mouse/.test( event.originalEvent.type ) ) {
219+
if ( this.options.track && event && /^mouse/.test( event.originalEvent.type ) ) {
220220
positionOption = $.extend( {}, this.options.position );
221221
this._on( this.document, {
222222
mousemove: position

0 commit comments

Comments
 (0)