Check originalEvent.repeat

This commit is contained in:
Robert Speicher 2015-10-07 15:19:26 -04:00
parent f96c6c43c4
commit fcf99d0d09
2 changed files with 10 additions and 2 deletions

View file

@ -14,7 +14,7 @@
# </form>
#
$(document).on 'keydown.quick_submit', '.js-quick-submit', (e) ->
return if e.repeat
return if e.originalEvent.repeat
return unless e.keyCode == 13 # Enter
if navigator.userAgent.match(/Macintosh/)

View file

@ -23,6 +23,11 @@ describe 'Quick Submit behavior', ->
expect(@spies.submit).not.toHaveBeenTriggered()
it 'does not respond to repeated events', ->
$('input').trigger(keydownEvent(repeat: true))
expect(@spies.submit).not.toHaveBeenTriggered()
it 'disables submit buttons', ->
$('textarea').trigger(keydownEvent())
@ -62,4 +67,7 @@ describe 'Quick Submit behavior', ->
else
defaults = { keyCode: 13, ctrlKey: true }
$.Event('keydown', $.extend({}, defaults, options))
args = $.extend({}, defaults, options)
originalEvent = new KeyboardEvent('keydown', args)
$.Event('keydown', $.extend({}, args, {originalEvent: originalEvent}))