var killFlag=null;
function showMoveControls() {
killFlag=null;
setTimeout("doOpenMoveControls()", 1000)
}
function doOpenMoveControls() {
if (!killFlag) {
$('move_controls').show();
}
}
function hideMoveControls() {
killFlag=1;
$('move_controls').hide();
}
Refactorings
No refactoring yet !
Tj Holowaychuk
April 30, 2009, April 30, 2009 19:26, permalink
This is not 100% ideal but should work for your situation. you should generalize functionality like this as much as you can, just helps to remove any state tied to it, because you will want to use this again most likely :)
(function($){
$.fn.delayedBind = function(type, duration, callback) {
return this.bind(type, function(){
var self = this
setTimeout(function(){
callback.call(self)
}, duration)
})
}
})(jQuery)
// change the value of any input to 'Wahoo' after hovering for 1 second
$(function(){
$('input').delayedBind('mouseover', 1000, function(){
$(this).attr('value', 'Wahoo')
})
})
openid.aol.com/forwardfootmedia
May 7, 2009, May 07, 2009 23:26, permalink
you may find this article on state machines of interest... good read either way. http://autonomousmachine.com/2008/12/30/list-ordering-with-a-javascript-state-machine
Hello. I'd like to fire a javascript event 1000 milliseconds after an event, but I'd like to CANCEL that event if there's activity again. So a simple setTimeout wont work because it'll fire regardless. I have the following but it kinda works and kinda doesn't.
showMoveControls is triggered on mouseover and hideMoveControls is triggered on mouseout.
As you can probably tell, I'm showing additional menu options if a user hovers over a toolbar for a few moments. But if they casually are just mousing up to the toolbar or over it without pausing, then I don't want those options to show.
Any help is appreciated.