From af65270e875e11887a89b61a62cc5a27cddb9e8a Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Wed, 18 Jan 2017 16:13:31 +0800 Subject: [PATCH] MDL-35978 comments: expandable comments announce change when toggled Added role and aria-expanded attributes to the toggler link and added a key handler for the space and enter keys. --- comment/comment.js | 9 +++++++++ comment/lib.php | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/comment/comment.js b/comment/comment.js index 9ae289598d1..5cc0fae6542 100644 --- a/comment/comment.js +++ b/comment/comment.js @@ -57,6 +57,12 @@ M.core_comment = { this.view(0); return false; }, this); + // Also handle space/enter key. + handle.on('key', function(e) { + e.preventDefault(); + this.view(0); + return false; + }, '13,32', this); } scope.toggle_textarea(false); }, @@ -335,6 +341,7 @@ M.core_comment = { ); }, view: function(page) { + var commenttoggler = Y.one('#comment-link-' + this.client_id); var container = Y.one('#comment-ctrl-'+this.client_id); var ta = Y.one('#dlg-content-'+this.client_id); var img = Y.one('#comment-img-'+this.client_id); @@ -351,6 +358,7 @@ M.core_comment = { if (img) { img.set('src', M.util.image_url('t/expanded', 'core')); } + commenttoggler.setAttribute('aria-expanded', 'true'); } else { // hide container.setStyle('display', 'none'); @@ -364,6 +372,7 @@ M.core_comment = { if (ta) { ta.set('value',''); } + commenttoggler.setAttribute('aria-expanded', 'false'); } if (ta) { //toggle_textarea.apply(ta, [false]); diff --git a/comment/lib.php b/comment/lib.php index 42b3d425dec..8bc01976e74 100644 --- a/comment/lib.php +++ b/comment/lib.php @@ -460,7 +460,13 @@ class comment { } else { $collapsedimage= 't/collapsed'; } - $html .= html_writer::start_tag('a', array('class' => 'comment-link', 'id' => 'comment-link-'.$this->cid, 'href' => '#')); + $html .= html_writer::start_tag('a', array( + 'class' => 'comment-link', + 'id' => 'comment-link-'.$this->cid, + 'href' => '#', + 'role' => 'button', + 'aria-expanded' => 'false') + ); $html .= html_writer::empty_tag('img', array('id' => 'comment-img-'.$this->cid, 'src' => $OUTPUT->pix_url($collapsedimage), 'alt' => $this->linktext, 'title' => $this->linktext)); $html .= html_writer::tag('span', $this->linktext.' '.$countstring, array('id' => 'comment-link-text-'.$this->cid)); $html .= html_writer::end_tag('a');