diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2012-06-14 01:02:11 +0200 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-06-14 12:38:13 -0400 |
commit | 5c2cf39dff34b4598b214b1a2a1f3b48d15f0366 (patch) | |
tree | 31fb4184f5b0488e860f1d146abd5bbee6284e97 | |
parent | ff39bed57a05ca060033187b8aecebafab357f78 (diff) | |
download | jquery-ui-5c2cf39dff34b4598b214b1a2a1f3b48d15f0366.tar.gz jquery-ui-5c2cf39dff34b4598b214b1a2a1f3b48d15f0366.zip |
Tooltip: Add track option
-rw-r--r-- | demos/tooltip/tracking.html | 22 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_common.js | 1 | ||||
-rw-r--r-- | ui/jquery.ui.tooltip.js | 29 |
3 files changed, 26 insertions, 26 deletions
diff --git a/demos/tooltip/tracking.html b/demos/tooltip/tracking.html index 033bc9766..ab0237da6 100644 --- a/demos/tooltip/tracking.html +++ b/demos/tooltip/tracking.html @@ -19,27 +19,7 @@ <script> $(function() { $( ".demo" ).tooltip({ - position: { - 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" ); - } + track: true }); }); </script> diff --git a/tests/unit/tooltip/tooltip_common.js b/tests/unit/tooltip/tooltip_common.js index d12ee9519..6d503aecd 100644 --- a/tests/unit/tooltip/tooltip_common.js +++ b/tests/unit/tooltip/tooltip_common.js @@ -11,6 +11,7 @@ TestHelpers.commonWidgetTests( "tooltip", { }, show: true, tooltipClass: null, + track: false, // callbacks close: null, diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index c4bdbb0d7..2c80f328c 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -54,6 +54,7 @@ $.widget( "ui.tooltip", { }, show: true, tooltipClass: null, + track: false, // callbacks close: null, @@ -145,13 +146,14 @@ $.widget( "ui.tooltip", { }, _open: function( event, target, content ) { + var tooltip, positionOption; if ( !content ) { return; } // Content can be updated multiple times. If the tooltip already // exists, then just update the content and bail. - var tooltip = this._find( target ); + tooltip = this._find( target ); if ( tooltip.length ) { tooltip.find( ".ui-tooltip-content" ).html( content ); return; @@ -175,11 +177,25 @@ $.widget( "ui.tooltip", { tooltip = this._tooltip( target ); addDescribedBy( target, tooltip.attr( "id" ) ); 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 - }, this.options.position ) ) - .hide(); + }, this.options.position ) ); + } + + tooltip.hide(); this._show( tooltip, this.options.show ); @@ -235,6 +251,9 @@ $.widget( "ui.tooltip", { target.removeData( "tooltip-open" ); this._off( target, "mouseleave focusout keyup" ); + // TODO use _off + this.document.unbind( "mousemove.tooltip" ); + this.closing = true; this._trigger( "close", event, { tooltip: tooltip } ); this.closing = false; |