Skip to content
Permalink
Browse files

Tooltip: Use .uniqueId() and move aria-describedby helper methods int…

…o the widget prototype.
  • Loading branch information...
scottgonzalez committed Sep 17, 2013
1 parent 10b383b commit 3103ba1ba4a7606f582df52fd76c948e689fcca5
Showing with 34 additions and 36 deletions.
  1. +34 −36 ui/jquery.ui.tooltip.js
@@ -15,33 +15,6 @@
*/
(function( $ ) {

var increments = 0;

function addDescribedBy( elem, id ) {
var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ );
describedby.push( id );
elem
.data( "ui-tooltip-id", id )
.attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
}

function removeDescribedBy( elem ) {
var id = elem.data( "ui-tooltip-id" ),
describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ),
index = $.inArray( id, describedby );
if ( index !== -1 ) {
describedby.splice( index, 1 );
}

elem.removeData( "ui-tooltip-id" );
describedby = $.trim( describedby.join( " " ) );
if ( describedby ) {
elem.attr( "aria-describedby", describedby );
} else {
elem.removeAttr( "aria-describedby" );
}
}

$.widget( "ui.tooltip", {
version: "@VERSION",
options: {
@@ -69,6 +42,32 @@ $.widget( "ui.tooltip", {
open: null
},

_addDescribedBy: function( elem, id ) {
var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ );
describedby.push( id );
elem
.data( "ui-tooltip-id", id )
.attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
},

_removeDescribedBy: function( elem ) {
var id = elem.data( "ui-tooltip-id" ),
describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ),
index = $.inArray( id, describedby );

if ( index !== -1 ) {
describedby.splice( index, 1 );
}

elem.removeData( "ui-tooltip-id" );
describedby = $.trim( describedby.join( " " ) );
if ( describedby ) {
elem.attr( "aria-describedby", describedby );
} else {
elem.removeAttr( "aria-describedby" );
}
},

_create: function() {
this._on({
mouseover: "open",
@@ -243,7 +242,7 @@ $.widget( "ui.tooltip", {
}

tooltip = this._tooltip( target );
addDescribedBy( target, tooltip.attr( "id" ) );
this._addDescribedBy( target, tooltip.attr( "id" ) );
tooltip.find( ".ui-tooltip-content" ).html( content );

function position( event ) {
@@ -322,7 +321,7 @@ $.widget( "ui.tooltip", {
target.attr( "title", target.data( "ui-tooltip-title" ) );
}

removeDescribedBy( target );
this._removeDescribedBy( target );

tooltip.stop( true );
this._hide( tooltip, this.options.hide, function() {
@@ -350,17 +349,16 @@ $.widget( "ui.tooltip", {
},

_tooltip: function( element ) {
var id = "ui-tooltip-" + increments++,
tooltip = $( "<div>" )
.attr({
id: id,
role: "tooltip"
})
var tooltip = $( "<div>" )
.attr( "role", "tooltip" )
.addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " +
( this.options.tooltipClass || "" ) );
( this.options.tooltipClass || "" ) ),
id = tooltip.uniqueId().attr( "id" );

$( "<div>" )
.addClass( "ui-tooltip-content" )
.appendTo( tooltip );

tooltip.appendTo( this.document[0].body );
this.tooltips[ id ] = element;
return tooltip;

0 comments on commit 3103ba1

Please sign in to comment.
You can’t perform that action at this time.