Skip to content

Instantly share code, notes, and snippets.

@fermion
Created April 9, 2009 16:26
Show Gist options
  • Save fermion/92555 to your computer and use it in GitHub Desktop.
Save fermion/92555 to your computer and use it in GitHub Desktop.
var Hoverer = {
current: null,
delay: 0.5,
timer: null,
handler: function(event) {
var element = event.findElement('div.nav_menu');
if (!element)
return Hoverer.leave();
if (element == Hoverer.current)
return Hoverer.stopTimer();
Hoverer.enter(element)
},
observe: function() {
document.observe('mouseover', Hoverer.handler);
},
stopObserving: function() {
document.stopObserving('mouseover', Hoverer.handler);
},
enter: function(element) {
Hoverer.stopTimer();
if (Hoverer.current) Hoverer.fireMouseExited(Hoverer.current);
element.fire('mouse:entered');
Hoverer.current = element;
},
leave: function() {
if (!Hoverer.current || Hoverer.timer) return;
Hoverer.timer = Hoverer.fireMouseExited.curry(Hoverer.current).delay(Hoverer.delay)
},
fireMouseExited: function(element) {
element.fire('mouse:exited');
Hoverer.current = null;
},
stopTimer: function() {
if (!Hoverer.timer) return;
window.clearTimeout(Hoverer.timer);
Hoverer.timer = null;
}
};
//Hoverer.observe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment