Skip to content

Commit 42099e4

Browse files
Daniel Owensjzaefferer
Daniel Owens
authored andcommitted
Tooltip: Accept HTMLElement and jQuery objects for the content option
Fixes #9278 Closes #983 Closes #1421
1 parent ae1d6d5 commit 42099e4

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

tests/unit/tooltip/tooltip_options.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ test( "content: string", function() {
100100
}).tooltip( "open" );
101101
});
102102

103+
test( "content: element", function() {
104+
expect( 1 );
105+
var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>",
106+
element = $( content )[ 0 ];
107+
$( "#tooltipped1" ).tooltip({
108+
content: element,
109+
open: function( event, ui ) {
110+
equal( ui.tooltip.children().html().toLowerCase(), content );
111+
}
112+
}).tooltip( "open" );
113+
});
114+
115+
test( "content: jQuery", function() {
116+
expect( 1 );
117+
var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>",
118+
element = $( content );
119+
$( "#tooltipped1" ).tooltip({
120+
content: element,
121+
open: function( event, ui ) {
122+
equal( ui.tooltip.children().html().toLowerCase(), content );
123+
}
124+
}).tooltip( "open" );
125+
});
126+
103127
test( "items", function() {
104128
expect( 2 );
105129
var event,

ui/tooltip.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ return $.widget( "ui.tooltip", {
208208
that = this,
209209
eventType = event ? event.type : null;
210210

211-
if ( typeof contentOption === "string" ) {
211+
if ( typeof contentOption === "string" || contentOption.nodeType ||
212+
contentOption.jquery ) {
212213
return this._open( event, target, contentOption );
213214
}
214215

@@ -276,13 +277,9 @@ return $.widget( "ui.tooltip", {
276277
// JAWS announces deletions even when aria-relevant="additions"
277278
// Voiceover will sometimes re-read the entire log region's contents from the beginning
278279
this.liveRegion.children().hide();
279-
if ( content.clone ) {
280-
a11yContent = content.clone();
281-
a11yContent.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" );
282-
} else {
283-
a11yContent = content;
284-
}
285-
$( "<div>" ).html( a11yContent ).appendTo( this.liveRegion );
280+
a11yContent = $( "<div>" ).html( tooltip.find( ".ui-tooltip-content" ).html() );
281+
a11yContent.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" );
282+
a11yContent.appendTo( this.liveRegion );
286283

287284
function position( event ) {
288285
positionOption.of = event;

0 commit comments

Comments
 (0)