r1050 - in branches/experimental/tabbable: . tests
Author: a.farkas.pm
Date: Sun Dec 7 12:38:06 2008
New Revision: 1050
Modified:
branches/experimental/tabbable/tests/core.html
branches/experimental/tabbable/tests/core.js
branches/experimental/tabbable/ui.core.js
Log:
added aria- labelWith and describeWith
Modified: branches/experimental/tabbable/tests/core.html
==============================================================================
--- branches/experimental/tabbable/tests/core.html (original)
+++ branches/experimental/tabbable/tests/core.html Sun Dec 7 12:38:06 2008
@@ -89,6 +89,14 @@
<a href="#" id="anchor6-4" tabindex="foo">anchor</a>
</div>
+
+ <div id="wrap7">
+ <div class="label-1"></div>
+ <div id="label-1"></div>
+ <div id="div7-1"></div>7
+ </div>
+
+
</div>
</body>
Modified: branches/experimental/tabbable/tests/core.js
==============================================================================
--- branches/experimental/tabbable/tests/core.js (original)
+++ branches/experimental/tabbable/tests/core.js Sun Dec 7 12:38:06 2008
@@ -138,9 +138,26 @@
expect(4);
ok(!$('#div6-1').is(':focusable'), 'div, without tabindex');
ok(!$('#div6-2').is(':focusable'), 'div, tabindex foo');
- //do we have to mess with this?
ok(!$('#div6-3').is(':focusable'), 'div, tabindex 3foo');
ok($('#anchor6-4').is(':focusable'), 'a, tabindex foo');
+});
+
+module("little label helper");
+test("label tests", function(){
+ expect(4);
+
+ $('#div7-1')
+ .labelWith('div.label-1');
+ var id = $('div.label-1').attr('id');
+
+ ok(id, 'add new id');
+ ok(($('#div7-1').attr('aria-labelledby') === id), 'labeld with added id');
+
+ $('#div7-1')
+ .labelWith('#label-1');
+
+ ok(($('#div7-1').attr('aria-labelledby') === 'label-1'), 'labeld with
existing id');
+ ok(($('#label-1').attr('id') === 'label-1'), 'existing id of label not
changed');
});
})(jQuery);
Modified: branches/experimental/tabbable/ui.core.js
==============================================================================
--- branches/experimental/tabbable/ui.core.js (original)
+++ branches/experimental/tabbable/ui.core.js Sun Dec 7 12:38:06 2008
@@ -37,7 +37,7 @@
}
});
-$.fn.setFocus = function() {
+$.fn.setFocus = function(time) {
var element = this[0];
if (element) {
@@ -47,10 +47,31 @@
setTimeout(function() {
element.focus();
- }, 1);
+ }, time || // sometimes a higher timeout is needed, to allow
screenreader to update the outputbuffer
+ 1);
}
-
return this;
+};
+
+//labelledby and describedby
+function getID(label){
+ label = $(label);
+ var id = label.attr('id');
+ if(!id){
+ id = 'labelID-'+ new Date().getTime();
+ label.attr({'id': id});
+ }
+ return id;
+}
+
+$.fn.labelWith = function(label) {
+ var id = getID(label);
+ return this.attr({'aria-labelledby': id});
+};
+
+$.fn.describeWith = function(label) {
+ var id = getID(label);
+ return this.attr({'aria-describedby': id});
};
})(jQuery);