From da0ad8ec07dda8b1637d95c9f7811c10236bd09f Mon Sep 17 00:00:00 2001 From: Ivan Cheung Date: Mon, 2 Jun 2014 13:57:02 -0500 Subject: [PATCH 1/4] Tooltip: Preserve changes to title attribute on close --- tests/unit/tooltip/tooltip_methods.js | 24 +++++++++--------------- ui/tooltip.js | 15 +++++---------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js index 8d1b1bd5b7d..8ac30699204 100644 --- a/tests/unit/tooltip/tooltip_methods.js +++ b/tests/unit/tooltip/tooltip_methods.js @@ -109,30 +109,24 @@ 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 preserved when set to empty string on close()", title: "", expected: "", method: "close" }; + tests[ 3 ] = { name: "Changes to title attribute are preserved when set to empty string on destroy()", title: "", expected: "", method: "destroy" }; + tests[ 4 ] = { name: "Changes to title attribute are NOT preserved when attribute has been removed on close()", expected: original, method: "close" }; + tests[ 5 ] = { name: "Changes to title attribute are NOT preserved when attribute has been removed on destroy()", expected: original, 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 ); } ); }); diff --git a/ui/tooltip.js b/ui/tooltip.js index 52be04dcb91..7cc08af8052 100644 --- a/ui/tooltip.js +++ b/ui/tooltip.js @@ -250,15 +250,10 @@ return $.widget( "ui.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). + // We use removeAttr to allow IE to export the correct accessible + // attributes. if ( target.is( "[title]" ) ) { - if ( event && event.type === "mouseover" ) { - target.attr( "title", "" ); - } else { - target.removeAttr( "title" ); - } + target.removeAttr( "title" ); } tooltip = this._tooltip( target ); @@ -356,7 +351,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[0].hasAttribute( "title" ) ) { target.attr( "title", target.data( "ui-tooltip-title" ) ); } @@ -431,7 +426,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[0].hasAttribute( "title" ) ) { element.attr( "title", element.data( "ui-tooltip-title" ) ); } element.removeData( "ui-tooltip-title" ); From 602805c56db0143b7eee5e1f9d3105401ec8b263 Mon Sep 17 00:00:00 2001 From: Ivan Cheung Date: Mon, 2 Jun 2014 15:57:46 -0500 Subject: [PATCH 2/4] Tooltip unit test - use typesafe comparison --- tests/unit/tooltip/tooltip_methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js index 8ac30699204..c2a962039b2 100644 --- a/tests/unit/tooltip/tooltip_methods.js +++ b/tests/unit/tooltip/tooltip_methods.js @@ -120,7 +120,7 @@ test( "preserve changes to title attributes on close and destroy", function() { element.attr( "title", original ).tooltip() .tooltip( "open", $.Event( "mouseover", { target: element[ 0 ] } ) ); - if ( test.title != undefined) { + if ( test.title !== undefined) { element.attr( "title", test.title ); } else{ element.removeAttr( "title" ); From 955c58da32a8cf0450e8ad67adacf855620afbcd Mon Sep 17 00:00:00 2001 From: Ivan Cheung Date: Mon, 9 Jun 2014 13:04:04 -0500 Subject: [PATCH 3/4] Tooltip: normalize open via mouseover impl --- tests/unit/tooltip/tooltip_methods.js | 45 +++++++++++++++++++++------ ui/tooltip.js | 9 ++---- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js index c2a962039b2..7f2a3551283 100644 --- a/tests/unit/tooltip/tooltip_methods.js +++ b/tests/unit/tooltip/tooltip_methods.js @@ -109,15 +109,41 @@ test( "preserve changes to title attributes on close and destroy", function() { original = "original title text", tests = []; - 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 preserved when set to empty string on close()", title: "", expected: "", method: "close" }; - tests[ 3 ] = { name: "Changes to title attribute are preserved when set to empty string on destroy()", title: "", expected: "", method: "destroy" }; - tests[ 4 ] = { name: "Changes to title attribute are NOT preserved when attribute has been removed on close()", expected: original, method: "close" }; - tests[ 5 ] = { name: "Changes to title attribute are NOT preserved when attribute has been removed on destroy()", 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 !== undefined) { @@ -126,9 +152,8 @@ test( "preserve changes to title attributes on close and destroy", function() { element.removeAttr( "title" ); } element.tooltip( test.method ); - equal( $( "#tooltipped1" ).attr( "title" ), test.expected, test.name ); - - } ); + equal( $( "#tooltipped1" ).attr( "title" ), test.expected, test.name ); + }); }); }( jQuery ) ); diff --git a/ui/tooltip.js b/ui/tooltip.js index 7cc08af8052..836ed6067b8 100644 --- a/ui/tooltip.js +++ b/ui/tooltip.js @@ -249,11 +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 to allow IE to export the correct accessible - // attributes. if ( target.is( "[title]" ) ) { - target.removeAttr( "title" ); + target.attr( "title", "" ); } tooltip = this._tooltip( target ); @@ -351,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[0].hasAttribute( "title" ) ) { + if ( target.data( "ui-tooltip-title" ) && target.attr( "title" ) === "" ) { target.attr( "title", target.data( "ui-tooltip-title" ) ); } @@ -426,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[0].hasAttribute( "title" ) ) { + if ( element.attr( "title" ) === "" ) { element.attr( "title", element.data( "ui-tooltip-title" ) ); } element.removeData( "ui-tooltip-title" ); From 06b1a11f4c46c0ee223d3fc75409aa5f1435af21 Mon Sep 17 00:00:00 2001 From: Ivan Cheung Date: Mon, 9 Jun 2014 13:17:48 -0500 Subject: [PATCH 4/4] Lint Fix --- tests/unit/tooltip/tooltip_methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js index 7f2a3551283..beb72e8fbef 100644 --- a/tests/unit/tooltip/tooltip_methods.js +++ b/tests/unit/tooltip/tooltip_methods.js @@ -152,7 +152,7 @@ test( "preserve changes to title attributes on close and destroy", function() { element.removeAttr( "title" ); } element.tooltip( test.method ); - equal( $( "#tooltipped1" ).attr( "title" ), test.expected, test.name ); + equal( $( "#tooltipped1" ).attr( "title" ), test.expected, test.name ); }); });