Skip to content

Commit bffc556

Browse files
committed
Tooltip: use the _classes method.
Fixes #7053
1 parent 0a2fa95 commit bffc556

File tree

7 files changed

+126
-14
lines changed

7 files changed

+126
-14
lines changed

tests/unit/tooltip/tooltip.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<title>jQuery UI Tooltip Test Suite</title>
66

77
<script src="../../jquery.js"></script>
8+
<script>
9+
$.uiBackCompat = false;
10+
</script>
811
<link rel="stylesheet" href="../../../external/qunit.css">
912
<script src="../../../external/qunit.js"></script>
1013
<script src="../../jquery.simulate.js"></script>

tests/unit/tooltip/tooltip_common.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
TestHelpers.commonWidgetTests( "tooltip", {
22
defaults: {
3+
classes: {
4+
"ui-tooltip": "ui-corner-all",
5+
"ui-tooltip-content": null
6+
},
37
content: function() {},
48
disabled: false,
59
hide: true,
@@ -10,7 +14,6 @@ TestHelpers.commonWidgetTests( "tooltip", {
1014
collision: "flipfit flip"
1115
},
1216
show: true,
13-
tooltipClass: null,
1417
track: false,
1518

1619
// callbacks
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
TestHelpers.commonWidgetTests( "tooltip", {
2+
defaults: {
3+
classes: {
4+
"ui-tooltip": "ui-corner-all",
5+
"ui-tooltip-content": null
6+
},
7+
content: function() {},
8+
disabled: false,
9+
hide: true,
10+
items: "[title]:not([disabled])",
11+
position: {
12+
my: "left top+15",
13+
at: "left bottom",
14+
collision: "flipfit flip"
15+
},
16+
show: true,
17+
tooltipClass: null,
18+
track: false,
19+
20+
// callbacks
21+
close: null,
22+
create: null,
23+
open: null
24+
}
25+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>jQuery UI Tooltip Test Suite</title>
6+
7+
<script src="../../jquery.js"></script>
8+
<script>
9+
$.uiBackCompat = true;
10+
</script>
11+
<link rel="stylesheet" href="../../../external/qunit.css">
12+
<script src="../../../external/qunit.js"></script>
13+
<script src="../../jquery.simulate.js"></script>
14+
<script src="../testsuite.js"></script>
15+
<script>
16+
TestHelpers.loadResources({
17+
css: [ "core", "tooltip" ],
18+
js: [
19+
"ui/core.js",
20+
"ui/widget.js",
21+
"ui/position.js",
22+
"ui/tooltip.js"
23+
]
24+
});
25+
</script>
26+
27+
<script src="tooltip_common_deprecated.js"></script>
28+
<script src="tooltip_core.js"></script>
29+
<script src="tooltip_events.js"></script>
30+
<script src="tooltip_methods.js"></script>
31+
<script src="tooltip_options.js"></script>
32+
<script src="tooltip_deprecated.js"></script>
33+
34+
<script src="../swarminject.js"></script>
35+
</head>
36+
<body>
37+
38+
<div id="qunit"></div>
39+
<div id="qunit-fixture">
40+
41+
<div>
42+
<a id="tooltipped1" href="#" title="anchortitle">anchor</a>
43+
<input title="inputtitle">
44+
<span id="multiple-describedby" aria-describedby="fixture-span" title="...">aria-describedby</span>
45+
<span id="fixture-span" title="title-text">span</span>
46+
<span id="contains-tooltipped" title="parent"><span id="contained-tooltipped" title="child">baz</span></span>
47+
</div>
48+
49+
<form id="tooltip-form">
50+
<input name="title" title="attroperties">
51+
</form>
52+
53+
</div>
54+
</body>
55+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* dialog_deprecated.js
3+
*/
4+
(function( $ ) {
5+
6+
module( "tooltip: (deprecated) options" );
7+
8+
test( "tooltipClass", function() {
9+
expect( 1 );
10+
var element = $( "#tooltipped1" ).tooltip({
11+
tooltipClass: "custom"
12+
}).tooltip( "open" );
13+
ok( $( "#" + element.data( "ui-tooltip-id" ) ).hasClass( "custom" ) );
14+
});
15+
16+
}( jQuery ) );

tests/unit/tooltip/tooltip_options.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ test( "items", function() {
120120
element.tooltip( "destroy" );
121121
});
122122

123-
test( "tooltipClass", function() {
124-
expect( 1 );
125-
var element = $( "#tooltipped1" ).tooltip({
126-
tooltipClass: "custom"
127-
}).tooltip( "open" );
128-
ok( $( "#" + element.data( "ui-tooltip-id" ) ).hasClass( "custom" ) );
129-
});
130-
131123
test( "track + show delay", function() {
132124
expect( 2 );
133125
var event,

ui/tooltip.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
}
2626
}(function( $ ) {
2727

28-
return $.widget( "ui.tooltip", {
28+
$.widget( "ui.tooltip", {
2929
version: "@VERSION",
3030
options: {
31+
classes: {
32+
"ui-tooltip": "ui-corner-all",
33+
"ui-tooltip-content": null
34+
},
3135
content: function() {
3236
// support: IE<9, Opera in jQuery <1.7
3337
// .text() can't accept undefined, so coerce to a string
@@ -44,7 +48,6 @@ return $.widget( "ui.tooltip", {
4448
collision: "flipfit flip"
4549
},
4650
show: true,
47-
tooltipClass: null,
4851
track: false,
4952

5053
// callbacks
@@ -391,12 +394,11 @@ return $.widget( "ui.tooltip", {
391394
_tooltip: function( element ) {
392395
var tooltip = $( "<div>" )
393396
.attr( "role", "tooltip" )
394-
.addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " +
395-
( this.options.tooltipClass || "" ) ),
397+
.addClass( this._classes( "ui-tooltip" ) + " ui-widget ui-widget-content " ),
396398
id = tooltip.uniqueId().attr( "id" );
397399

398400
$( "<div>" )
399-
.addClass( "ui-tooltip-content" )
401+
.addClass( this._classes( "ui-tooltip-content" ) )
400402
.appendTo( tooltip );
401403

402404
tooltip.appendTo( this.document[0].body );
@@ -441,4 +443,20 @@ return $.widget( "ui.tooltip", {
441443
}
442444
});
443445

446+
// DEPRECATED
447+
if ($.uiBackCompat !== false) {
448+
// tooltipClass option
449+
$.widget( "ui.tooltip", $.ui.tooltip, {
450+
options: {
451+
tooltipClass: null
452+
},
453+
_tooltip: function() {
454+
var tooltip = this._superApply( arguments );
455+
return tooltip.addClass( this.options.tooltipClass || "" );
456+
}
457+
});
458+
}
459+
460+
return $.ui.tooltip;
461+
444462
}));

0 commit comments

Comments
 (0)