Skip to content

Instantly share code, notes, and snippets.

@csuwildcat
Forked from ibolmo/Element.Event.js
Created August 19, 2011 17:44
Show Gist options
  • Save csuwildcat/1157453 to your computer and use it in GitHub Desktop.
Save csuwildcat/1157453 to your computer and use it in GitHub Desktop.
/*<ltIE9>*/
if (!window.addEventListener) (function(){
var update = function(event){
event.target.store('$change:last', {
type: event.type,
value: event.target.checked
});
};
Element.Events._change = {
base: 'change'
};
Element.Events.change = {
base: 'click',
condition: function(event){
var target = event.target, type = target.type, last = target.retrieve('$change:last', {});
if (type == 'text' || /textarea|select/.test(target.get('tag'))) return event.type == 'change';
if (type == 'radio' && last.type != 'mousedown' && /up|down|left|right/.test(target.retrieve('$change:key', ''))) return true;
return target.checked != last.value;
},
onAdd: function(fn){
this.addEvents(this.retrieve('$change:events', {
keydown: update,
mousedown: update,
_change: function(event){
if (!/radio|checkbox/.test(event.target.type)) fn.call(this, event);
},
keyup: function(event) {
event.target.store('$change:key', event.key);
return event.code != 16 && event.key != 'tab';
}
}));
},
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