Permalink
Browse files

fixes #76 (keyCode vs which regression)

  • Loading branch information...
1 parent 4ea48a2 commit dd0f4238b6a945a1e2b15d8b4f0fccd5107ba895 @rvagg rvagg committed Sep 22, 2012
Showing with 24 additions and 6 deletions.
  1. +1 −1 src/bean.js
  2. +23 −5 tests/event-object-test.js
View
@@ -110,7 +110,7 @@
{ // key events
reg: /key/i
, fix: function (event, newEvent) {
- newEvent.keyCode = event.which || event.keyCode
+ newEvent.keyCode = event.keyCode || event.which
return keyProps
}
}
@@ -1,4 +1,4 @@
-/*global bean:true, qwery:true, buster:true, Syn:true, assert:true, defer:true, features:true, globalSetUp:true, globalTearDown:true*/
+/*global bean:true, qwery:true, buster:true, Syn:true, assert:true, features:true, globalSetUp:true, globalTearDown:true*/
buster.testCase('event object', {
'setUp': globalSetUp
@@ -216,11 +216,11 @@ buster.testCase('event object', {
, clickIgnorables = commonIgnorables.concat(oldIEIgnorables).concat(('charCode defaultPrevented initMouseEvent keyCode layerX layerY ' +
'initNSMouseEvent x y state webkitMovementY webkitMovementX').split(' '))
, oldIEKeyIgnorables = 'fromElement toElement dataTransfer button x y screenX screenY clientX clientY offsetX offsetY state'.split(' ')
- , keyIgnorables = commonIgnorables.concat(oldIEIgnorables).concat(oldIEKeyIgnorables).concat('initKeyEvent layerX layerY pageX pageY state'.split(' '))
+ , keyIgnorables = this.keyIgnorables = commonIgnorables.concat(oldIEIgnorables).concat(oldIEKeyIgnorables).concat('initKeyEvent layerX layerY pageX pageY state'.split(' '))
, el = this.byId('input')
- , getEventObject = function (evType, elType, trigger, callback) {
+ , getEventObject = this.getEventObject = function (evType, elType, trigger, callback) {
var handler = function (e) {
bean.remove(el)
callback(e)
@@ -238,7 +238,7 @@ buster.testCase('event object', {
return false
}
- , verifyEventObject = function (event, type, ignorables) {
+ , verifyEventObject = this.verifyEventObject = function (event, type, ignorables) {
var p, orig = event.originalEvent
assert(event, 'has event object')
@@ -276,7 +276,7 @@ buster.testCase('event object', {
getEventObject(
type
, window
- , function (el) {
+ , function () {
window.history.pushState({}, 'test state', '#test-state')
window.history.go(-1)
}
@@ -333,5 +333,23 @@ buster.testCase('event object', {
, 'keypress: has correct properties': function (done) {
this.testKeyEvent('keypress', done)
}
+
+ // see https://github.com/fat/bean/pull/61 & https://github.com/fat/bean/issues/76
+ , 'key events prefer "keyCode" rather than "which"': function (done) {
+ var verifyEventObject = this.verifyEventObject
+ , keyIgnorables = this.keyIgnorables
+
+ this.getEventObject(
+ 'keyup'
+ , 'input'
+ , function (el) { Syn.trigger('keyup', { which: 'g', keyCode: 'f' }, el) }
+ , function (event) {
+ verifyEventObject(event, 'keyup', keyIgnorables)
+ console.log(event)
+ assert.equals(event.keyCode, 'f', 'correct keyCode')
+ done()
+ }
+ )
+ }
}
})

0 comments on commit dd0f423

Please sign in to comment.