Tooltip: Add track option

This commit is contained in:
Jörn Zaefferer 2012-06-14 01:02:11 +02:00 committed by Scott González
parent ff39bed57a
commit 5c2cf39dff
3 changed files with 26 additions and 26 deletions

View File

@ -19,27 +19,7 @@
<script> <script>
$(function() { $(function() {
$( ".demo" ).tooltip({ $( ".demo" ).tooltip({
position: { track: true
my: "left+25 center",
at: "center"
},
open: function( event, ui ) {
if ( !( /^mouse/.test( event.originalEvent.type ) ) ) {
return;
}
var positionOption = $.extend( {}, $( this ).tooltip( "option", "position" ) );
function position( event ) {
positionOption.of = event;
ui.tooltip.position( positionOption );
}
$( document ).bind( "mousemove.tooltip-position", position );
// trigger once to override element-relative positioning
position( event );
},
close: function() {
$( document ).unbind( "mousemove.tooltip-position" );
}
}); });
}); });
</script> </script>

View File

@ -11,6 +11,7 @@ TestHelpers.commonWidgetTests( "tooltip", {
}, },
show: true, show: true,
tooltipClass: null, tooltipClass: null,
track: false,
// callbacks // callbacks
close: null, close: null,

View File

@ -54,6 +54,7 @@ $.widget( "ui.tooltip", {
}, },
show: true, show: true,
tooltipClass: null, tooltipClass: null,
track: false,
// callbacks // callbacks
close: null, close: null,
@ -145,13 +146,14 @@ $.widget( "ui.tooltip", {
}, },
_open: function( event, target, content ) { _open: function( event, target, content ) {
var tooltip, positionOption;
if ( !content ) { if ( !content ) {
return; return;
} }
// Content can be updated multiple times. If the tooltip already // Content can be updated multiple times. If the tooltip already
// exists, then just update the content and bail. // exists, then just update the content and bail.
var tooltip = this._find( target ); tooltip = this._find( target );
if ( tooltip.length ) { if ( tooltip.length ) {
tooltip.find( ".ui-tooltip-content" ).html( content ); tooltip.find( ".ui-tooltip-content" ).html( content );
return; return;
@ -175,11 +177,25 @@ $.widget( "ui.tooltip", {
tooltip = this._tooltip( target ); tooltip = this._tooltip( target );
addDescribedBy( target, tooltip.attr( "id" ) ); addDescribedBy( target, tooltip.attr( "id" ) );
tooltip.find( ".ui-tooltip-content" ).html( content ); tooltip.find( ".ui-tooltip-content" ).html( content );
tooltip
.position( $.extend({ function position( event ) {
positionOption.of = event;
tooltip.position( positionOption );
}
if ( this.options.track && /^mouse/.test( event.originalEvent.type ) ) {
positionOption = $.extend( {}, this.options.position );
this._on( this.document, {
mousemove: position
});
// trigger once to override element-relative positioning
position( event );
} else {
tooltip.position( $.extend({
of: target of: target
}, this.options.position ) ) }, this.options.position ) );
.hide(); }
tooltip.hide();
this._show( tooltip, this.options.show ); this._show( tooltip, this.options.show );
@ -235,6 +251,9 @@ $.widget( "ui.tooltip", {
target.removeData( "tooltip-open" ); target.removeData( "tooltip-open" );
this._off( target, "mouseleave focusout keyup" ); this._off( target, "mouseleave focusout keyup" );
// TODO use _off
this.document.unbind( "mousemove.tooltip" );
this.closing = true; this.closing = true;
this._trigger( "close", event, { tooltip: tooltip } ); this._trigger( "close", event, { tooltip: tooltip } );
this.closing = false; this.closing = false;