Skip to content

Commit b8fcc39

Browse files
committed
Merge branch 'master' into tabs-aria
2 parents 2c60638 + f5954fc commit b8fcc39

File tree

9 files changed

+74
-43
lines changed

9 files changed

+74
-43
lines changed

tests/unit/core/core.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,14 @@ test( "outerHeight(true) - setter", function() {
153153
equal( el.height(), 32, "height set properly when hidden" );
154154
});
155155

156+
test( "uniqueId / removeUniqueId", function() {
157+
var el = $( "img" ).eq( 0 );
158+
159+
equal( el.attr( "id" ), undefined, "element has no initial id" );
160+
el.uniqueId();
161+
ok( /ui-id-\d+$/.test( el.attr( "id" ) ), "element has generated id" );
162+
el.removeUniqueId();
163+
equal( el.attr( "id" ), undefined, "unique id has been removed from element" );
164+
});
165+
156166
})( jQuery );

tests/unit/dialog/dialog_core.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,11 @@ function margin(el, side) {
8989
module("dialog: core");
9090

9191
test("title id", function() {
92-
expect(3);
93-
94-
var titleId;
95-
96-
// reset the uuid so we know what values to expect
97-
$.ui.dialog.uuid = 0;
92+
expect(1);
9893

9994
el = $('<div></div>').dialog();
100-
titleId = dlg().find('.ui-dialog-title').attr('id');
101-
equal(titleId, 'ui-dialog-title-1', 'auto-numbered title id');
102-
el.remove();
103-
104-
el = $('<div></div>').dialog();
105-
titleId = dlg().find('.ui-dialog-title').attr('id');
106-
equal(titleId, 'ui-dialog-title-2', 'auto-numbered title id');
107-
el.remove();
108-
109-
el = $('<div id="foo">').dialog();
110-
titleId = dlg().find('.ui-dialog-title').attr('id');
111-
equal(titleId, 'ui-dialog-title-foo', 'carried over title id');
95+
var titleId = dlg().find('.ui-dialog-title').attr('id');
96+
ok( /ui-id-\d+$/.test( titleId ), 'auto-numbered title id');
11297
el.remove();
11398
});
11499

tests/unit/menu/menu.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ <h2 id="qunit-userAgent"></h2>
5555
<li class="foo"><a class="foo" href="#">Aberdeen</a></li>
5656
<li class="foo"><a class="foo" href="#">Ada</a></li>
5757
<li class="foo"><a class="foo" href="#">Adamsville</a></li>
58-
<li class="foo"><a class="foo" href="#">Addyston</a></li>
58+
<li class="foo"><a id="testID1" class="foo" href="#">Addyston</a></li>
5959
<li class="foo"><a class="foo" href="#">Adelphi</a></li>
6060
</ul>
6161

@@ -235,7 +235,7 @@ <h2 id="qunit-userAgent"></h2>
235235
<a href="#">Delphi</a>
236236
<div>
237237
<blockquote><a href="#">Ada</a></blockquote>
238-
<blockquote><a href="#">Saarland</a></blockquote>
238+
<blockquote><a id="testID2" href="#">Saarland</a></blockquote>
239239
<blockquote><a href="#">Salzburg</a></blockquote>
240240
</div>
241241
</blockquote>
@@ -258,7 +258,7 @@ <h2 id="qunit-userAgent"></h2>
258258
<li class="foo"><a class="foo" href="#">Adamsville</a></li>
259259
<li class="foo"><a class="foo" href="#">Addyston</a></li>
260260
<li class="ui-state-disabled">
261-
<a href="#">Delphi</a>
261+
<a id="testID3" href="#">Delphi</a>
262262
<ul>
263263
<li class="foo"><a class="foo" href="#">Ada</a></li>
264264
<li class="foo"><a class="foo" href="#">Saarland</a></li>

tests/unit/menu/menu_core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test("accessibility", function () {
2323

2424
item = menu.find( "li:last" );
2525
menu.menu( "focus", $.Event(), item );
26-
equal( menu.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id");
26+
ok( /^ui-id-\d+$/.test( menu.attr( "aria-activedescendant" ) ), "aria attribute, generated id");
2727
});
2828

2929
})(jQuery);

