Created
April 9, 2009 16:26
-
-
Save fermion/92555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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