Tooltip: Style updates

Ref #14246
This commit is contained in:
Alexander Schmitz 2015-08-24 08:50:46 -04:00
parent cfd48ed037
commit a0892eca70
8 changed files with 124 additions and 109 deletions

View File

@ -26,6 +26,6 @@ common.testWidget( "tooltip", {
create: null, create: null,
open: null open: null
} }
}); } );
} ); } );

View File

@ -25,6 +25,6 @@ common.testWidget( "tooltip", {
create: null, create: null,
open: null open: null
} }
}); } );
} ); } );

View File

@ -21,7 +21,7 @@ test( "markup structure", function( assert ) {
equal( tooltip.length, 1, ".ui-tooltip exists" ); equal( tooltip.length, 1, ".ui-tooltip exists" );
equal( tooltip.find( ".ui-tooltip-content" ).length, 1, equal( tooltip.find( ".ui-tooltip-content" ).length, 1,
".ui-tooltip-content exists" ); ".ui-tooltip-content exists" );
}); } );
test( "accessibility", function() { test( "accessibility", function() {
expect( 15 ); expect( 15 );
@ -61,7 +61,7 @@ test( "accessibility", function() {
element.tooltip( "destroy" ); element.tooltip( "destroy" );
equal( liveRegion.parent().length, 0, equal( liveRegion.parent().length, 0,
"Tooltip liveregion element should be removed" ); "Tooltip liveregion element should be removed" );
}); } );
test( "delegated removal", function() { test( "delegated removal", function() {
expect( 2 ); expect( 2 );
@ -74,32 +74,32 @@ test( "delegated removal", function() {
container.empty(); container.empty();
equal( $( ".ui-tooltip" ).length, 0 ); equal( $( ".ui-tooltip" ).length, 0 );
}); } );
test( "nested tooltips", function() { test( "nested tooltips", function() {
expect( 2 ); expect( 2 );
var child = $( "#contained-tooltipped" ), var child = $( "#contained-tooltipped" ),
parent = $( "#contains-tooltipped" ).tooltip({ parent = $( "#contains-tooltipped" ).tooltip( {
show: null, show: null,
hide: null hide: null
}); } );
parent.trigger( "mouseover" ); parent.trigger( "mouseover" );
equal( $( ".ui-tooltip:visible" ).text(), "parent" ); equal( $( ".ui-tooltip:visible" ).text(), "parent" );
child.trigger( "mouseover" ); child.trigger( "mouseover" );
equal( $( ".ui-tooltip" ).text(), "child" ); equal( $( ".ui-tooltip" ).text(), "child" );
}); } );
// #8742 // #8742
test( "form containing an input with name title", function() { test( "form containing an input with name title", function() {
expect( 4 ); expect( 4 );
var form = $( "#tooltip-form" ).tooltip({ var form = $( "#tooltip-form" ).tooltip( {
show: null, show: null,
hide: null hide: null
}), } ),
input = form.find( "[name=title]" ); input = form.find( "[name=title]" );
equal( $( ".ui-tooltip" ).length, 0, "no tooltips on init" ); equal( $( ".ui-tooltip" ).length, 0, "no tooltips on init" );
@ -111,7 +111,7 @@ test( "form containing an input with name title", function() {
form.trigger( "mouseover" ); form.trigger( "mouseover" );
equal( $( ".ui-tooltip" ).length, 0, "no tooltip for form" ); equal( $( ".ui-tooltip" ).length, 0, "no tooltip for form" );
}); } );
test( "tooltip on .ui-state-disabled element", function() { test( "tooltip on .ui-state-disabled element", function() {
expect( 2 ); expect( 2 );
@ -124,18 +124,18 @@ test( "tooltip on .ui-state-disabled element", function() {
container.empty(); container.empty();
equal( $( ".ui-tooltip" ).length, 0 ); equal( $( ".ui-tooltip" ).length, 0 );
}); } );
// http://bugs.jqueryui.com/ticket/8740 // http://bugs.jqueryui.com/ticket/8740
asyncTest( "programmatic focus with async content", function() { asyncTest( "programmatic focus with async content", function() {
expect( 2 ); expect( 2 );
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
content: function( response ) { content: function( response ) {
setTimeout(function() { setTimeout( function() {
response( "test" ); response( "test" );
}); } );
} }
}); } );
element.on( "tooltipopen", function( event ) { element.on( "tooltipopen", function( event ) {
deepEqual( event.originalEvent.type, "focusin" ); deepEqual( event.originalEvent.type, "focusin" );
@ -143,35 +143,35 @@ asyncTest( "programmatic focus with async content", function() {
element.on( "tooltipclose", function( event ) { element.on( "tooltipclose", function( event ) {
deepEqual( event.originalEvent.type, "focusout" ); deepEqual( event.originalEvent.type, "focusout" );
start(); start();
}); } );
setTimeout(function() { setTimeout( function() {
element.trigger( "blur" ); element.trigger( "blur" );
}); } );
}); } );
element.trigger( "focus" ); element.trigger( "focus" );
}); } );
asyncTest( "destroy during hide animation; only one close event", function() { asyncTest( "destroy during hide animation; only one close event", function() {
expect( 1 ); expect( 1 );
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
show: false, show: false,
hide: true hide: true
}); } );
element.on( "tooltipclose", function() { element.on( "tooltipclose", function() {
ok( true, "tooltip closed" ); ok( true, "tooltip closed" );
}); } );
element.tooltip( "open" ); element.tooltip( "open" );
element.tooltip( "close" ); element.tooltip( "close" );
setTimeout(function() { setTimeout( function() {
element.tooltip( "destroy" ); element.tooltip( "destroy" );
start(); start();
}); } );
}); } );
// http://bugs.jqueryui.com/ticket/10602 // http://bugs.jqueryui.com/ticket/10602
asyncTest( "multiple active delegated tooltips", function() { asyncTest( "multiple active delegated tooltips", function() {
@ -181,7 +181,7 @@ asyncTest( "multiple active delegated tooltips", function() {
input = anchor.next(), input = anchor.next(),
actions = []; actions = [];
$( document ).tooltip({ $( document ).tooltip( {
show: false, show: false,
hide: false, hide: false,
open: function( event, ui ) { open: function( event, ui ) {
@ -190,7 +190,7 @@ asyncTest( "multiple active delegated tooltips", function() {
close: function( event, ui ) { close: function( event, ui ) {
actions.push( "close:" + ui.tooltip.text() ); actions.push( "close:" + ui.tooltip.text() );
} }
}); } );
function step1() { function step1() {
anchor.simulate( "mouseover" ); anchor.simulate( "mouseover" );
@ -219,7 +219,7 @@ asyncTest( "multiple active delegated tooltips", function() {
} }
step1(); step1();
}); } );
// http://bugs.jqueryui.com/ticket/11272 // http://bugs.jqueryui.com/ticket/11272
test( "remove conflicting attributes from live region", function() { test( "remove conflicting attributes from live region", function() {
@ -234,7 +234,7 @@ test( "remove conflicting attributes from live region", function() {
"</div>" ); "</div>" );
$( "#tooltipped1" ) $( "#tooltipped1" )
.tooltip({ .tooltip( {
content: element, content: element,
open: function() { open: function() {
equal( $( ".ui-helper-hidden-accessible [name]" ).length, 0, equal( $( ".ui-helper-hidden-accessible [name]" ).length, 0,
@ -242,8 +242,8 @@ test( "remove conflicting attributes from live region", function() {
equal( $( ".ui-helper-hidden-accessible [id]" ).length, 0, equal( $( ".ui-helper-hidden-accessible [id]" ).length, 0,
"no id attributes within live region" ); "no id attributes within live region" );
} }
}) } )
.tooltip( "open" ); .tooltip( "open" );
}); } );
} ); } );

View File

@ -7,10 +7,10 @@ module( "tooltip: (deprecated) options" );
test( "tooltipClass", function( assert ) { test( "tooltipClass", function( assert ) {
expect( 1 ); expect( 1 );
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
tooltipClass: "custom" tooltipClass: "custom"
}).tooltip( "open" ); } ).tooltip( "open" );
assert.hasClasses( $( "#" + element.data( "ui-tooltip-id" ) ), "custom" ); assert.hasClasses( $( "#" + element.data( "ui-tooltip-id" ) ), "custom" );
}); } );
} ); } );

View File

@ -13,17 +13,17 @@ test( "programmatic triggers", function() {
element.one( "tooltipopen", function( event, ui ) { element.one( "tooltipopen", function( event, ui ) {
tooltip = ui.tooltip; tooltip = ui.tooltip;
ok( !( "originalEvent" in event ), "open" ); ok( !( "originalEvent" in event ), "open" );
strictEqual( ui.tooltip[0], strictEqual( ui.tooltip[ 0 ],
$( "#" + element.data( "ui-tooltip-id" ) )[0], "ui.tooltip" ); $( "#" + element.data( "ui-tooltip-id" ) )[ 0 ], "ui.tooltip" );
}); } );
element.tooltip( "open" ); element.tooltip( "open" );
element.one( "tooltipclose", function( event, ui ) { element.one( "tooltipclose", function( event, ui ) {
ok( !( "originalEvent" in event ), "close" ); ok( !( "originalEvent" in event ), "close" );
strictEqual( ui.tooltip[0], tooltip[0], "ui.tooltip" ); strictEqual( ui.tooltip[ 0 ], tooltip[ 0 ], "ui.tooltip" );
}); } );
element.tooltip( "close" ); element.tooltip( "close" );
}); } );
test( "mouse events", function() { test( "mouse events", function() {
expect( 2 ); expect( 2 );
@ -31,15 +31,15 @@ test( "mouse events", function() {
element.on( "tooltipopen", function( event ) { element.on( "tooltipopen", function( event ) {
deepEqual( event.originalEvent.type, "mouseover" ); deepEqual( event.originalEvent.type, "mouseover" );
}); } );
element.trigger( "mouseover" ); element.trigger( "mouseover" );
element.on( "tooltipclose", function( event ) { element.on( "tooltipclose", function( event ) {
deepEqual( event.originalEvent.type, "mouseleave" ); deepEqual( event.originalEvent.type, "mouseleave" );
}); } );
element.trigger( "focusout" ); element.trigger( "focusout" );
element.trigger( "mouseleave" ); element.trigger( "mouseleave" );
}); } );
test( "focus events", function() { test( "focus events", function() {
expect( 2 ); expect( 2 );
@ -47,14 +47,14 @@ test( "focus events", function() {
element.on( "tooltipopen", function( event ) { element.on( "tooltipopen", function( event ) {
deepEqual( event.originalEvent.type, "focusin" ); deepEqual( event.originalEvent.type, "focusin" );
}); } );
element.trigger( "focusin" ); element.trigger( "focusin" );
element.on( "tooltipclose", function( event ) { element.on( "tooltipclose", function( event ) {
deepEqual( event.originalEvent.type, "focusout" ); deepEqual( event.originalEvent.type, "focusout" );
}); } );
element.trigger( "mouseleave" ); element.trigger( "mouseleave" );
element.trigger( "focusout" ); element.trigger( "focusout" );
}); } );
} ); } );

