Permalink
Browse files

MDL-30833 Accessibility: Added aria-expanded attribute on navigation …

…nodes
  • Loading branch information...
1 parent 32efb09 commit 9ac00a5394ab2973e36235bdf2fa69dee6a05f94 @rajeshtaneja rajeshtaneja committed Sep 11, 2012
Showing with 12 additions and 2 deletions.
  1. +3 −1 blocks/navigation/renderer.php
  2. +6 −0 blocks/navigation/yui/navigation/navigation.js
  3. +3 −1 blocks/settings/renderer.php
View
4 blocks/navigation/renderer.php
@@ -121,18 +121,20 @@ protected function navigation_node($items, $attrs=array(), $expansionlimit=null,
// this applies to the li item which contains all child lists too
$liclasses = array($item->get_css_type(), 'depth_'.$depth);
+ $liexpandable = array();
if ($item->has_children() && (!$item->forceopen || $item->collapse)) {
$liclasses[] = 'collapsed';
}
if ($isbranch) {
$liclasses[] = 'contains_branch';
+ $liexpandable = array('aria-expanded' => in_array('collapsed', $liclasses) ? "false" : "true");
} else if ($hasicon) {
$liclasses[] = 'item_with_icon';
}
if ($item->isactive === true) {
$liclasses[] = 'current_branch';
}
- $liattr = array('class'=>join(' ',$liclasses));
+ $liattr = array('class' => join(' ',$liclasses)) + $liexpandable;
// class attribute on the div item which only contains the item content
$divclasses = array('tree_item');
if ($isbranch) {
View
6 blocks/navigation/yui/navigation/navigation.js
@@ -162,16 +162,20 @@ TREE.prototype = {
switch (e.action) {
case 'expand' :
target.removeClass('collapsed');
+ target.set('aria-expanded', true);
break;
case 'collapse' :
target.addClass('collapsed');
+ target.set('aria-expanded', false);
break;
default :
target.toggleClass('collapsed');
+ target.set('aria-expanded', !target.hasClass('collapsed'));
}
e.halt();
} else {
target.toggleClass('collapsed');
+ target.set('aria-expanded', !target.hasClass('collapsed'));
}
}
@@ -180,6 +184,7 @@ TREE.prototype = {
target.siblings('li').each(function(){
if (this.get('id') !== target.get('id') && !this.hasClass('collapsed')) {
this.addClass('collapsed');
+ this.set('aria-expanded', false);
}
});
}
@@ -287,6 +292,7 @@ BRANCH.prototype = {
}
if (isbranch) {
branchli.addClass('collapsed').addClass('contains_branch');
+ branchli.set('aria-expanded', false);
branchp.addClass('branch');
}
View
4 blocks/settings/renderer.php
@@ -40,18 +40,20 @@ protected function navigation_node(navigation_node $node, $attrs=array()) {
// this applies to the li item which contains all child lists too
$liclasses = array($item->get_css_type());
+ $liexpandable = array();
if (!$item->forceopen || (!$item->forceopen && $item->collapse) || ($item->children->count()==0 && $item->nodetype==navigation_node::NODETYPE_BRANCH)) {
$liclasses[] = 'collapsed';
}
if ($isbranch) {
$liclasses[] = 'contains_branch';
+ $liexpandable = array('aria-expanded' => in_array('collapsed', $liclasses) ? "false" : "true");
} else if ($hasicon) {
$liclasses[] = 'item_with_icon';
}
if ($item->isactive === true) {
$liclasses[] = 'current_branch';
}
- $liattr = array('class'=>join(' ',$liclasses));
+ $liattr = array('class' => join(' ',$liclasses)) + $liexpandable;
// class attribute on the div item which only contains the item content
$divclasses = array('tree_item');
if ($isbranch) {

0 comments on commit 9ac00a5

Please sign in to comment.