From 5aa3c9d01ee771fb71f2d807307aac399dba3f44 Mon Sep 17 00:00:00 2001 From: Daniel Owens Date: Wed, 8 May 2013 12:15:44 -0500 Subject: [PATCH 1/2] Added checks to the tooltip content option for allowing HTMLElement and jQuery objects to be set as content. Added tests for these scenarios. --- .gitignore | 1 + tests/unit/tooltip/tooltip_options.js | 25 +++++++++++++++++++++++++ ui/jquery.ui.tooltip.js | 6 +++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 23d9dd00058..918e206168a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ docs *.patch .DS_Store .settings +*.sw? diff --git a/tests/unit/tooltip/tooltip_options.js b/tests/unit/tooltip/tooltip_options.js index 01ac2504088..ea709de0e7f 100644 --- a/tests/unit/tooltip/tooltip_options.js +++ b/tests/unit/tooltip/tooltip_options.js @@ -95,7 +95,32 @@ test( "content: string", function() { equal( ui.tooltip.text(), "just a string" ); } }).tooltip( "open" ); +} + +test( "content: element", function() { + expect( 1 ); + var html = $( "

This is a test of the emergency broadcast system.

" )[0]; + $( "#tooltipped1" ).tooltip({ + content: html, + open: function( event, ui ) { + equal( ui.tooltip.html(), html ); + } + }).tooltip( "open" ); +}); +); + +test( "content: jQuery", function() { + expect( 1 ); + var html = $( "

This is a test of the emergency broadcast system.

" ); + $( "#tooltipped1" ).tooltip({ + content: html, + open: function( event, ui ) { + equal( ui.tooltip.html(), html ); + } + }).tooltip( "open" ); }); +); + test( "items", function() { expect( 2 ); diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index 5df93a00245..4e88a3e12ac 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -180,10 +180,14 @@ $.widget( "ui.tooltip", { _updateContent: function( target, event ) { var content, contentOption = this.options.content, + contentOptionType = (typeof contentOption), that = this, eventType = event ? event.type : null; - if ( typeof contentOption === "string" ) { + if ( contentOptionType === "string" || + ( contentOptionType === "object" && + ( contentOption instanceof HTMLElement || contentOption instanceof jQuery ) ) + ) { return this._open( event, target, contentOption ); } From 93388dde37b1fb859fa2a4317ad18fa3d780337b Mon Sep 17 00:00:00 2001 From: Daniel Owens Date: Wed, 8 May 2013 18:07:01 -0500 Subject: [PATCH 2/2] Simplified conditions checking for elements to insert into tooltip. Fixed the tests. --- tests/unit/tooltip/tooltip_options.js | 21 +++++++++++---------- ui/jquery.ui.tooltip.js | 6 +----- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/unit/tooltip/tooltip_options.js b/tests/unit/tooltip/tooltip_options.js index ea709de0e7f..0b0043bfaad 100644 --- a/tests/unit/tooltip/tooltip_options.js +++ b/tests/unit/tooltip/tooltip_options.js @@ -95,32 +95,33 @@ test( "content: string", function() { equal( ui.tooltip.text(), "just a string" ); } }).tooltip( "open" ); -} +}); test( "content: element", function() { expect( 1 ); - var html = $( "

This is a test of the emergency broadcast system.

" )[0]; + var content = "

This is a test of the emergency broadcast system.

" + var element = $( content )[ 0 ]; $( "#tooltipped1" ).tooltip({ - content: html, + content: element, open: function( event, ui ) { - equal( ui.tooltip.html(), html ); + // Getting just the contents of the tooltip wrapper. + equal( ui.tooltip[ 0 ].firstChild.innerHTML, content ); } }).tooltip( "open" ); }); -); test( "content: jQuery", function() { expect( 1 ); - var html = $( "

This is a test of the emergency broadcast system.

" ); + var content = "

This is a test of the emergency broadcast system.

" + var element = $( content ); $( "#tooltipped1" ).tooltip({ - content: html, + content: element, open: function( event, ui ) { - equal( ui.tooltip.html(), html ); + console.log( ui.tooltip ); + equal( ui.tooltip[ 0 ].firstChild.innerHTML, content ); } }).tooltip( "open" ); }); -); - test( "items", function() { expect( 2 ); diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index 4e88a3e12ac..e516b01baab 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -180,14 +180,10 @@ $.widget( "ui.tooltip", { _updateContent: function( target, event ) { var content, contentOption = this.options.content, - contentOptionType = (typeof contentOption), that = this, eventType = event ? event.type : null; - if ( contentOptionType === "string" || - ( contentOptionType === "object" && - ( contentOption instanceof HTMLElement || contentOption instanceof jQuery ) ) - ) { + if ( typeof contentOption === "string" || contentOption.nodeType || contentOption.jquery ) { return this._open( event, target, contentOption ); }