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

@ -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" };

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" ) );