diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-05-22 11:06:44 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-05-22 11:06:44 -0400 |
commit | b6cc9dd870836b94d6f82729d56e592c548f24ea (patch) | |
tree | 2731c6661089fb3a7b723ede7601d12861403c3b /ui | |
parent | d7359beee6f8103e997959efd4f070245e9d3225 (diff) | |
download | jquery-ui-b6cc9dd870836b94d6f82729d56e592c548f24ea.tar.gz jquery-ui-b6cc9dd870836b94d6f82729d56e592c548f24ea.zip |
Tooltip: Handle multiple aria-describedby values.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.tooltip.js | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/ui/jquery.ui.tooltip.js b/ui/jquery.ui.tooltip.js index 47a377bfd..1d6cd32a8 100644 --- a/ui/jquery.ui.tooltip.js +++ b/ui/jquery.ui.tooltip.js @@ -14,6 +14,31 @@ 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: { @@ -93,7 +118,7 @@ $.widget( "ui.tooltip", { .closest( this.options.items ); // if aria-describedby exists, then the tooltip is already open - if ( !target.length || target.attr( "aria-describedby" ) ) { + if ( !target.length || target.data( "ui-tooltip-id" ) ) { return; } @@ -143,7 +168,7 @@ $.widget( "ui.tooltip", { var tooltip = this._find( target ); if ( !tooltip.length ) { tooltip = this._tooltip( target ); - target.attr( "aria-describedby", tooltip.attr( "id" ) ); + addDescribedBy( target, tooltip.attr( "id" ) ); } tooltip.find( ".ui-tooltip-content" ).html( content ); tooltip @@ -195,7 +220,7 @@ $.widget( "ui.tooltip", { target.attr( "title", target.data( "ui-tooltip-title" ) ); } - target.removeAttr( "aria-describedby" ); + removeDescribedBy( target ); tooltip.stop( true ); this._hide( tooltip, this.options.hide, function() { @@ -232,7 +257,7 @@ $.widget( "ui.tooltip", { }, _find: function( target ) { - var id = target.attr( "aria-describedby" ); + var id = target.data( "ui-tooltip-id" ); return id ? $( "#" + id ) : $(); }, |