View File

@ -11,17 +11,17 @@ test( "destroy", function( assert ) {
assert.domEqual( "#tooltipped1", function() { assert.domEqual( "#tooltipped1", function() {
element.tooltip().tooltip( "destroy" ); element.tooltip().tooltip( "destroy" );
}); } );
// Make sure that open tooltips are removed on destroy // Make sure that open tooltips are removed on destroy
assert.domEqual( "#tooltipped1", function() { assert.domEqual( "#tooltipped1", function() {
element element
.tooltip() .tooltip()
.tooltip( "open", $.Event( "mouseover", { target: element[0] }) ) .tooltip( "open", $.Event( "mouseover", { target: element[ 0 ] } ) )
.tooltip( "destroy" ); .tooltip( "destroy" );
}); } );
equal( $( ".ui-tooltip" ).length, 0 ); equal( $( ".ui-tooltip" ).length, 0 );
}); } );
test( "open/close", function() { test( "open/close", function() {
expect( 3 ); expect( 3 );
@ -37,14 +37,14 @@ test( "open/close", function() {
element.tooltip( "close" ); element.tooltip( "close" );
ok( tooltip.is( ":hidden" ) ); ok( tooltip.is( ":hidden" ) );
$.fx.off = false; $.fx.off = false;
}); } );
// #8626 - Calling open() without an event // #8626 - Calling open() without an event
test( "open/close with tracking", function() { test( "open/close with tracking", function() {
expect( 3 ); expect( 3 );
$.fx.off = true; $.fx.off = true;
var tooltip, var tooltip,
element = $( "#tooltipped1" ).tooltip({ track: true }); element = $( "#tooltipped1" ).tooltip( { track: true } );
equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
element.tooltip( "open" ); element.tooltip( "open" );
@ -54,7 +54,7 @@ test( "open/close with tracking", function() {
element.tooltip( "close" ); element.tooltip( "close" );
ok( tooltip.is( ":hidden" ) ); ok( tooltip.is( ":hidden" ) );
$.fx.off = false; $.fx.off = false;
}); } );
test( "enable/disable", function( assert ) { test( "enable/disable", function( assert ) {
expect( 11 ); expect( 11 );
@ -91,7 +91,7 @@ test( "enable/disable", function( assert ) {
tooltip = $( "#" + element.data( "ui-tooltip-id" ) ); tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
ok( tooltip.is( ":visible" ) ); ok( tooltip.is( ":visible" ) );
$.fx.off = false; $.fx.off = false;
}); } );
test( "widget", function() { test( "widget", function() {
expect( 2 ); expect( 2 );
@ -99,7 +99,7 @@ test( "widget", function() {
widgetElement = element.tooltip( "widget" ); widgetElement = element.tooltip( "widget" );
equal( widgetElement.length, 1, "one element" ); equal( widgetElement.length, 1, "one element" );
strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" ); strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
}); } );
test( "preserve changes to title attributes on close and destroy", function() { test( "preserve changes to title attributes on close and destroy", function() {
expect( 6 ); expect( 6 );
@ -110,14 +110,19 @@ test( "preserve changes to title attributes on close and destroy", function() {
// 1. Changes to title attribute are preserved on close() // 1. Changes to title attribute are preserved on close()
tests[ 0 ] = { title: changed, expected: changed, method: "close" }; tests[ 0 ] = { title: changed, expected: changed, method: "close" };
// 2. Changes to title attribute are preserved on destroy() // 2. Changes to title attribute are preserved on destroy()
tests[ 1 ] = { title: changed, expected: changed , method: "destroy" }; tests[ 1 ] = { title: changed, expected: changed, method: "destroy" };
// 3. Changes to title attribute are NOT preserved when set to empty string on close() // 3. Changes to title attribute are NOT preserved when set to empty string on close()
tests[ 2 ] = { title: "", expected: original, method: "close" }; tests[ 2 ] = { title: "", expected: original, method: "close" };
// 4. Changes to title attribute are NOT preserved when set to empty string on destroy() // 4. Changes to title attribute are NOT preserved when set to empty string on destroy()
tests[ 3 ] = { title: "", expected: original, method: "destroy" }; tests[ 3 ] = { title: "", expected: original, method: "destroy" };
// 5. Changes to title attribute NOT preserved when attribute has been removed on close() // 5. Changes to title attribute NOT preserved when attribute has been removed on close()
tests[ 4 ] = { expected: original, method: "close" }; tests[ 4 ] = { expected: original, method: "close" };
// 6. Changes to title attribute NOT preserved when attribute has been removed on destroy() // 6. Changes to title attribute NOT preserved when attribute has been removed on destroy()
tests[ 5 ] = { expected: original, method: "destroy" }; tests[ 5 ] = { expected: original, method: "destroy" };
@ -134,6 +139,6 @@ test( "preserve changes to title attributes on close and destroy", function() {
equal( $( "#tooltipped1" ).attr( "title" ), test.expected ); equal( $( "#tooltipped1" ).attr( "title" ), test.expected );
} ); } );
}); } );
} ); } );

View File

@ -7,17 +7,17 @@ module( "tooltip: options" );
test( "disabled: true", function() { test( "disabled: true", function() {
expect( 1 ); expect( 1 );
$( "#tooltipped1" ).tooltip({ $( "#tooltipped1" ).tooltip( {
disabled: true disabled: true
}).tooltip( "open" ); } ).tooltip( "open" );
equal( $( ".ui-tooltip" ).length, 0 ); equal( $( ".ui-tooltip" ).length, 0 );
}); } );
test( "content: default", function() { test( "content: default", function() {
expect( 1 ); expect( 1 );
var element = $( "#tooltipped1" ).tooltip().tooltip( "open" ); var element = $( "#tooltipped1" ).tooltip().tooltip( "open" );
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" ); deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" );
}); } );
test( "content: default; HTML escaping", function() { test( "content: default; HTML escaping", function() {
expect( 2 ); expect( 2 );
@ -31,130 +31,130 @@ test( "content: default; HTML escaping", function() {
equal( $.ui.tooltip.hacked, false, "script did not execute" ); equal( $.ui.tooltip.hacked, false, "script did not execute" );
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText, deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText,
"correct tooltip text" ); "correct tooltip text" );
}); } );
test( "content: return string", function() { test( "content: return string", function() {
expect( 1 ); expect( 1 );
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
content: function() { content: function() {
return "customstring"; return "customstring";
} }
}).tooltip( "open" ); } ).tooltip( "open" );
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" );
}); } );
test( "content: return jQuery", function() { test( "content: return jQuery", function() {
expect( 2 ); expect( 2 );
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
content: function() { content: function() {
return $( "<div id='unique'>" ).html( "cu<b id='bold'>s</b>tomstring" ); return $( "<div id='unique'>" ).html( "cu<b id='bold'>s</b>tomstring" );
} }
}).tooltip( "open" ), } ).tooltip( "open" ),
liveRegion = element.tooltip( "instance" ).liveRegion; liveRegion = element.tooltip( "instance" ).liveRegion;
deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" );
equal( liveRegion.children().last().html().toLowerCase(), "<div>cu<b>s</b>tomstring</div>", equal( liveRegion.children().last().html().toLowerCase(), "<div>cu<b>s</b>tomstring</div>",
"The accessibility live region will strip the ids but keep the structure" ); "The accessibility live region will strip the ids but keep the structure" );
}); } );
asyncTest( "content: sync + async callback", function() { asyncTest( "content: sync + async callback", function() {
expect( 2 ); expect( 2 );
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
content: function( response ) { content: function( response ) {
setTimeout(function() { setTimeout( function() {
deepEqual( $( "#" + element.data("ui-tooltip-id") ).text(), "loading..." ); deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "loading..." );
response( "customstring2" ); response( "customstring2" );
setTimeout(function() { setTimeout( function() {
deepEqual( $( "#" + element.data("ui-tooltip-id") ).text(), "customstring2" ); deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring2" );
start(); start();
}, 13 ); }, 13 );
}, 13 ); }, 13 );
return "loading..."; return "loading...";
} }
}).tooltip( "open" ); } ).tooltip( "open" );
}); } );
// http://bugs.jqueryui.com/ticket/8740 // http://bugs.jqueryui.com/ticket/8740
asyncTest( "content: async callback loses focus before load", function() { asyncTest( "content: async callback loses focus before load", function() {
expect( 1 ); expect( 1 );
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
content: function( response ) { content: function( response ) {
setTimeout(function() { setTimeout( function() {
element.trigger( "mouseleave" ); element.trigger( "mouseleave" );
setTimeout(function() { setTimeout( function() {
response( "sometext" ); response( "sometext" );
setTimeout(function() { setTimeout( function() {
ok( !$( "#" + element.data( "ui-tooltip-id" ) ).is( ":visible" ), ok( !$( "#" + element.data( "ui-tooltip-id" ) ).is( ":visible" ),
"Tooltip should not display" ); "Tooltip should not display" );
start(); start();
}); } );
}); } );
}); } );
} }
}); } );
element.trigger( "mouseover" ); element.trigger( "mouseover" );
}); } );
test( "content: change while open", function() { test( "content: change while open", function() {
expect( 2 ) ; expect( 2 ) ;
var element = $( "#tooltipped1" ).tooltip({ var element = $( "#tooltipped1" ).tooltip( {
content: function() { content: function() {
return "old"; return "old";
} }
}); } );
element.one( "tooltipopen", function( event, ui ) { element.one( "tooltipopen", function( event, ui ) {
equal( ui.tooltip.text(), "old", "original content" ); equal( ui.tooltip.text(), "old", "original content" );
element.tooltip( "option", "content", function() { element.tooltip( "option", "content", function() {
return "new"; return "new";
}); } );
equal( ui.tooltip.text(), "new", "updated content" ); equal( ui.tooltip.text(), "new", "updated content" );
}); } );
element.tooltip( "open" ); element.tooltip( "open" );
}); } );
test( "content: string", function() { test( "content: string", function() {
expect( 1 ); expect( 1 );
$( "#tooltipped1" ).tooltip({ $( "#tooltipped1" ).tooltip( {
content: "just a string", content: "just a string",
open: function( event, ui ) { open: function( event, ui ) {
equal( ui.tooltip.text(), "just a string" ); equal( ui.tooltip.text(), "just a string" );
} }
}).tooltip( "open" ); } ).tooltip( "open" );
}); } );
test( "content: element", function() { test( "content: element", function() {
expect( 1 ); expect( 1 );
var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>", var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>",
element = $( content )[ 0 ]; element = $( content )[ 0 ];
$( "#tooltipped1" ).tooltip({ $( "#tooltipped1" ).tooltip( {
content: element, content: element,
open: function( event, ui ) { open: function( event, ui ) {
equal( ui.tooltip.children().html().toLowerCase(), content ); equal( ui.tooltip.children().html().toLowerCase(), content );
} }
}).tooltip( "open" ); } ).tooltip( "open" );
}); } );
test( "content: jQuery", function() { test( "content: jQuery", function() {
expect( 1 ); expect( 1 );
var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>", var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>",
element = $( content ); element = $( content );
$( "#tooltipped1" ).tooltip({ $( "#tooltipped1" ).tooltip( {
content: element, content: element,
open: function( event, ui ) { open: function( event, ui ) {
equal( ui.tooltip.children().html().toLowerCase(), content ); equal( ui.tooltip.children().html().toLowerCase(), content );
} }
}).tooltip( "open" ); } ).tooltip( "open" );
}); } );
test( "items", function() { test( "items", function() {
expect( 2 ); expect( 2 );
var event, var event,
element = $( "#qunit-fixture" ).tooltip({ element = $( "#qunit-fixture" ).tooltip( {
items: "#fixture-span" items: "#fixture-span"
}); } );
event = $.Event( "mouseenter" ); event = $.Event( "mouseenter" );
event.target = $( "#fixture-span" )[ 0 ]; event.target = $( "#fixture-span" )[ 0 ];
@ -167,7 +167,7 @@ test( "items", function() {
deepEqual( $( "#tooltipped1" ).data( "ui-tooltip-id" ), undefined ); deepEqual( $( "#tooltipped1" ).data( "ui-tooltip-id" ), undefined );
element.tooltip( "destroy" ); element.tooltip( "destroy" );
}); } );
test( "track + show delay", function() { test( "track + show delay", function() {
expect( 2 ); expect( 2 );
@ -175,7 +175,7 @@ test( "track + show delay", function() {
leftVal = 314, leftVal = 314,
topVal = 159, topVal = 159,
offsetVal = 26, offsetVal = 26,
element = $( "#tooltipped1" ).tooltip({ element = $( "#tooltipped1" ).tooltip( {
track: true, track: true,
show: { show: {
delay: 1 delay: 1
@ -184,7 +184,7 @@ test( "track + show delay", function() {
my: "left+" + offsetVal + " top+" + offsetVal, my: "left+" + offsetVal + " top+" + offsetVal,
at: "right bottom" at: "right bottom"
} }
}); } );
event = $.Event( "mouseover" ); event = $.Event( "mouseover" );
event.target = $( "#tooltipped1" )[ 0 ]; event.target = $( "#tooltipped1" )[ 0 ];
@ -202,14 +202,14 @@ test( "track + show delay", function() {
equal( $( ".ui-tooltip" ).css( "left" ), leftVal + offsetVal + "px" ); equal( $( ".ui-tooltip" ).css( "left" ), leftVal + offsetVal + "px" );
equal( $( ".ui-tooltip" ).css( "top" ), topVal + offsetVal + "px" ); equal( $( ".ui-tooltip" ).css( "top" ), topVal + offsetVal + "px" );
}); } );
test( "track and programmatic focus", function() { test( "track and programmatic focus", function() {
expect( 1 ); expect( 1 );
$( "#qunit-fixture div input" ).tooltip({ $( "#qunit-fixture div input" ).tooltip( {
track: true track: true
}).trigger( "focus" ); } ).trigger( "focus" );
equal( "inputtitle", $( ".ui-tooltip" ).text() ); equal( "inputtitle", $( ".ui-tooltip" ).text() );
}); } );
} ); } );

View File

@ -42,13 +42,16 @@ $.widget( "ui.tooltip", {
"ui-tooltip": "ui-corner-all ui-widget-shadow" "ui-tooltip": "ui-corner-all ui-widget-shadow"
}, },
content: function() { content: function() {
// support: IE<9, Opera in jQuery <1.7 // support: IE<9, Opera in jQuery <1.7
// .text() can't accept undefined, so coerce to a string // .text() can't accept undefined, so coerce to a string
var title = $( this ).attr( "title" ) || ""; var title = $( this ).attr( "title" ) || "";
// Escape title, since we're going from an attribute to raw HTML // Escape title, since we're going from an attribute to raw HTML
return $( "<a>" ).text( title ).html(); return $( "<a>" ).text( title ).html();
}, },
hide: true, hide: true,
// Disabled elements have inconsistent behavior across browsers (#8661) // Disabled elements have inconsistent behavior across browsers (#8661)
items: "[title]:not([disabled])", items: "[title]:not([disabled])",
position: { position: {
@ -123,6 +126,7 @@ $.widget( "ui.tooltip", {
if ( key === "disabled" ) { if ( key === "disabled" ) {
this[ value ? "_disable" : "_enable" ](); this[ value ? "_disable" : "_enable" ]();
this.options[ key ] = value; this.options[ key ] = value;
// disable element style changes // disable element style changes
return; return;
} }
@ -158,6 +162,7 @@ $.widget( "ui.tooltip", {
}, },
_enable: function() { _enable: function() {
// restore title attributes // restore title attributes
this.element.find( this.options.items ).addBack().each( function() { this.element.find( this.options.items ).addBack().each( function() {
var element = $( this ); var element = $( this );
@ -170,6 +175,7 @@ $.widget( "ui.tooltip", {
open: function( event ) { open: function( event ) {
var that = this, var that = this,
target = $( event ? event.target : this.element ) target = $( event ? event.target : this.element )
// we need closest here due to mouseover bubbling, // we need closest here due to mouseover bubbling,
// but always pointing at the same event target // but always pointing at the same event target
.closest( this.options.items ); .closest( this.options.items );
@ -304,6 +310,7 @@ $.widget( "ui.tooltip", {
this._on( this.document, { this._on( this.document, {
mousemove: position mousemove: position
} ); } );
// trigger once to override element-relative positioning // trigger once to override element-relative positioning
position( event ); position( event );
} else { } else {
@ -315,6 +322,7 @@ $.widget( "ui.tooltip", {
tooltip.hide(); tooltip.hide();
this._show( tooltip, this.options.show ); this._show( tooltip, this.options.show );
// Handle tracking tooltips that are shown with a delay (#8644). As soon // Handle tracking tooltips that are shown with a delay (#8644). As soon
// as the tooltip is visible, position the tooltip using the most recent // as the tooltip is visible, position the tooltip using the most recent
// event. // event.
@ -464,6 +472,7 @@ $.widget( "ui.tooltip", {
// Close open tooltips // Close open tooltips
$.each( this.tooltips, function( id, tooltipData ) { $.each( this.tooltips, function( id, tooltipData ) {
// Delegate to close method to handle common cleanup // Delegate to close method to handle common cleanup
var event = $.Event( "blur" ), var event = $.Event( "blur" ),
element = tooltipData.element; element = tooltipData.element;
@ -476,6 +485,7 @@ $.widget( "ui.tooltip", {
// Restore the title // Restore the title
if ( element.data( "ui-tooltip-title" ) ) { if ( element.data( "ui-tooltip-title" ) ) {
// If the title attribute has changed since open(), don't restore // 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.attr( "title", element.data( "ui-tooltip-title" ) );