|
15 | 15 | */ |
16 | 16 | (function( $ ) { |
17 | 17 |
|
18 | | -var increments = 0; |
19 | | - |
20 | | -function addDescribedBy( elem, id ) { |
21 | | - var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ); |
22 | | - describedby.push( id ); |
23 | | - elem |
24 | | - .data( "ui-tooltip-id", id ) |
25 | | - .attr( "aria-describedby", $.trim( describedby.join( " " ) ) ); |
26 | | -} |
27 | | - |
28 | | -function removeDescribedBy( elem ) { |
29 | | - var id = elem.data( "ui-tooltip-id" ), |
30 | | - describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ), |
31 | | - index = $.inArray( id, describedby ); |
32 | | - if ( index !== -1 ) { |
33 | | - describedby.splice( index, 1 ); |
34 | | - } |
35 | | - |
36 | | - elem.removeData( "ui-tooltip-id" ); |
37 | | - describedby = $.trim( describedby.join( " " ) ); |
38 | | - if ( describedby ) { |
39 | | - elem.attr( "aria-describedby", describedby ); |
40 | | - } else { |
41 | | - elem.removeAttr( "aria-describedby" ); |
42 | | - } |
43 | | -} |
44 | | - |
45 | 18 | $.widget( "ui.tooltip", { |
46 | 19 | version: "@VERSION", |
47 | 20 | options: { |
@@ -69,6 +42,32 @@ $.widget( "ui.tooltip", { |
69 | 42 | open: null |
70 | 43 | }, |
71 | 44 |
|
| 45 | + _addDescribedBy: function( elem, id ) { |
| 46 | + var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ); |
| 47 | + describedby.push( id ); |
| 48 | + elem |
| 49 | + .data( "ui-tooltip-id", id ) |
| 50 | + .attr( "aria-describedby", $.trim( describedby.join( " " ) ) ); |
| 51 | + }, |
| 52 | + |
| 53 | + _removeDescribedBy: function( elem ) { |
| 54 | + var id = elem.data( "ui-tooltip-id" ), |
| 55 | + describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ), |
| 56 | + index = $.inArray( id, describedby ); |
| 57 | + |
| 58 | + if ( index !== -1 ) { |
| 59 | + describedby.splice( index, 1 ); |
| 60 | + } |
| 61 | + |
| 62 | + elem.removeData( "ui-tooltip-id" ); |
| 63 | + describedby = $.trim( describedby.join( " " ) ); |
| 64 | + if ( describedby ) { |
| 65 | + elem.attr( "aria-describedby", describedby ); |
| 66 | + } else { |
| 67 | + elem.removeAttr( "aria-describedby" ); |
| 68 | + } |
| 69 | + }, |
| 70 | + |
72 | 71 | _create: function() { |
73 | 72 | this._on({ |
74 | 73 | mouseover: "open", |
@@ -243,7 +242,7 @@ $.widget( "ui.tooltip", { |
243 | 242 | } |
244 | 243 |
|
245 | 244 | tooltip = this._tooltip( target ); |
246 | | - addDescribedBy( target, tooltip.attr( "id" ) ); |
| 245 | + this._addDescribedBy( target, tooltip.attr( "id" ) ); |
247 | 246 | tooltip.find( ".ui-tooltip-content" ).html( content ); |
248 | 247 |
|
249 | 248 | function position( event ) { |
@@ -322,7 +321,7 @@ $.widget( "ui.tooltip", { |
322 | 321 | target.attr( "title", target.data( "ui-tooltip-title" ) ); |
323 | 322 | } |
324 | 323 |
|
325 | | - removeDescribedBy( target ); |
| 324 | + this._removeDescribedBy( target ); |
326 | 325 |
|
327 | 326 | tooltip.stop( true ); |
328 | 327 | this._hide( tooltip, this.options.hide, function() { |
@@ -350,17 +349,16 @@ $.widget( "ui.tooltip", { |
350 | 349 | }, |
351 | 350 |
|
352 | 351 | _tooltip: function( element ) { |
353 | | - var id = "ui-tooltip-" + increments++, |
354 | | - tooltip = $( "<div>" ) |
355 | | - .attr({ |
356 | | - id: id, |
357 | | - role: "tooltip" |
358 | | - }) |
| 352 | + var tooltip = $( "<div>" ) |
| 353 | + .attr( "role", "tooltip" ) |
359 | 354 | .addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " + |
360 | | - ( this.options.tooltipClass || "" ) ); |
| 355 | + ( this.options.tooltipClass || "" ) ), |
| 356 | + id = tooltip.uniqueId().attr( "id" ); |
| 357 | + |
361 | 358 | $( "<div>" ) |
362 | 359 | .addClass( "ui-tooltip-content" ) |
363 | 360 | .appendTo( tooltip ); |
| 361 | + |
364 | 362 | tooltip.appendTo( this.document[0].body ); |
365 | 363 | this.tooltips[ id ] = element; |
366 | 364 | return tooltip; |
|
0 commit comments