Skip to content

Instantly share code, notes, and snippets.

View blatyo's full-sized avatar
🎯
Planning

Allen Madsen blatyo

🎯
Planning
View GitHub Profile
InputOnChange = Class.create({
initialize: function(elementToWatch, functionToExecute, delay){
this.id = null;
this.functionToExecute = functionToExecute;
this.delay = delay;
elementToWatch.observe('keyup', this.onKeyUp.bindAsEventListener(this));
},
onKeyUp: function(event){
if(this.id){
window.clearTimeout(this.id);
Element.addMethods({
isVisible: function(element){
return !$(element).getStyle('visibility').match('hidden');
},
makeVisible: function(element){
//IE doesn't work with others, so we don't handle them
return $(element).setStyle({visibility: 'visible'});
},
Element.addMethods({
observeAll: function(element, eventHandlers){
$H(eventHandlers).each(function(handler){
Event.observe(element, handler.key, handler.value);
});
},
stopObservingAll: function(element, eventHandlers){
$H(eventHandlers).each(function(handler){
Event.stopObserving(element, handler.key, handler.value);
});