r734 - in trunk: tests ui

r734 - in trunk: tests ui


Author: david.bolter
Date: Mon Sep 22 08:47:41 2008
New Revision: 734
Modified:
trunk/tests/core.html
trunk/tests/core.js
trunk/ui/ui.core.js
trunk/ui/ui.dialog.js
Log:
Added ariaRole and ariaState to ui.core with tests.
Added ARIA role and state to ui.dialog
Fixes #3350
(Inspired by jARIA plugin from Chris Hoffman)
Modified: trunk/tests/core.html
==============================================================================
--- trunk/tests/core.html    (original)
+++ trunk/tests/core.html    Mon Sep 22 08:47:41 2008
@@ -65,6 +65,7 @@
        <input id="input4-3" tabindex="-1" />
        <input id="input4-4" tabindex="-50" />
    </div>
+    <div id="aria"></div>
</div>
</body>
Modified: trunk/tests/core.js
==============================================================================
--- trunk/tests/core.js    (original)
+++ trunk/tests/core.js    Mon Sep 22 08:47:41 2008
@@ -53,4 +53,19 @@
    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);
Modified: trunk/ui/ui.core.js
==============================================================================
--- trunk/ui/ui.core.js    (original)
+++ trunk/ui/ui.core.js    Mon Sep 22 08:47:41 2008
@@ -437,4 +437,31 @@
    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);
Modified: trunk/ui/ui.dialog.js
==============================================================================
--- trunk/ui/ui.dialog.js    (original)
+++ trunk/ui/ui.dialog.js    Mon Sep 22 08:47:41 2008
@@ -84,6 +84,8 @@
                    (options.closeOnEscape && ev.keyCode
                        && ev.keyCode == $.keyCode.ESCAPE && self.close());
                })
+                .ariaRole("dialog")
+                .ariaState("labelledby", titleId)
                .mousedown(function() {
                    self._moveToTop();
                }),