Fix forum button keyboard activation
Previously, buttons were activated on pressing Enter, but the expected behavior is to activate on pressing Space. Several JavaScript errors that prevented various buttons from properly activating via the keyboard are also fixed.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user