diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js index 8d1b1bd5b7d..beb72e8fbef 100644 --- a/tests/unit/tooltip/tooltip_methods.js +++ b/tests/unit/tooltip/tooltip_methods.js @@ -109,32 +109,51 @@ test( "preserve changes to title attributes on close and destroy", function() { original = "original title text", tests = []; - // 1. Changes to title attribute are preserved on close() - tests[ 0 ] = { title: changed, expected: changed, method: "close" }; - // 2. Changes to title attribute are preserved on destroy() - tests[ 1 ] = { title: changed, expected: changed , method: "destroy" }; - // 3. Changes to title attribute are NOT preserved when set to empty string on close() - tests[ 2 ] = { title: "", expected: original, method: "close" }; - // 4. Changes to title attribute are NOT preserved when set to empty string on destroy() - tests[ 3 ] = { title: "", expected: original, method: "destroy" }; - // 5. Changes to title attribute NOT preserved when attribute has been removed on close() - tests[ 4 ] = { expected: original, method: "close" }; - // 6. Changes to title attribute NOT preserved when attribute has been removed on destroy() - tests[ 5 ] = { expected: original, method: "destroy" }; + tests[ 0 ] = { + name: "Changes to title attribute are preserved on close()", + title: changed, + expected: changed, + method: "close" + }; + tests[ 1 ] = { + name: "Changes to title attribute are preserved on destroy()", + title: changed, + expected: changed, + method: "destroy" + }; + tests[ 2 ] = { + name: "Changes to title attribute are NOT preserved when set to empty string on close()", + title: "", + expected: original, + method: "close" + }; + tests[ 3 ] = { + name: "Changes to title attribute are NOT preserved when set to empty string on destroy()", + title: "", + expected: original, + method: "destroy" }; + tests[ 4 ] = { + name: "Changes to title attribute are preserved when attribute has been removed on close()", + expected: undefined, + method: "close" + }; + tests[ 5 ] = { + name: "Changes to title attribute are preserved when attribute has been removed on destroy()", + expected: undefined, + method: "destroy" + }; $.each( tests, function( index, test ) { - element.attr( "title", original ).tooltip() .tooltip( "open", $.Event( "mouseover", { target: element[ 0 ] } ) ); - if ( test.title ) { + if ( test.title !== undefined) { element.attr( "title", test.title ); - } else { + } else{ element.removeAttr( "title" ); } element.tooltip( test.method ); - equal( $( "#tooltipped1" ).attr( "title" ), test.expected ); - - } ); + equal( $( "#tooltipped1" ).attr( "title" ), test.expected, test.name ); + }); }); }( jQuery ) ); diff --git a/ui/tooltip.js b/ui/tooltip.js index 52be04dcb91..836ed6067b8 100644 --- a/ui/tooltip.js +++ b/ui/tooltip.js @@ -249,16 +249,8 @@ return $.widget( "ui.tooltip", { // if we have a title, clear it to prevent the native tooltip // we have to check first to avoid defining a title if none exists // (we don't want to cause an element to start matching [title]) - // - // We use removeAttr only for key events, to allow IE to export the correct - // accessible attributes. For mouse events, set to empty string to avoid - // native tooltip showing up (happens only when removing inside mouseover). if ( target.is( "[title]" ) ) { - if ( event && event.type === "mouseover" ) { - target.attr( "title", "" ); - } else { - target.removeAttr( "title" ); - } + target.attr( "title", "" ); } tooltip = this._tooltip( target ); @@ -356,7 +348,7 @@ return $.widget( "ui.tooltip", { // only set title if we had one before (see comment in _open()) // If the title attribute has changed since open(), don't restore - if ( target.data( "ui-tooltip-title" ) && !target.attr( "title" ) ) { + if ( target.data( "ui-tooltip-title" ) && target.attr( "title" ) === "" ) { target.attr( "title", target.data( "ui-tooltip-title" ) ); } @@ -431,7 +423,7 @@ return $.widget( "ui.tooltip", { // Restore the title if ( element.data( "ui-tooltip-title" ) ) { // If the title attribute has changed since open(), don't restore - if ( !element.attr( "title" ) ) { + if ( element.attr( "title" ) === "" ) { element.attr( "title", element.data( "ui-tooltip-title" ) ); } element.removeData( "ui-tooltip-title" );