Skip to content

Instantly share code, notes, and snippets.

@cpojer
Forked from ibolmo/Element.Event.js
Created August 19, 2011 02:23
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/1155881 to your computer and use it in GitHub Desktop.
Save cpojer/1155881 to your computer and use it in GitHub Desktop.
/*<ltIE9>*/
if (!window.addEventListener) (function(){
var update = function(event){
event.target.store('$change', event.target.checked);
};
Element.Events.change = {
base: 'click',
condition: function(event){
var target = event.target;
if (target.type != 'radio') return true;
return (event.type == 'keyup') ? !target.checked : target.checked;
},
onAdd: function(fn){
if (this.type == 'checkbox' || this.type == 'radio') this.addEvents(this.retrieve('$change:events', {
focus: update,
keydown: update,
keyup: function(event){
var code = event.which || event.keyCode,
element = event.target,
value = element.retrieve('$change');
if (value != null && value != element.checked && (type == 'checkbox' && code == 32) || (type == 'radio' && code >= 37 && code <= 39)) fn.call(this, event)
}
});
},
onRemove: function(){
this.removeEvents(this.retrieve('$change:events')).eliminate('$change:events');
}
};
})();
/*</ltIE9>*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment