Refactor keypress activation for forum buttons

This removes the use of the space key to activate buttons, which is not
expected behavior.
This commit is contained in:
Greg Price
2013-11-22 17:48:29 -05:00
parent 3ed96f75a1
commit a0fa9d0b14
5 changed files with 15 additions and 15 deletions

View File

@@ -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) ->

View File

@@ -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)

View File

@@ -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"

View File

@@ -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"

View File

@@ -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)