From 34201847f6b8e0ba41356f0b383ec99696e2946f Mon Sep 17 00:00:00 2001 From: kradmiy Date: Wed, 16 Feb 2011 18:06:03 +0200 Subject: [PATCH 1/2] Tooltip show / hide animation effects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://wiki.jqueryui.com/w/page/12138112/Tooltip http://bugs.jqueryui.com/ticket/3772 Fixed: #3772 - work through places where animations could be used this time solution based on both my previous pull requests: - added new method to tooltip object "_animate", that is based on kbwood animation solution posted http://bugs.jqueryui.com/ticket/3772#comment:6 - default animations fadeIn / fadeOut implemented, thank's Jörn) - And some from Jörn: "Somewhat related: With this API implemented, the close callback could run once the animation is completed, instead of as soon as the animation starts. Though that could get into trouble when the closing animation is cancelled (hover before animation finished)." So may be fire trigger close event just before animation fired? --- ui/jquery.ui.tooltip.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index 50e1b4437c0..eb4cf6584b5 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -86,7 +86,27 @@ $.widget("ui.tooltip", { self._show(event, target, content); } }, - + + /** + * used function from this comment http://bugs.jqueryui.com/ticket/3772#comment:6 + */ + _animate: function (effect, showing) { + // Convert to array + effect = ($.isArray(effect) ? effect : (typeof effect === 'string' ? [effect] : + [effect.fx, effect.options, effect.speed, effect.callback])); + // Check for options + (effect[1] && typeof effect[1] !== 'object' ? effect.splice(1, 0, null) : effect); + // Check for callback + ($.isFunction(effect[2]) ? effect.splice(2, 0, null) : effect); + // Special case for 'show' + effect = (effect[0] && effect[0] !== 'show' ? effect : effect.slice(2)); + (effect[0] === 'fade' ? + // Special case for 'fade' + this.tooltip[showing ? 'fadeIn' : 'fadeOut'].apply(this.tooltip, effect.slice(2)) : + // Apply effect + this.tooltip[showing ? 'show' : 'hide'].apply(this.tooltip, effect)); + }, + _show: function(event, target, content) { if (!content) return; @@ -107,7 +127,11 @@ $.widget("ui.tooltip", { this.tooltip.attr("aria-hidden", "false"); target.attr("aria-describedby", this.tooltip.attr("id")); - this.tooltip.stop(false, true).fadeIn(); + //move animation code apart, so will be no need to repeat stop in "if" closures + this.tooltip.stop(false, true); + + //if show was not provided -> trigger default fadeIn animation + this._animate( !this.options.show ? 'fade' : this.options.show, 1 ); this._trigger( "open", event ); }, @@ -126,9 +150,14 @@ $.widget("ui.tooltip", { current.removeAttr("aria-describedby"); this.tooltip.attr("aria-hidden", "true"); - this.tooltip.stop(false, true).fadeOut(); + //move animation code apart, so will be no need to repeat stop in "if" closures + this.tooltip.stop(false, true); + //trigger close event just before animation fired? this._trigger( "close", event ); + + //show was not provided -> trigger default fadeIn animation + this._animate( !this.options.hide ? 'fade' : this.options.hide, 0 ); } }); From 29d0592c2e666d3564821ff3a505e59194fe2ccf Mon Sep 17 00:00:00 2001 From: kradmiy Date: Wed, 16 Feb 2011 08:42:17 -0800 Subject: [PATCH 2/2] Edited ui/jquery.ui.tooltip.js via GitHub --- ui/jquery.ui.tooltip.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index eb4cf6584b5..d870a8d8f80 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -127,10 +127,8 @@ $.widget("ui.tooltip", { this.tooltip.attr("aria-hidden", "false"); target.attr("aria-describedby", this.tooltip.attr("id")); - //move animation code apart, so will be no need to repeat stop in "if" closures this.tooltip.stop(false, true); - - //if show was not provided -> trigger default fadeIn animation + //animation stuff - if show was not provided -> trigger default fadeIn animation this._animate( !this.options.show ? 'fade' : this.options.show, 1 ); this._trigger( "open", event ); @@ -149,11 +147,9 @@ $.widget("ui.tooltip", { current.removeAttr("aria-describedby"); this.tooltip.attr("aria-hidden", "true"); - - //move animation code apart, so will be no need to repeat stop in "if" closures + this.tooltip.stop(false, true); - - //trigger close event just before animation fired? + //animation stuff - trigger close event just before animation fired? this._trigger( "close", event ); //show was not provided -> trigger default fadeIn animation