]> source.dussan.org Git - jquery-ui.git/commitdiff
Added ariaRole and ariaState to ui.core with tests.
authorDavid Bolter <david.bolter@gmail.com>
Mon, 22 Sep 2008 15:47:41 +0000 (15:47 +0000)
committerDavid Bolter <david.bolter@gmail.com>
Mon, 22 Sep 2008 15:47:41 +0000 (15:47 +0000)
Added ARIA role and state to ui.dialog
Fixes #3350
(Inspired by jARIA plugin from Chris Hoffman)

tests/core.html
tests/core.js
ui/ui.core.js
ui/ui.dialog.js

index 510d4f3a707285c8443f2d4916e2a97c4e3a7e16..5da16011ac12a8da13b1bb65180d866cf9c31982 100644 (file)
@@ -65,6 +65,7 @@
                <input id="input4-3" tabindex="-1" />
                <input id="input4-4" tabindex="-50" />
        </div>
+       <div id="aria"></div>
 </div>
 
 </body>
index 144c272655ff3f70cc126870dbcaa96ccf68b962..f9885e68467b564e09da9a9d5a62f31303525183 100644 (file)
@@ -53,4 +53,19 @@ test("tabbable - tabindex", function() {
        ok(!$('#input4-4').is(':tabbable'), 'input, tabindex -50');
 });
 
+test("aria", function() {
+       expect(10);
+       
+       ok(!$('#aria').attr('role'), 'role is empty via attr');
+       ok(!$('#aria').ariaRole(), 'role is empty via ariaRole');
+       equals($('#aria').ariaRole('dialog').attr('role').replace(/^wairole:/, ""), 'dialog', 'role is dialog');
+       equals($('#aria').ariaRole(), 'dialog', 'role is dialog');
+       equals($('#aria').ariaRole('tablist').attr('role').replace(/^wairole:/, ""), 'tablist', 'role is tablist via attr');
+       equals($('#aria').ariaRole(), 'tablist', 'role is tablist via ariaRole');
+       ok(!$('#aria').attr('expanded'), 'state expanded absent via attr');
+       ok(!$('#aria').ariaState('expanded'), 'state expanded absent via ariaState');
+       equals($('#aria').ariaState('expanded', 'true').ariaState('expanded'), 'true', 'aria expanded is true');
+       equals($('#aria').ariaState('expanded', 'false').ariaState('expanded'), 'false', 'aria expanded is false');
+});
+
 })(jQuery);
index 2cf48d11f02602ff93d4f6fd086ec5671e54343d..be0caa92048e6904833aa44f2432bf7c65cdf5ff 100644 (file)
@@ -437,4 +437,31 @@ $.ui.mouse.defaults = {
        delay: 0
 };
 
+
+// WAI-ARIA Semantics
+var isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9);
+$.fn.extend({
+       ariaRole : function(role) {
+               // setter?
+               if (role) {
+                       return this.each(function(i, el) {
+                               $(el).attr("role", isFF2 ? "wairole:" + role : role);
+                       });
+               }
+               // getter just returns first jquery member's role string
+               return (this.eq(0).attr("role") || "").replace(/^wairole:/, "");
+       },
+       
+       ariaState : function(state, value) {
+               // setter?
+               if (value) 
+                       return this.each(function(i, el) {
+                               isFF2? el.setAttributeNS("http://www.w3.org/2005/07/aaa", "aaa:" + state, value) :
+                                       $(el).attr("aria-" + state, value);
+                       });
+               // getter
+               return this.attr(isFF2? "aaa:"+state : "aria-" + state);
+       }
+});
+
 })(jQuery);
index c0a99494cae6cb64d601e327e96d810069b46513..c856af5ce1488164bd4645875ebb95fdddf22c6c 100644 (file)
@@ -84,6 +84,8 @@ $.widget("ui.dialog", {
                                        (options.closeOnEscape && ev.keyCode
                                                && ev.keyCode == $.keyCode.ESCAPE && self.close());
                                })
+                               .ariaRole("dialog")
+                               .ariaState("labelledby", titleId)
                                .mousedown(function() {
                                        self._moveToTop();
                                }),