Tooltip: Fix style issues

Closes gh-1492
This commit is contained in:
Jörn Zaefferer 2015-03-13 19:36:41 +01:00
parent 2c3be80143
commit adcc9680ec

View File

@ -16,11 +16,11 @@
//>>css.structure: ../themes/base/tooltip.css //>>css.structure: ../themes/base/tooltip.css
//>>css.theme: ../themes/base/theme.css //>>css.theme: ../themes/base/theme.css
(function( factory ) { ( function( factory ) {
if ( typeof define === "function" && define.amd ) { if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module. // AMD. Register as an anonymous module.
define([ define( [
"jquery", "jquery",
"./core", "./core",
"./widget", "./widget",
@ -31,7 +31,7 @@
// Browser globals // Browser globals
factory( jQuery ); factory( jQuery );
} }
}(function( $ ) { }( function( $ ) {
$.widget( "ui.tooltip", { $.widget( "ui.tooltip", {
version: "@VERSION", version: "@VERSION",
@ -63,7 +63,7 @@ $.widget( "ui.tooltip", {
}, },
_addDescribedBy: function( elem, id ) { _addDescribedBy: function( elem, id ) {
var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ); var describedby = ( elem.attr( "aria-describedby" ) || "" ).split( /\s+/ );
describedby.push( id ); describedby.push( id );
elem elem
.data( "ui-tooltip-id", id ) .data( "ui-tooltip-id", id )
@ -72,7 +72,7 @@ $.widget( "ui.tooltip", {
_removeDescribedBy: function( elem ) { _removeDescribedBy: function( elem ) {
var id = elem.data( "ui-tooltip-id" ), var id = elem.data( "ui-tooltip-id" ),
describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ), describedby = ( elem.attr( "aria-describedby" ) || "" ).split( /\s+/ ),
index = $.inArray( id, describedby ); index = $.inArray( id, describedby );
if ( index !== -1 ) { if ( index !== -1 ) {
@ -89,10 +89,10 @@ $.widget( "ui.tooltip", {
}, },
_create: function() { _create: function() {
this._on({ this._on( {
mouseover: "open", mouseover: "open",
focusin: "open" focusin: "open"
}); } );
// IDs of generated tooltips, needed for destroy // IDs of generated tooltips, needed for destroy
this.tooltips = {}; this.tooltips = {};
@ -106,11 +106,11 @@ $.widget( "ui.tooltip", {
// Append the aria-live region so tooltips announce correctly // Append the aria-live region so tooltips announce correctly
this.liveRegion = $( "<div>" ) this.liveRegion = $( "<div>" )
.attr({ .attr( {
role: "log", role: "log",
"aria-live": "assertive", "aria-live": "assertive",
"aria-relevant": "additions" "aria-relevant": "additions"
}) } )
.appendTo( this.document[ 0 ].body ); .appendTo( this.document[ 0 ].body );
this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" ); this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
}, },
@ -130,7 +130,7 @@ $.widget( "ui.tooltip", {
if ( key === "content" ) { if ( key === "content" ) {
$.each( this.tooltips, function( id, tooltipData ) { $.each( this.tooltips, function( id, tooltipData ) {
that._updateContent( tooltipData.element ); that._updateContent( tooltipData.element );
}); } );
} }
}, },
@ -142,27 +142,27 @@ $.widget( "ui.tooltip", {
var event = $.Event( "blur" ); var event = $.Event( "blur" );
event.target = event.currentTarget = tooltipData.element[ 0 ]; event.target = event.currentTarget = tooltipData.element[ 0 ];
that.close( event, true ); that.close( event, true );
}); } );
// remove title attributes to prevent native tooltips // remove title attributes to prevent native tooltips
this.element.find( this.options.items ).addBack().each(function() { this.element.find( this.options.items ).addBack().each( function() {
var element = $( this ); var element = $( this );
if ( element.is( "[title]" ) ) { if ( element.is( "[title]" ) ) {
element element
.data( "ui-tooltip-title", element.attr( "title" ) ) .data( "ui-tooltip-title", element.attr( "title" ) )
.removeAttr( "title" ); .removeAttr( "title" );
} }
}); } );
}, },
_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 );
if ( element.data( "ui-tooltip-title" ) ) { if ( element.data( "ui-tooltip-title" ) ) {
element.attr( "title", element.data( "ui-tooltip-title" ) ); element.attr( "title", element.data( "ui-tooltip-title" ) );
} }
}); } );
}, },
open: function( event ) { open: function( event ) {
@ -185,7 +185,7 @@ $.widget( "ui.tooltip", {
// kill parent tooltips, custom or native, for hover // kill parent tooltips, custom or native, for hover
if ( event && event.type === "mouseover" ) { if ( event && event.type === "mouseover" ) {
target.parents().each(function() { target.parents().each( function() {
var parent = $( this ), var parent = $( this ),
blurEvent; blurEvent;
if ( parent.data( "ui-tooltip-open" ) ) { if ( parent.data( "ui-tooltip-open" ) ) {
@ -201,7 +201,7 @@ $.widget( "ui.tooltip", {
}; };
parent.attr( "title", "" ); parent.attr( "title", "" );
} }
}); } );
} }
this._registerCloseHandlers( event, target ); this._registerCloseHandlers( event, target );
@ -219,11 +219,11 @@ $.widget( "ui.tooltip", {
return this._open( event, target, contentOption ); return this._open( event, target, contentOption );
} }
content = contentOption.call( target[0], function( response ) { content = contentOption.call( target[ 0 ], function( response ) {
// IE may instantly serve a cached response for ajax requests // IE may instantly serve a cached response for ajax requests
// delay this call to _open so the other call to _open runs first // delay this call to _open so the other call to _open runs first
that._delay(function() { that._delay( function() {
// Ignore async response if tooltip was closed already // Ignore async response if tooltip was closed already
if ( !target.data( "ui-tooltip-open" ) ) { if ( !target.data( "ui-tooltip-open" ) ) {
@ -239,8 +239,8 @@ $.widget( "ui.tooltip", {
event.type = eventType; event.type = eventType;
} }
this._open( event, target, response ); this._open( event, target, response );
}); } );
}); } );
if ( content ) { if ( content ) {
this._open( event, target, content ); this._open( event, target, content );
} }
@ -300,11 +300,11 @@ $.widget( "ui.tooltip", {
if ( this.options.track && event && /^mouse/.test( event.type ) ) { if ( this.options.track && event && /^mouse/.test( event.type ) ) {
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 {
tooltip.position( $.extend({ tooltip.position( $.extend( {
of: target of: target
}, this.options.position ) ); }, this.options.position ) );
} }
@ -316,7 +316,7 @@ $.widget( "ui.tooltip", {
// 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.
if ( this.options.show && this.options.show.delay ) { if ( this.options.show && this.options.show.delay ) {
delayedShow = this.delayedShow = setInterval(function() { delayedShow = this.delayedShow = setInterval( function() {
if ( tooltip.is( ":visible" ) ) { if ( tooltip.is( ":visible" ) ) {
position( positionOption.of ); position( positionOption.of );
clearInterval( delayedShow ); clearInterval( delayedShow );
@ -331,8 +331,8 @@ $.widget( "ui.tooltip", {
var events = { var events = {
keyup: function( event ) { keyup: function( event ) {
if ( event.keyCode === $.ui.keyCode.ESCAPE ) { if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
var fakeEvent = $.Event(event); var fakeEvent = $.Event( event );
fakeEvent.currentTarget = target[0]; fakeEvent.currentTarget = target[ 0 ];
this.close( fakeEvent, true ); this.close( fakeEvent, true );
} }
} }
@ -395,7 +395,7 @@ $.widget( "ui.tooltip", {
tooltip.stop( true ); tooltip.stop( true );
this._hide( tooltip, this.options.hide, function() { this._hide( tooltip, this.options.hide, function() {
that._removeTooltip( $( this ) ); that._removeTooltip( $( this ) );
}); } );
target.removeData( "ui-tooltip-open" ); target.removeData( "ui-tooltip-open" );
this._off( target, "mouseleave focusout keyup" ); this._off( target, "mouseleave focusout keyup" );
@ -410,7 +410,7 @@ $.widget( "ui.tooltip", {
$.each( this.parents, function( id, parent ) { $.each( this.parents, function( id, parent ) {
$( parent.element ).attr( "title", parent.title ); $( parent.element ).attr( "title", parent.title );
delete that.parents[ id ]; delete that.parents[ id ];
}); } );
} }
tooltipData.closing = true; tooltipData.closing = true;
@ -428,7 +428,7 @@ $.widget( "ui.tooltip", {
this._addClass( content, "ui-tooltip-content" ); this._addClass( content, "ui-tooltip-content" );
this._addClass( tooltip, "ui-tooltip", "ui-widget ui-widget-content" ); this._addClass( tooltip, "ui-tooltip", "ui-widget ui-widget-content" );
tooltip.appendTo( this.document[0].body ); tooltip.appendTo( this.document[ 0 ].body );
return this.tooltips[ id ] = { return this.tooltips[ id ] = {
element: element, element: element,
@ -469,10 +469,10 @@ $.widget( "ui.tooltip", {
} }
element.removeData( "ui-tooltip-title" ); element.removeData( "ui-tooltip-title" );
} }
}); } );
this.liveRegion.remove(); this.liveRegion.remove();
} }
}); } );
// DEPRECATED // DEPRECATED
// TODO: Switch return back to widget declaration at top of file when this is removed // TODO: Switch return back to widget declaration at top of file when this is removed
@ -490,9 +490,9 @@ if ( $.uiBackCompat !== false ) {
} }
return tooltipData; return tooltipData;
} }
}); } );
} }
return $.ui.tooltip; return $.ui.tooltip;
})); } ) );