mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Tooltip: Do not attempt to position if tooltip is hidden. Fixed #8644 - Delayed tooltips set to track should reposition when being shown for the first time.
This commit is contained in:
parent
3b2d1e7736
commit
0b3e59f149
@ -103,4 +103,39 @@ test( "tooltipClass", function() {
|
|||||||
ok( $( "#" + element.data( "ui-tooltip-id" ) ).hasClass( "custom" ) );
|
ok( $( "#" + element.data( "ui-tooltip-id" ) ).hasClass( "custom" ) );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "track + show delay", function() {
|
||||||
|
expect( 2 );
|
||||||
|
var event,
|
||||||
|
leftVal = 314,
|
||||||
|
topVal = 159,
|
||||||
|
offsetVal = 26,
|
||||||
|
element = $( "#tooltipped1" ).tooltip({
|
||||||
|
track: true,
|
||||||
|
show: {
|
||||||
|
delay: 1
|
||||||
|
},
|
||||||
|
position: {
|
||||||
|
my: "left+" + offsetVal + " top+" + offsetVal,
|
||||||
|
at: "right bottom"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
event = $.Event( "mouseover" );
|
||||||
|
event.target = $( "#tooltipped1" )[ 0 ];
|
||||||
|
event.originalEvent = { type: "mouseover" };
|
||||||
|
event.pageX = leftVal;
|
||||||
|
event.pageY = topVal;
|
||||||
|
element.trigger( event );
|
||||||
|
|
||||||
|
event = $.Event( "mousemove" );
|
||||||
|
event.target = $( "#tooltipped1" )[ 0 ];
|
||||||
|
event.originalEvent = { type: "mousemove" };
|
||||||
|
event.pageX = leftVal;
|
||||||
|
event.pageY = topVal;
|
||||||
|
element.trigger( event );
|
||||||
|
|
||||||
|
equal( $( ".ui-tooltip" ).css( "left" ), leftVal + offsetVal + "px" );
|
||||||
|
equal( $( ".ui-tooltip" ).css( "top" ), topVal + offsetVal + "px" );
|
||||||
|
});
|
||||||
|
|
||||||
}( jQuery ) );
|
}( jQuery ) );
|
||||||
|
@ -91,7 +91,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$( "#blurs-on-click" ).tooltip().click(function() {
|
$( "#blurs-on-click" ).tooltip({
|
||||||
|
track: true,
|
||||||
|
show: {
|
||||||
|
delay: 500
|
||||||
|
}
|
||||||
|
}).click(function() {
|
||||||
$( "#focus-on-me" ).focus();
|
$( "#focus-on-me" ).focus();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
18
ui/jquery.ui.tooltip.js
vendored
18
ui/jquery.ui.tooltip.js
vendored
@ -206,7 +206,8 @@ $.widget( "ui.tooltip", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_open: function( event, target, content ) {
|
_open: function( event, target, content ) {
|
||||||
var tooltip, positionOption, events;
|
var tooltip, events, delayedShow,
|
||||||
|
positionOption = $.extend( {}, this.options.position );
|
||||||
|
|
||||||
if ( !content ) {
|
if ( !content ) {
|
||||||
return;
|
return;
|
||||||
@ -241,10 +242,12 @@ $.widget( "ui.tooltip", {
|
|||||||
|
|
||||||
function position( event ) {
|
function position( event ) {
|
||||||
positionOption.of = event;
|
positionOption.of = event;
|
||||||
|
if ( tooltip.is( ":hidden" ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
tooltip.position( positionOption );
|
tooltip.position( positionOption );
|
||||||
}
|
}
|
||||||
if ( this.options.track && event && /^mouse/.test( event.originalEvent.type ) ) {
|
if ( this.options.track && event && /^mouse/.test( event.originalEvent.type ) ) {
|
||||||
positionOption = $.extend( {}, this.options.position );
|
|
||||||
this._on( this.document, {
|
this._on( this.document, {
|
||||||
mousemove: position
|
mousemove: position
|
||||||
});
|
});
|
||||||
@ -259,6 +262,17 @@ $.widget( "ui.tooltip", {
|
|||||||
tooltip.hide();
|
tooltip.hide();
|
||||||
|
|
||||||
this._show( tooltip, this.options.show );
|
this._show( tooltip, this.options.show );
|
||||||
|
// Handle tracking tooltips that are shown with a delay (#8644). As soon
|
||||||
|
// as the tooltip is visible, position the tooltip using the most recent
|
||||||
|
// event.
|
||||||
|
if ( this.options.show && this.options.show.delay ) {
|
||||||
|
delayedShow = setInterval(function() {
|
||||||
|
if ( tooltip.is( ":visible" ) ) {
|
||||||
|
position( positionOption.of );
|
||||||
|
clearInterval( delayedShow );
|
||||||
|
}
|
||||||
|
}, $.fx.interval );
|
||||||
|
}
|
||||||
|
|
||||||
this._trigger( "open", event, { tooltip: tooltip } );
|
this._trigger( "open", event, { tooltip: tooltip } );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user