From a0fa9d0b148f6d05f8cd8e1afa2aa0e3004abdb9 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 22 Nov 2013 17:48:29 -0500 Subject: [PATCH 1/2] Refactor keypress activation for forum buttons This removes the use of the space key to activate buttons, which is not expected behavior. --- common/static/coffee/src/discussion/utils.coffee | 5 +++++ .../discussion/views/discussion_content_view.coffee | 13 ++----------- .../views/discussion_thread_profile_view.coffee | 3 ++- .../views/discussion_thread_show_view.coffee | 6 ++++-- .../views/thread_response_show_view.coffee | 3 ++- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common/static/coffee/src/discussion/utils.coffee b/common/static/coffee/src/discussion/utils.coffee index 89014c5f57..53509b35e0 100644 --- a/common/static/coffee/src/discussion/utils.coffee +++ b/common/static/coffee/src/discussion/utils.coffee @@ -87,6 +87,11 @@ class @DiscussionUtil "notifications_status" : "/notification_prefs/status" }[name] + @activateOnEnter: (event, func) -> + if event.which == 13 + e.preventDefault() + func(event) + @makeFocusTrap: (elem) -> elem.keydown( (event) -> diff --git a/common/static/coffee/src/discussion/views/discussion_content_view.coffee b/common/static/coffee/src/discussion/views/discussion_content_view.coffee index c695955897..9c3c4a01f5 100644 --- a/common/static/coffee/src/discussion/views/discussion_content_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_content_view.coffee @@ -4,7 +4,8 @@ if Backbone? events: "click .discussion-flag-abuse": "toggleFlagAbuse" - "keypress .discussion-flag-abuse": "toggleFlagAbuseKeypress" + "keypress .discussion-flag-abuse": + (event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) attrRenderer: endorsed: (endorsed) -> @@ -106,11 +107,6 @@ if Backbone? @model.bind('change', @renderPartialAttrs, @) - toggleFollowingKeypress: (event) -> - # Activate on spacebar or enter - if event.which == 32 or event.which == 13 - @toggleFollowing(event) - toggleFollowing: (event) -> event.preventDefault() $elem = $(event.target) @@ -126,11 +122,6 @@ if Backbone? url: url type: "POST" - toggleFlagAbuseKeypress: (event) -> - # Activate on spacebar or enter - if event.which == 32 or event.which == 13 - @toggleFlagAbuse(event) - toggleFlagAbuse: (event) -> event.preventDefault() if window.user.id in @model.get("abuse_flaggers") or (DiscussionUtil.isFlagModerator and @model.get("abuse_flaggers").length > 0) diff --git a/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee index b8cecbf39b..7130ac555c 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_profile_view.coffee @@ -4,7 +4,8 @@ if Backbone? events: "click .discussion-vote": "toggleVote" "click .action-follow": "toggleFollowing" - "keypress .action-follow": "toggleFollowingKeypress" + "keypress .action-follow": + (event) -> DiscussionUtil.activateOnEnter(event, toggleFollowing) "click .expand-post": "expandPost" "click .collapse-post": "collapsePost" diff --git a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee index b5f478a8af..1a3f8929e1 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee @@ -4,10 +4,12 @@ if Backbone? events: "click .discussion-vote": "toggleVote" "click .discussion-flag-abuse": "toggleFlagAbuse" - "keypress .discussion-flag-abuse": "toggleFlagAbuseKeypress" + "keypress .discussion-flag-abuse": + (event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) "click .admin-pin": "togglePin" "click .action-follow": "toggleFollowing" - "keypress .action-follow": "toggleFollowingKeypress" + "keypress .action-follow": + (event) -> DiscussionUtil.activateOnEnter(event, toggleFollowing) "click .action-edit": "edit" "click .action-delete": "_delete" "click .action-openclose": "toggleClosed" diff --git a/common/static/coffee/src/discussion/views/thread_response_show_view.coffee b/common/static/coffee/src/discussion/views/thread_response_show_view.coffee index aaff4a4a39..eaed0568c2 100644 --- a/common/static/coffee/src/discussion/views/thread_response_show_view.coffee +++ b/common/static/coffee/src/discussion/views/thread_response_show_view.coffee @@ -6,7 +6,8 @@ if Backbone? "click .action-delete": "_delete" "click .action-edit": "edit" "click .discussion-flag-abuse": "toggleFlagAbuse" - "keypress .discussion-flag-abuse": "toggleFlagAbuseKeypress" + "keypress .discussion-flag-abuse": + (event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) $: (selector) -> @$el.find(selector) From 81798dd8be9f72f2ab7f61f9aa2526320a6a5ce7 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 22 Nov 2013 17:50:39 -0500 Subject: [PATCH 2/2] Improve accessibility of inline discussions The show/hide toggle now properly acts like a button, and focus is now trapped on the loading element for both the show/hide action and loading of a new page. --- CHANGELOG.rst | 2 ++ .../coffee/src/discussion/discussion_module_view.coffee | 4 ++++ common/static/coffee/src/discussion/utils.coffee | 9 ++++++--- lms/templates/discussion/_discussion_module.html | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8e2ff9f896..a9926ad9e6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,8 @@ Studio: Continued modification of Studio pages to follow a RESTful framework. includes Settings pages, edit page for Subsection and Unit, and interfaces for updating xblocks (xmodules) and getting their editing HTML. +LMS: Improve accessibility of inline discussions in courseware. + Blades: Put 2nd "Hide output" button at top of test box & increase text size for code response questions. BLD-126. diff --git a/common/static/coffee/src/discussion/discussion_module_view.coffee b/common/static/coffee/src/discussion/discussion_module_view.coffee index f99eba3872..e23215561e 100644 --- a/common/static/coffee/src/discussion/discussion_module_view.coffee +++ b/common/static/coffee/src/discussion/discussion_module_view.coffee @@ -2,6 +2,8 @@ if Backbone? class @DiscussionModuleView extends Backbone.View events: "click .discussion-show": "toggleDiscussion" + "keypress .discussion-show": + (event) -> DiscussionUtil.activateOnEnter(event, toggleDiscussion) "click .new-post-btn": "toggleNewPost" "click .new-post-cancel": "hideNewPost" "click .discussion-paginator a": "navigateToPage" @@ -70,6 +72,7 @@ if Backbone? DiscussionUtil.safeAjax $elem: $elem $loading: $elem + takeFocus: true url: url type: "GET" dataType: 'json' @@ -77,6 +80,7 @@ if Backbone? error: error renderDiscussion: ($elem, response, textStatus, discussionId) => + $elem.focus() window.user = new DiscussionUser(response.user_info) Content.loadContentInfos(response.annotated_content_info) DiscussionUtil.loadRoles(response.roles) diff --git a/common/static/coffee/src/discussion/utils.coffee b/common/static/coffee/src/discussion/utils.coffee index 53509b35e0..466beff419 100644 --- a/common/static/coffee/src/discussion/utils.coffee +++ b/common/static/coffee/src/discussion/utils.coffee @@ -2,9 +2,12 @@ $ -> if !window.$$contents window.$$contents = {} $.fn.extend - loading: -> - @$_loading = $("
Loading content
") + loading: (takeFocus) -> + @$_loading = $("
Loading content
") $(this).after(@$_loading) + if takeFocus + DiscussionUtil.makeFocusTrap(@$_loading) + @$_loading.focus() loaded: -> @$_loading.remove() @@ -132,7 +135,7 @@ class @DiscussionUtil if params["loadingCallback"]? params["loadingCallback"].apply(params["$loading"]) else - params["$loading"].loading() + params["$loading"].loading(params["takeFocus"]) if !params["error"] params["error"] = => @discussionAlert( diff --git a/lms/templates/discussion/_discussion_module.html b/lms/templates/discussion/_discussion_module.html index 37f8052520..00f6c94801 100644 --- a/lms/templates/discussion/_discussion_module.html +++ b/lms/templates/discussion/_discussion_module.html @@ -2,6 +2,6 @@ <%include file="_underscore_templates.html" />