tests/unit/testsuite.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,16 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
138138
/*
139139
* Experimental assertion for comparing DOM objects.
140140
*
141-
* Serializes an element and some properties and it's children if any, otherwise the text.
141+
* Serializes an element and some properties and attributes and it's children if any, otherwise the text.
142142
* Then compares the result using deepEqual.
143143
*/
144144
window.domEqual = function( selector, modifier, message ) {
145145
var expected, actual,
146146
properties = [
147+
"disabled",
148+
"readOnly"
149+
],
150+
attributes = [
147151
"autocomplete",
148152
"aria-activedescendant",
149153
"aria-controls",
@@ -159,11 +163,9 @@ window.domEqual = function( selector, modifier, message ) {
159163
"aria-valuemin",
160164
"aria-valuenow",
161165
"class",
162-
"disabled",
163166
"href",
164167
"id",
165168
"nodeName",
166-
"readOnly",
167169
"role",
168170
"tabIndex",
169171
"title"
@@ -179,7 +181,12 @@ window.domEqual = function( selector, modifier, message ) {
179181
var children,
180182
result = {};
181183
$.each( properties, function( index, attr ) {
182-
result[ attr ] = elem.prop( attr );
184+
var value = elem.prop( attr );
185+
result[ attr ] = value !== undefined ? value : "";
186+
});
187+
$.each( attributes, function( index, attr ) {
188+
var value = elem.attr( attr );
189+
result[ attr ] = value !== undefined ? value : "";
183190
});
184191
children = elem.children();
185192
if ( children.length ) {

ui/jquery.ui.core.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
(function( $, undefined ) {
1111

12+
var uuid = 0,
13+
runiqueId = /^ui-id-\d+$/;
14+
1215
// prevent duplicate loading
1316
// this is only a problem because we proxy existing functions
1417
// and we don't want to double proxy them
@@ -107,6 +110,22 @@ $.fn.extend({
107110
return 0;
108111
},
109112

113+
uniqueId: function() {
114+
return this.each(function() {
115+
if ( !this.id ) {
116+
this.id = "ui-id-" + (++uuid);
117+
}
118+
});
119+
},
120+
121+
removeUniqueId: function() {
122+
return this.each(function() {
123+
if ( runiqueId.test( this.id ) ) {
124+
$( this ).removeAttr( "id" );
125+
}
126+
});
127+
},
128+
110129
disableSelection: function() {
111130
return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
112131
".ui-disableSelection", function( event ) {

ui/jquery.ui.dialog.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ $.widget("ui.dialog", {
8787
options = this.options,
8888

8989
title = options.title || "&#160;",
90-
titleId = $.ui.dialog.getTitleId( this.element ),
9190

9291
uiDialog = ( this.uiDialog = $( "<div>" ) )
9392
.addClass( uiDialogClasses + options.dialogClass )
@@ -105,10 +104,6 @@ $.widget("ui.dialog", {
105104
event.preventDefault();
106105
}
107106
})
108-
.attr({
109-
role: "dialog",
110-
"aria-labelledby": titleId
111-
})
112107
.mousedown(function( event ) {
113108
that.moveToTop( false, event );
114109
})
@@ -140,8 +135,8 @@ $.widget("ui.dialog", {
140135
.appendTo( uiDialogTitlebarClose ),
141136

142137
uiDialogTitle = $( "<span>" )
138+
.uniqueId()
143139
.addClass( "ui-dialog-title" )
144-
.attr( "id", titleId )
145140
.html( title )
146141
.prependTo( uiDialogTitlebar ),
147142

@@ -152,6 +147,11 @@ $.widget("ui.dialog", {
152147
.addClass( "ui-dialog-buttonset" )
153148
.appendTo( uiDialogButtonPane );
154149

150+
uiDialog.attr({
151+
role: "dialog",
152+
"aria-labelledby": uiDialogTitle.attr( "id" )
153+
});
154+
155155
uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();
156156
this._hoverable( uiDialogTitlebarClose );
157157
this._focusable( uiDialogTitlebarClose );

ui/jquery.ui.menu.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
*/
1414
(function($) {
1515

16-
var idIncrement = 0,
17-
currentEventTarget = null;
16+
var currentEventTarget = null;
1817

1918
$.widget( "ui.menu", {
2019
version: "@VERSION",
@@ -35,12 +34,11 @@ $.widget( "ui.menu", {
3534
},
3635
_create: function() {
3736
this.activeMenu = this.element;
38-
this.menuId = this.element.attr( "id" ) || "ui-menu-" + idIncrement++;
3937
this.element
38+
.uniqueId()
4039
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
4140
.toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length )
4241
.attr({
43-
id: this.menuId,
4442
role: this.options.role,
4543
tabIndex: 0
4644
})
@@ -145,18 +143,21 @@ $.widget( "ui.menu", {
145143
.removeAttr( "aria-labelledby" )
146144
.removeAttr( "aria-expanded" )
147145
.removeAttr( "aria-hidden" )
146+
.removeAttr( "aria-disabled" )
147+
.removeUniqueId()
148148
.show();
149149

150150
// destroy menu items
151151
this.element.find( ".ui-menu-item" )
152152
.removeClass( "ui-menu-item" )
153153
.removeAttr( "role" )
154+
.removeAttr( "aria-disabled" )
154155
.children( "a" )
156+
.removeUniqueId()
155157
.removeClass( "ui-corner-all ui-state-hover" )
156158
.removeAttr( "tabIndex" )
157159
.removeAttr( "role" )
158160
.removeAttr( "aria-haspopup" )
159-
.removeAttr( "id" )
160161
// TODO: is this correct? Don't these exist in the original markup?
161162
.children( ".ui-icon" )
162163
.remove();
@@ -273,7 +274,6 @@ $.widget( "ui.menu", {
273274
refresh: function() {
274275
// initialize nested menus
275276
var menus,
276-
menuId = this.menuId,
277277
submenus = this.element.find( this.options.menus + ":not(.ui-menu)" )
278278
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
279279
.hide()
@@ -290,13 +290,11 @@ $.widget( "ui.menu", {
290290
.addClass( "ui-menu-item" )
291291
.attr( "role", "presentation" )
292292
.children( "a" )
293+
.uniqueId()
293294
.addClass( "ui-corner-all" )
294295
.attr({
295296
tabIndex: -1,
296-
role: this._itemRole(),
297-
id: function( i ) {
298-
return menuId + "-" + i;
299-
}
297+
role: this._itemRole()
300298
});
301299

302300
// initialize unlinked menu-items containing spaces and/or dashes only as dividers

ui/jquery.ui.tabs.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ $.widget( "ui.tabs", {
345345
if ( panel.length) {
346346
that.panels = that.panels.add( panel );
347347
}
348-
tab.attr( "aria-controls", selector.substring( 1 ) );
348+
tab
349+
.data( "ui-tabs-aria-controls", tab.attr( "aria-controls" ) )
350+
.attr( "aria-controls", selector.substring( 1 ) );
349351
});
350352

351353
this.panels
@@ -634,6 +636,16 @@ $.widget( "ui.tabs", {
634636
}
635637
});
636638

639+
this.lis.each(function() {
640+
var li = $( this ),
641+
prev = li.data( "ui-tabs-aria-controls" );
642+
if ( prev ) {
643+
li.attr( "aria-controls", prev );
644+
} else {
645+
li.removeAttr( "aria-controls" );
646+
}
647+
});
648+
637649
if ( this.options.heightStyle !== "content" ) {
638650
this.panels.css( "height", "" );
639651
}

0 commit comments

Comments
 (0)