Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-30883 question flags: aria attributes for accessibility

Also, update code to use html_writer.

Conflicts:

	theme/base/style/question.css
  • Loading branch information...
commit bd874d2a0e8c31f7d8df7f776eeac554df47f048 1 parent 3546266
Tim Hunt timhunt authored

Showing 1 changed file with 33 additions and 17 deletions. Show diff stats Hide diff stats

  1. +33 17 question/engine/renderer.php
50 question/engine/renderer.php
@@ -207,36 +207,52 @@ protected function mark_summary(question_attempt $qa, question_display_options $
207 207 */
208 208 protected function question_flag(question_attempt $qa, $flagsoption) {
209 209 global $CFG;
  210 +
  211 + $divattributes = array('class' => 'questionflag');
  212 +
210 213 switch ($flagsoption) {
211 214 case question_display_options::VISIBLE:
212 215 $flagcontent = $this->get_flag_html($qa->is_flagged());
213 216 break;
  217 +
214 218 case question_display_options::EDITABLE:
215 219 $id = $qa->get_flag_field_name();
216   - if ($qa->is_flagged()) {
217   - $checked = 'checked="checked" ';
218   - } else {
219   - $checked = '';
220   - }
221   - $postdata = question_flags::get_postdata($qa);
222 220 // The checkbox id must be different from any element name, because
223 221 // of a stupid IE bug:
224 222 // http://www.456bereastreet.com/archive/200802/beware_of_id_and_name_attribute_mixups_when_using_getelementbyid_in_internet_explorer/
225   - $flagcontent = '<input type="hidden" name="' . $id . '" value="0" />' .
226   - '<input type="checkbox" id="' . $id . 'checkbox" name="' . $id .
227   - '" value="1" ' . $checked . ' />' .
228   - '<input type="hidden" value="' . s($postdata) .
229   - '" class="questionflagpostdata" />' .
230   - '<label id="' . $id . 'label" for="' . $id . 'checkbox">' .
231   - $this->get_flag_html($qa->is_flagged(), $id . 'img') .
232   - '</label>' . "\n";
  223 + $checkboxattributes = array(
  224 + 'type' => 'checkbox',
  225 + 'id' => $id . 'checkbox',
  226 + 'name' => $id,
  227 + 'value' => 1,
  228 + );
  229 + if ($qa->is_flagged()) {
  230 + $checkboxattributes['checked'] = 'checked';
  231 + }
  232 + $postdata = question_flags::get_postdata($qa);
  233 +
  234 + $flagcontent = html_writer::empty_tag('input',
  235 + array('type' => 'hidden', 'name' => $id, 'value' => 0)) .
  236 + html_writer::empty_tag('input', $checkboxattributes) .
  237 + html_writer::empty_tag('input',
  238 + array('type' => 'hidden', 'value' => $postdata, 'class' => 'questionflagpostdata')) .
  239 + html_writer::tag('label', $this->get_flag_html($qa->is_flagged(), $id . 'img'),
  240 + array('id' => $id . 'label', 'for' => $id . 'checkbox')) . "\n";
  241 +
  242 + $divattributes = array(
  243 + 'class' => 'questionflag editable',
  244 + 'aria-atomic' => 'true',
  245 + 'aria-relevant' => 'text',
  246 + 'aria-live' => 'assertive',
  247 + );
  248 +
233 249 break;
  250 +
234 251 default:
235 252 $flagcontent = '';
236 253 }
237   - if ($flagcontent) {
238   - return '<div class="questionflag">' . $flagcontent . "</div>\n";
239   - }
  254 +
  255 + return html_writer::nonempty_tag('div', $flagcontent, $divattributes);
240 256 }
241 257
242 258 /**

0 comments on commit bd874d2

Please sign in to comment.
Something went wrong with that request. Please try again.