Skip to content

Commit e609beb

Browse files
committed
Custom tooltip animations based on widget-animations branch.
1 parent 00559b3 commit e609beb

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

demos/tooltip/custom-animation.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
<link type="text/css" href="../demos.css" rel="stylesheet" />
1212
<script type="text/javascript">
1313
$(function() {
14-
// TODO overhaul this with custom animation API
1514
$(".demo").tooltip({
16-
open: function() {
17-
$(".ui-tooltip").stop(false, true).hide().slideDown();
15+
show: {
16+
effect: "slideDown"
1817
},
19-
close: function() {
20-
$(".ui-tooltip").stop(false, false).show().slideUp(function() {
21-
$(this).remove();
22-
});
18+
hide: {
19+
effect: "slideUp"
2320
}
2421
});
2522
});

ui/jquery.ui.tooltip.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ $.widget("ui.tooltip", {
9191
}, this.options.position ) ).hide();
9292

9393

94-
tooltip.fadeIn();
94+
this._show( tooltip, this.options.show );
9595

9696
this._trigger( "open", event );
9797

@@ -111,7 +111,7 @@ $.widget("ui.tooltip", {
111111
var tooltip = this._find( target );
112112
target.removeAttr( "aria-describedby" );
113113

114-
tooltip.fadeOut( function() {
114+
this._hide( tooltip, this.options.hide, function() {
115115
$( this ).remove();
116116
});
117117

ui/jquery.ui.widget.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@ $.Widget.prototype = {
353353
}
354354
};
355355

356+
$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
357+
$.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
358+
options = options || {};
359+
var hasOptions = !$.isEmptyObject( options ),
360+
effectName = options.effect || defaultEffect;
361+
options.complete = callback;
362+
363+
if ( hasOptions && $.effects && $.effects[ effectName ] ) {
364+
element[ method ]( options );
365+
} else if ( element[ effectName ] ) {
366+
element[ effectName ]( options.duration, options.easing, callback );
367+
} else {
368+
element[ method ]();
369+
if ( callback ) {
370+
callback.call( element[ 0 ] );
371+
}
372+
}
373+
};
374+
});
375+
356376
// DEPRECATED
357377
if ( $.uiBackCompat !== false ) {
358378
$.Widget.prototype._getCreateOptions = function() {

0 commit comments

Comments
 (0)