From 318b9027db03bc7397fa8072811db33783d29976 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Tue, 21 Feb 2017 21:56:56 +0000 Subject: Bug 1280363 - [a11y] Make the Actions menu button accessible for keyboard and screen readers --- .../en/default/bug_modal/activity_stream.html.tmpl | 48 +++++++--- .../template/en/default/bug_modal/edit.html.tmpl | 95 ++++++++++++++++--- .../template/en/default/bug_modal/header.html.tmpl | 6 +- .../template/en/default/bug_modal/user.html.tmpl | 7 +- extensions/BugModal/web/bug_modal.js | 101 +-------------------- extensions/BugModal/web/comments.js | 43 ++++----- extensions/BugModal/web/dropdown.css | 52 +++++++++++ extensions/BugModal/web/dropdown.js | 98 ++++++++++++++++++++ 8 files changed, 292 insertions(+), 158 deletions(-) create mode 100644 extensions/BugModal/web/dropdown.css create mode 100644 extensions/BugModal/web/dropdown.js diff --git a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl index c658f0642..49817b6a1 100644 --- a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl @@ -14,21 +14,43 @@ [% END %] + + - - [% PROCESS bug/time.html.tmpl; diff --git a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl index 4b23df786..6373e1f52 100644 --- a/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/edit.html.tmpl @@ -308,19 +308,32 @@ [% is_cced ? "Stop Following" : "Follow" %] [% END %] - - +
Get help with this page @@ -1300,9 +1313,61 @@
- + [% IF user.id %] - + [% END %]
diff --git a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl index e5070bcf5..3231ab311 100644 --- a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl @@ -52,6 +52,7 @@ "extensions/ProdCompSearch/web/js/prod_comp_search.js", "extensions/BugModal/web/bug_modal.js", "extensions/BugModal/web/comments.js", + "extensions/BugModal/web/dropdown.js", "extensions/BugModal/web/ZeroClipboard/ZeroClipboard.min.js", "js/bugzilla-readable-status-min.js", "js/field.js", @@ -60,14 +61,13 @@ ); jquery.push( "datetimepicker", - "contextMenu", "visibility" ); style_urls.push( "extensions/BugModal/web/bug_modal.css", + "extensions/BugModal/web/dropdown.css", "skins/custom/bug_groups.css", - "js/jquery/plugins/datetimepicker/datetimepicker.css", - "js/jquery/plugins/contextMenu/contextMenu.css" + "js/jquery/plugins/datetimepicker/datetimepicker.css" ); IF user.in_group('canconfirm'); diff --git a/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl index 5c630ba07..4c28936cc 100644 --- a/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/user.html.tmpl @@ -41,12 +41,11 @@ END; width="[% gravatar_size FILTER none %]" height="[% gravatar_size FILTER none %]"> [% END %] [% UNLESS gravatar_only %] - ') + .append(value + ' (' + tags[value] + ')'))); }); - $.contextMenu('destroy', '#comment-tags-btn'); - $.contextMenu({ - selector: '#comment-tags-btn', - trigger: 'left', - items: menuItems, - callback: function(key, opt) { - var tag = opt.commands[key].tag; + $('a[data-comment-tag]').each(function() { + $(this).click(function() { + var $that = $(this); + var tag = $that.data('comment-tag'); if (tag === '') { $('.change-spinner:visible').each(function() { toggleChange($(this), 'reset'); @@ -241,17 +238,17 @@ $(function() { } var firstComment = false; $('.change-spinner:visible').each(function() { - var that = $(this); - var commentTags = tagsFromDom(that.parents('.comment').find('.comment-tags')); + var $that = $(this); + var commentTags = tagsFromDom($that.parents('.comment').find('.comment-tags')); var hasTag = $.inArrayIn(tag, commentTags) >= 0; - toggleChange(that, hasTag ? 'show' : 'hide'); + toggleChange($that, hasTag ? 'show' : 'hide'); if (hasTag && !firstComment) { - firstComment = that; + firstComment = $that; } }); if (firstComment) $.scrollTo(firstComment); - } + }); }); } diff --git a/extensions/BugModal/web/dropdown.css b/extensions/BugModal/web/dropdown.css new file mode 100644 index 000000000..977a7a57f --- /dev/null +++ b/extensions/BugModal/web/dropdown.css @@ -0,0 +1,52 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. */ + +/* The container
- needed to position the dropdown content */ +.dropdown { + position: relative; + display: inline-block; +} + +/* Dropdown Content (Hidden by Default) */ +.dropdown-content { + position: absolute; + background-color: #eee; + min-width: 120px; + z-index: 1; + text-align: left; + margin: 0; + padding: 0; + border: 1px solid #ddd; + -webkit-box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1); + -moz-box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1); + box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1); + list-style: none; +} + +.dropdown-content.menu-up { + bottom: 100%; +} + +.dropdown-separator { + border-bottom: 1px solid #ddd; +} + +/* Links inside the dropdown */ +.dropdown-content a { + white-space: nowrap; + background-color: #eee; + color: black !important; + padding: 4px 8px; + text-decoration: none !important; + display: block; +} + +/* Change color of dropdown links on hover */ +.dropdown-content li .active { + text-decoration: none; + background-color: #39f; +} diff --git a/extensions/BugModal/web/dropdown.js b/extensions/BugModal/web/dropdown.js new file mode 100644 index 000000000..3198c09b1 --- /dev/null +++ b/extensions/BugModal/web/dropdown.js @@ -0,0 +1,98 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This Source Code Form is "Incompatible With Secondary Licenses", as + * defined by the Mozilla Public License, v. 2.0. */ + +$(function() { + 'use strict'; + + $(window).click(function(e) { + // clicking dropdown button opens or closes the dropdown content + if (!$(e.target).hasClass('dropdown-button')) { + $('.dropdown-button').each(function() { + toggleDropDown(e, $(this), $('#' + $(this).attr('aria-controls')), 1); + }); + } + }).keydown(function(e) { + // Escape key hides the dropdown if visible + if (e.keyCode == 27) { + $('.dropdown-button').each(function() { + var $button = $(this); + if ($button.siblings('.dropdown-content').is(':visible')) { + toggleDropDown(e, $button, $('#' + $button.attr('aria-controls')), 1); + $button.focus(); + } + }); + } + // allow arrow up and down keys to choose one of the dropdown items if menu visible + if (e.keyCode == 38 || e.keyCode == 40) { + $('.dropdown-content').each(function() { + var $content = $(this); + if ($content.is(':visible')) { + e.preventDefault(); + e.stopPropagation(); + var $li = $content.find('li'); + // if none focused select the first or last + var $any_focused = $content.find('a:focus'); + if ($any_focused.length == 0) { + var index = e.keyCode == 40 ? 0 : $li.length - 1; + var $link = $li.eq(index).find('a'); + $link.addClass('active').focus(); + return; + } + // otherwise move up or down the list based on arrow key pressed + var inc = e.keyCode == 40 ? 1 : -1; + var move = $content.find('a:focus').parent('li').index() + inc; + var $link = $li.eq(move % $li.length).find('a'); + $content.find('a').removeClass('active'); + $link.addClass('active').focus(); + } + }); + } + + // enter clicks on a link + if (e.keyCode == 13) { + $('.dropdown-content:visible a.active').trigger('click'); + } + }); + + $('.dropdown-content a').hover( + function(){ $(this).addClass('active') }, + function(){ $(this).removeClass('active') } + ); + + $('.dropdown').each(function() { + var $div = $(this); + var $button = $div.find('.dropdown-button'); + var $content = $div.find('.dropdown-content'); + $button.click(function(e) { + toggleDropDown(e, $button, $content); + }).keydown(function(e) { + // allow enter to toggle menu + if (e.keyCode == 13) { + toggleDropDown(e, $button, $content); + } + }); + }); + + function toggleDropDown(e, $button, $content, hide_only) { + // If clicking a real link we do not want to prevent default behavior + if (!$(e.target).is('.dropdown-content a') || $(e.target).is('.dropbown-button')) { + e.preventDefault(); + } + e.stopPropagation(); + // clear all active links + $content.find('a').removeClass('active'); + if ($content.is(':visible')) { + $content.hide(); + $button.attr('aria-expanded', false); + } + // if not using Escape or clicking outside the dropdown div, then we are hiding + else if (!hide_only) { + $content.show(); + $button.attr('aria-expanded', true); + } + } +}); -- cgit v1.2.3-24-g4f1b