Commit a0fa9d0b by Greg Price

Refactor keypress activation for forum buttons

This removes the use of the space key to activate buttons, which is not
expected behavior.
parent 3ed96f75
......@@ -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) ->
......
......@@ -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)
......
......@@ -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"
......
......@@ -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"
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment