diff --git a/common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee b/common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee index 5696766aca..042cde5c64 100644 --- a/common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee +++ b/common/static/coffee/spec/discussion/view/discussion_view_spec_helper.coffee @@ -105,7 +105,7 @@ class @DiscussionViewSpecHelper expect(view.toggleVote).toHaveBeenCalled() view.toggleVote.reset() button.trigger($.Event("keydown", {which: 13})) - expect(view.toggleVote).toHaveBeenCalled() + expect(view.toggleVote).not.toHaveBeenCalled() view.toggleVote.reset() button.trigger($.Event("keydown", {which: 32})) - expect(view.toggleVote).not.toHaveBeenCalled() + expect(view.toggleVote).toHaveBeenCalled() diff --git a/common/static/coffee/src/discussion/discussion_module_view.coffee b/common/static/coffee/src/discussion/discussion_module_view.coffee index 2e6002b011..ec91c067f5 100644 --- a/common/static/coffee/src/discussion/discussion_module_view.coffee +++ b/common/static/coffee/src/discussion/discussion_module_view.coffee @@ -2,8 +2,8 @@ if Backbone? class @DiscussionModuleView extends Backbone.View events: "click .discussion-show": "toggleDiscussion" - "keypress .discussion-show": - (event) -> DiscussionUtil.activateOnEnter(event, toggleDiscussion) + "keydown .discussion-show": + (event) -> DiscussionUtil.activateOnSpace(event, @toggleDiscussion) "click .new-post-btn": "toggleNewPost" "click .new-post-cancel": "hideNewPost" "click .discussion-paginator a": "navigateToPage" @@ -38,13 +38,13 @@ if Backbone? event.preventDefault() @newPostForm.slideUp(300) - hideDiscussion: -> + hideDiscussion: => @$("section.discussion").slideUp() @toggleDiscussionBtn.removeClass('shown') @toggleDiscussionBtn.find('.button-text').html(gettext("Show Discussion")) @showed = false - toggleDiscussion: (event) -> + toggleDiscussion: (event) => if @showed @hideDiscussion() else diff --git a/common/static/coffee/src/discussion/utils.coffee b/common/static/coffee/src/discussion/utils.coffee index 87d94ab590..ad10ccae38 100644 --- a/common/static/coffee/src/discussion/utils.coffee +++ b/common/static/coffee/src/discussion/utils.coffee @@ -88,8 +88,8 @@ class @DiscussionUtil "notifications_status" : "/notification_prefs/status/" }[name] - @activateOnEnter: (event, func) -> - if event.which == 13 + @activateOnSpace: (event, func) -> + if event.which == 32 event.preventDefault() func(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 5ea75f338b..90abbb4cf3 100644 --- a/common/static/coffee/src/discussion/views/discussion_content_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_content_view.coffee @@ -4,8 +4,8 @@ if Backbone? events: "click .discussion-flag-abuse": "toggleFlagAbuse" - "keypress .discussion-flag-abuse": - (event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) + "keydown .discussion-flag-abuse": + (event) -> DiscussionUtil.activateOnSpace(event, @toggleFlagAbuse) attrRenderer: endorsed: (endorsed) -> @@ -107,7 +107,7 @@ if Backbone? @model.bind('change', @renderPartialAttrs, @) - toggleFollowing: (event) -> + toggleFollowing: (event) => event.preventDefault() $elem = $(event.target) url = null @@ -122,14 +122,14 @@ if Backbone? url: url type: "POST" - 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) @unFlagAbuse() else @flagAbuse() - flagAbuse: -> + flagAbuse: => url = @model.urlFor("flagAbuse") DiscussionUtil.safeAjax $elem: @$(".discussion-flag-abuse") @@ -144,7 +144,7 @@ if Backbone? temp_array.push(window.user.id) @model.set('abuse_flaggers', temp_array) - unFlagAbuse: -> + unFlagAbuse: => url = @model.urlFor("unFlagAbuse") DiscussionUtil.safeAjax $elem: @$(".discussion-flag-abuse") 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 f6a6ea8eb6..2564015b1b 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 @@ -5,10 +5,10 @@ if Backbone? "click .vote-btn": (event) -> @toggleVote(event) "keydown .vote-btn": - (event) -> DiscussionUtil.activateOnEnter(event, @toggleVote) + (event) -> DiscussionUtil.activateOnSpace(event, @toggleVote) "click .action-follow": "toggleFollowing" - "keypress .action-follow": - (event) -> DiscussionUtil.activateOnEnter(event, toggleFollowing) + "keydown .action-follow": + (event) -> DiscussionUtil.activateOnSpace(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 a31e977442..26f2267b73 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 @@ -5,14 +5,14 @@ if Backbone? "click .vote-btn": (event) -> @toggleVote(event) "keydown .vote-btn": - (event) -> DiscussionUtil.activateOnEnter(event, @toggleVote) + (event) -> DiscussionUtil.activateOnSpace(event, @toggleVote) "click .discussion-flag-abuse": "toggleFlagAbuse" - "keypress .discussion-flag-abuse": - (event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) + "keydown .discussion-flag-abuse": + (event) -> DiscussionUtil.activateOnSpace(event, @toggleFlagAbuse) "click .admin-pin": "togglePin" "click .action-follow": "toggleFollowing" - "keypress .action-follow": - (event) -> DiscussionUtil.activateOnEnter(event, toggleFollowing) + "keydown .action-follow": + (event) -> DiscussionUtil.activateOnSpace(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 2ffe2d987c..01b985a627 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 @@ -4,13 +4,13 @@ if Backbone? "click .vote-btn": (event) -> @toggleVote(event) "keydown .vote-btn": - (event) -> DiscussionUtil.activateOnEnter(event, @toggleVote) + (event) -> DiscussionUtil.activateOnSpace(event, @toggleVote) "click .action-endorse": "toggleEndorse" "click .action-delete": "_delete" "click .action-edit": "edit" "click .discussion-flag-abuse": "toggleFlagAbuse" - "keypress .discussion-flag-abuse": - (event) -> DiscussionUtil.activateOnEnter(event, toggleFlagAbuse) + "keydown .discussion-flag-abuse": + (event) -> DiscussionUtil.activateOnSpace(event, @toggleFlagAbuse) $: (selector) -> @$el.find(selector)