Merge branch 'wip-MDL-30921-m24' of git://github.com/samhemelryk/moodle

This commit is contained in:
Dan Poltawski 2012-11-07 10:51:06 +08:00
commit e830d6f98e
11 changed files with 119 additions and 6 deletions

View file

@ -64,6 +64,17 @@ class block_activity_modules extends block_list {
return $this->content; return $this->content;
} }
/**
* Returns the role that best describes this blocks contents.
*
* This returns 'navigation' as the blocks contents is a list of links to activities and resources.
*
* @return string 'navigation'
*/
public function get_aria_role() {
return 'navigation';
}
function applicable_formats() { function applicable_formats() {
return array('all' => true, 'mod' => false, 'my' => false, 'admin' => false, return array('all' => true, 'mod' => false, 'my' => false, 'admin' => false,
'tag' => false); 'tag' => false);

View file

@ -126,6 +126,15 @@ class block_admin_bookmarks extends block_base {
return $this->content; return $this->content;
} }
/**
* Returns the role that best describes the admin bookmarks block.
*
* @return string
*/
public function get_aria_role() {
return 'navigation';
}
} }

View file

@ -112,4 +112,13 @@ class block_blog_menu extends block_base {
// Return the content object // Return the content object
return $this->content; return $this->content;
} }
/**
* Returns the role that best describes the blog menu block.
*
* @return string
*/
public function get_aria_role() {
return 'navigation';
}
} }

View file

@ -142,6 +142,14 @@ class block_course_list extends block_list {
return false; return false;
} }
/**
* Returns the role that best describes the course list block.
*
* @return string
*/
public function get_aria_role() {
return 'navigation';
}
} }

View file

@ -240,6 +240,9 @@ class block_base {
if (!$this->hide_header()) { if (!$this->hide_header()) {
$bc->title = $this->title; $bc->title = $this->title;
} }
if (empty($bc->title)) {
$bc->arialabel = new lang_string('pluginname', get_class($this));
}
if ($this->page->user_is_editing()) { if ($this->page->user_is_editing()) {
$bc->controls = $this->page->blocks->edit_controls($this); $bc->controls = $this->page->blocks->edit_controls($this);
@ -398,7 +401,8 @@ class block_base {
function html_attributes() { function html_attributes() {
$attributes = array( $attributes = array(
'id' => 'inst' . $this->instance->id, 'id' => 'inst' . $this->instance->id,
'class' => 'block_' . $this->name(). ' block' 'class' => 'block_' . $this->name(). ' block',
'role' => $this->get_aria_role()
); );
if ($this->instance_can_be_docked() && get_user_preferences('docked_block_instance_'.$this->instance->id, 0)) { if ($this->instance_can_be_docked() && get_user_preferences('docked_block_instance_'.$this->instance->id, 0)) {
$attributes['class'] .= ' dock_on_load'; $attributes['class'] .= ' dock_on_load';
@ -700,6 +704,29 @@ EOD;
public static function comment_add(&$comments, $options) { public static function comment_add(&$comments, $options) {
return true; return true;
} }
/**
* Returns the aria role attribute that best describes this block.
*
* Region is the default, but this should be overridden by a block is there is a region child, or even better
* a landmark child.
*
* Options are as follows:
* - landmark
* - application
* - banner
* - complementary
* - contentinfo
* - form
* - main
* - navigation
* - search
*
* @return string
*/
public function get_aria_role() {
return 'complementary';
}
} }
/** /**

View file

@ -325,4 +325,13 @@ class block_navigation extends block_base {
$string = $start.'...'.$end; $string = $start.'...'.$end;
return $string; return $string;
} }
/**
* Returns the role that best describes the navigation block... 'navigation'
*
* @return string 'navigation'
*/
public function get_aria_role() {
return 'navigation';
}
} }

View file

@ -42,6 +42,15 @@ class block_search_forums extends block_base {
function applicable_formats() { function applicable_formats() {
return array('site' => true, 'course' => true); return array('site' => true, 'course' => true);
} }
/**
* Returns the role that best describes the forum search block.
*
* @return string
*/
public function get_aria_role() {
return 'search';
}
} }

View file

@ -148,4 +148,13 @@ class block_settings extends block_base {
$this->contentgenerated = true; $this->contentgenerated = true;
return true; return true;
} }
/**
* Returns the role that best describes the settings block.
*
* @return string 'navigation'
*/
public function get_aria_role() {
return 'navigation';
}
} }

View file

