Skip to content

Instantly share code, notes, and snippets.

@3n
Created January 13, 2011 23:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3n/778870 to your computer and use it in GitHub Desktop.
Save 3n/778870 to your computer and use it in GitHub Desktop.
defines :delay(time) pseudo for Element.Event in MooTools
Event.definePseudo('onPause', function(split, fn, args){
clearTimeout(fn.onPauseId);
fn.onPauseId = fn.delay(split.value, this, args);
});
someElement.addEvent('keyup:onPause(100)', function(){
// will execute 100ms after last keyup occurs, great for keyboard input
});
@ibolmo
Copy link

ibolmo commented Jan 14, 2011

I'd imagine that this is bound to the element. Couldn't you store the delay timer in storage?

@3n
Copy link
Author

3n commented Jan 14, 2011

ibolmo, an element could have multiple of these events bound to it so, no, you probably shouldn't use element storage. The function you pass in will almost always be an anon function and wont be used anywhere else, therefor it makes a likely candidate for the timeout id. Logically it makes sense as well - the timer is for the function, not the element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment