Skip to content

Instantly share code, notes, and snippets.

@cpojer
Created July 24, 2011 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpojer/1103139 to your computer and use it in GitHub Desktop.
Save cpojer/1103139 to your computer and use it in GitHub Desktop.
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