]> source.dussan.org Git - jquery-ui.git/commitdiff
Tooltip: Accept HTMLElement and jQuery objects for the content option
authorDaniel Owens <daniel@matchstickmixup.com>
Wed, 8 May 2013 17:15:44 +0000 (12:15 -0500)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Mon, 12 Jan 2015 17:37:57 +0000 (18:37 +0100)
Fixes #9278
Closes #983
Closes #1421

tests/unit/tooltip/tooltip_options.js
ui/tooltip.js

index 17f0a423775b3a31631e3425aca6a5242fc33117..2d49533f24f6366fc06810c49eac01fbe378b4aa 100644 (file)
@@ -100,6 +100,30 @@ test( "content: string", function() {
        }).tooltip( "open" );
 });
 
+test( "content: element", function() {
+       expect( 1 );
+       var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>",
+               element = $( content )[ 0 ];
+       $( "#tooltipped1" ).tooltip({
+               content: element,
+               open: function( event, ui ) {
+                       equal( ui.tooltip.children().html().toLowerCase(), content );
+               }
+       }).tooltip( "open" );
+});
+
+test( "content: jQuery", function() {
+       expect( 1 );
+       var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>",
+               element = $( content );
+       $( "#tooltipped1" ).tooltip({
+               content: element,
+               open: function( event, ui ) {
+                       equal( ui.tooltip.children().html().toLowerCase(), content );
+               }
+       }).tooltip( "open" );
+});
+
 test( "items", function() {
        expect( 2 );
        var event,
index 7ea1d13ee8067a962a972739dbc5da5f0d4f7a85..85c64f2a09141d691619c6fec3f22c06057fb228 100644 (file)
@@ -208,7 +208,8 @@ return $.widget( "ui.tooltip", {
                        that = this,
                        eventType = event ? event.type : null;
 
-               if ( typeof contentOption === "string" ) {
+               if ( typeof contentOption === "string" || contentOption.nodeType ||
+                               contentOption.jquery ) {
                        return this._open( event, target, contentOption );
                }
 
@@ -276,13 +277,9 @@ return $.widget( "ui.tooltip", {
                // JAWS announces deletions even when aria-relevant="additions"
                // Voiceover will sometimes re-read the entire log region's contents from the beginning
                this.liveRegion.children().hide();
-               if ( content.clone ) {
-                       a11yContent = content.clone();
-                       a11yContent.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" );
-               } else {
-                       a11yContent = content;
-               }
-               $( "<div>" ).html( a11yContent ).appendTo( this.liveRegion );
+               a11yContent = $( "<div>" ).html( tooltip.find( ".ui-tooltip-content" ).html() );
+               a11yContent.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" );
+               a11yContent.appendTo( this.liveRegion );
 
                function position( event ) {
                        positionOption.of = event;