Skip to content

Commit d4f6f17

Browse files
committed
Tooltip: Changed custom animation demo and changed the logic for showing tooltips so custom position options can perform animations.
1 parent c34a814 commit d4f6f17

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

demos/tooltip/custom-animation.html

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,46 @@
99
<script src="../../ui/jquery.ui.widget.js"></script>
1010
<script src="../../ui/jquery.ui.position.js"></script>
1111
<script src="../../ui/jquery.ui.tooltip.js"></script>
12+
<script src="../../ui/jquery.effects.core.js"></script>
13+
<script src="../../ui/jquery.effects.explode.js"></script>
1214
<link rel="stylesheet" href="../demos.css">
13-
<style>
14-
label {
15-
display: inline-block;
16-
width: 5em;
17-
}
18-
</style>
1915
<script>
2016
$(function() {
21-
$( ".demo" ).tooltip({
17+
$( "#show-option" ).tooltip({
2218
show: {
2319
effect: "slideDown",
2420
delay: 250
25-
},
21+
}
22+
});
23+
$( "#hide-option" ).tooltip({
2624
hide: {
27-
effect: "hide",
25+
effect: "explode",
2826
delay: 250
2927
}
3028
});
29+
$( "#position-option" ).tooltip({
30+
position: {
31+
my: "left top",
32+
at: "left bottom+10",
33+
using: function( pos ) {
34+
$( this ).css({
35+
left: pos.left,
36+
top: pos.top - 10
37+
}).animate({ top: pos.top }, "fast" );
38+
}
39+
}
40+
});
3141
});
3242
</script>
3343
</head>
3444
<body>
3545

3646
<div class="demo">
3747

38-
<p><a href="#" title="That's what this widget is">Tooltips</a> can be attached to any element. When you hover
39-
the element with your mouse, the title attribute is displayed in a little box next to the element, just like a native tooltip.</p>
40-
<p>But as it's not a native tooltip, it can be styled. Any themes built with
41-
<a href="http://themeroller.com" title="ThemeRoller: jQuery UI's theme builder application">ThemeRoller</a>
42-
will also style tooltips accordingly.</p>
43-
<p>Tooltips are also useful for form elements, to show some additional information in the context of each field.</p>
44-
<p><label for="age">Your age:</label><input id="age" title="We ask for your age only for statistical purposes."></p>
45-
<p>Hover the field to see the tooltip.</p>
48+
<p>There are various ways to customize the animation of a tooltip.</p>
49+
<p>You can use the <a id="show-option" href="http://jqueryui.com/demos/tooltip/#option-show" title="show effect">show</a> and
50+
<a id="hide-option" href="http://jqueryui.com/demos/tooltip/#option-hide" title="hide effect">hide</a> options.</p>
51+
<p>You can also use the <a id="position-option" href="http://jqueryui.com/demos/tooltip/#option-position" title="position option">position option</a>.</p>
4652

4753
</div><!-- End demo -->
4854

ui/jquery.ui.tooltip.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ $.widget("ui.tooltip", {
9090
target.attr( "aria-describedby", tooltip.attr( "id" ) );
9191
}
9292
tooltip.find( ".ui-tooltip-content" ).html( content );
93-
tooltip.position( $.extend({
94-
of: target
95-
}, this.options.position ) ).hide();
93+
tooltip
94+
.stop( true )
95+
.position( $.extend({
96+
of: target,
97+
using: function( pos ) {
98+
// we only want to hide if there's no custom using defined
99+
$( this ).css( pos ).hide();
100+
}
101+
}, this.options.position ) );
96102

97-
tooltip.stop( true );
98103
this._show( tooltip, this.options.show );
99104

100105
this._trigger( "open", event );

ui/jquery.ui.widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
379379
var hasOptions = !$.isEmptyObject( options ),
380380
effectName = options.effect || defaultEffect;
381381
options.complete = callback;
382-
if (options.delay) {
382+
if ( options.delay ) {
383383
element.delay( options.delay );
384384
}
385385
if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {

0 commit comments

Comments
 (0)