@ -84,7 +84,7 @@ class block_settings_renderer extends plugin_renderer_base {
} }
public function search_form(moodle_url $formtarget, $searchvalue) { public function search_form(moodle_url $formtarget, $searchvalue) {
$content = html_writer::start_tag('form', array('class'=>'adminsearchform', 'method'=>'get', 'action'=>$formtarget)); $content = html_writer::start_tag('form', array('class'=>'adminsearchform', 'method'=>'get', 'action'=>$formtarget, 'role' => 'search'));
$content .= html_writer::start_tag('div'); $content .= html_writer::start_tag('div');
$content .= html_writer::tag('label', s(get_string('searchinsettings', 'admin')), array('for'=>'adminsearchquery', 'class'=>'accesshide')); $content .= html_writer::tag('label', s(get_string('searchinsettings', 'admin')), array('for'=>'adminsearchquery', 'class'=>'accesshide'));
$content .= html_writer::empty_tag('input', array('id'=>'adminsearchquery', 'type'=>'text', 'name'=>'query', 'value'=>s($searchvalue))); $content .= html_writer::empty_tag('input', array('id'=>'adminsearchquery', 'type'=>'text', 'name'=>'query', 'value'=>s($searchvalue)));

View file

@ -2378,6 +2378,12 @@ class block_contents {
*/ */
public $title = ''; public $title = '';
/**
* @var string The label to use when the block does not, or will not have a visible title.
* You should never set this as well as title... it will just be ignored.
*/
public $arialabel = '';
/** /**
* @var string HTML for the content * @var string HTML for the content
*/ */

View file

@ -492,7 +492,13 @@ class core_renderer extends renderer_base {
* @return string HTML fragment. * @return string HTML fragment.
*/ */
public function main_content() { public function main_content() {
return $this->unique_main_content_token; // This is here because it is the only place we can inject the "main" role over the entire main content area
// without requiring all theme's to manually do it, and without creating yet another thing people need to
// remember in the theme.
// This is an unfortunate hack. DO NO EVER add anything more here.
// DO NOT add classes.
// DO NOT add an id.
return '<div role="main">'.$this->unique_main_content_token.'</div>';
} }
/** /**
@ -914,6 +920,12 @@ class core_renderer extends renderer_base {
if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) { if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
$bc->collapsible = block_contents::NOT_HIDEABLE; $bc->collapsible = block_contents::NOT_HIDEABLE;
} }
$skiptitle = strip_tags($bc->title);
if ($bc->blockinstanceid && !empty($skiptitle)) {
$bc->attributes['aria-labelledby'] = 'instance-'.$bc->blockinstanceid.'-header';
} else if (!empty($bc->arialabel)) {
$bc->attributes['aria-label'] = $bc->arialabel;
}
if ($bc->collapsible == block_contents::HIDDEN) { if ($bc->collapsible == block_contents::HIDDEN) {
$bc->add_class('hidden'); $bc->add_class('hidden');
} }
@ -921,7 +933,7 @@ class core_renderer extends renderer_base {
$bc->add_class('block_with_controls'); $bc->add_class('block_with_controls');
} }
$skiptitle = strip_tags($bc->title);
if (empty($skiptitle)) { if (empty($skiptitle)) {
$output = ''; $output = '';
$skipdest = ''; $skipdest = '';
@ -955,7 +967,11 @@ class core_renderer extends renderer_base {
$title = ''; $title = '';
if ($bc->title) { if ($bc->title) {
$title = html_writer::tag('h2', $bc->title, null); $attributes = array();
if ($bc->blockinstanceid) {
$attributes['id'] = 'instance-'.$bc->blockinstanceid.'-header';
}
$title = html_writer::tag('h2', $bc->title, $attributes);
} }
$controlshtml = $this->block_controls($bc->controls); $controlshtml = $this->block_controls($bc->controls);
@ -2520,7 +2536,7 @@ EOD;
//accessibility: heading for navbar list (MDL-20446) //accessibility: heading for navbar list (MDL-20446)
$navbarcontent = html_writer::tag('span', get_string('pagepath'), array('class'=>'accesshide')); $navbarcontent = html_writer::tag('span', get_string('pagepath'), array('class'=>'accesshide'));
$navbarcontent .= html_writer::tag('ul', join('', $htmlblocks)); $navbarcontent .= html_writer::tag('ul', join('', $htmlblocks), array('role'=>'navigation'));
// XHTML // XHTML
return $navbarcontent; return $navbarcontent;
} }