Created
July 24, 2011 21:41
-
-
Save cpojer/1103139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!window.addEventListener) (function(){ | |
Element.Events.keychange = { | |
base: 'keyup', | |
condition: function(e){ | |
var type = this.get('type'), | |
key = e.key; | |
if (type == 'radio') | |
return (key == 'up' || key == 'down' || key == 'left' || key == 'right' ) && this.checked; | |
return (type == 'checkbox' && key == 'space'); | |
} | |
}; | |
var getBase = function(){ | |
var type = this.get('type'); | |
return (type == 'checkbox' || type == 'radio') ? 'mouseup' : 'change'; | |
}; | |
Element.Events.change = { | |
base: getBase, | |
condition: function(){ | |
return (this.get('type') == 'radio') ? ((event.type == 'keyup') ? this.checked : !this.checked) : true; | |
}, | |
onAdd: function(fn){ | |
if (getBase.call(this) == 'mouseup') this.addEvent('keychange', fn); | |
}, | |
onRemove: function(fn){ | |
var base = getBase.call(this); | |
if (base == 'mouseup') this.addEvent('keychange', fn); | |
this.removeEvent(base, fn); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment