Hi folks,
While I have the problem itself seemingly resolved, I'm hoping someone can shed some light on the why of this...
Below are two snapshots of the same function whose job is to remove a div that contains a user feedback message. It's setup to use an optional timeout, if a timeout is specified it makes a call to itself using setTimeout() which then removes the div.
The only difference between the two versions of the function is where this.remove() is called - in the problem version I send a message to the log using blackbirdjs first and then call this.remove() - after this executes the log is flooded with unending log messages of "Removing feedback div..." as fast as the browser can pump them in.
In the working version, however, I simply reverse the order and everything executes normally and all is well...
I'm boggled, I would think that the order in this case would be trivial but apparently not. Can anyone shed some light on why this would be happening? Is this a jQuery bug or a problem with blackbird or some kind of weird quirk of JavaScript in general?
NOTE:
I had some mixed success using a call to confirm() - if it came back false I told it to return and this stopped it - however, just adding return after the remove call had no effect.
Interestingly enough, either version seems to work fine in IE8 - so this may be a firefox/gecko problem?
Problem Code:
function clear_feedback(target_container, timeout){
log.debug("timeout: " + timeout);
log.debug("target_container: " + target_container);
if(timeout == undefined){
log.info("removing target...");
$(target_container).children(".update_feedback").slideUp("slow",
function() {
log.info("Removing feedback div...");
this.remove();
}
);
}
else{
log.info("Setting timeout, THEN removing target...");
setTimeout("clear_feedback('" + target_container + "')", timeout);
}
}
Working Code:
function clear_feedback(target_container, timeout){
log.debug("timeout: " + timeout);
log.debug("target_container: " + target_container);
if(timeout == undefined){
log.info("removing target...");
$(target_container).children(".update_feedback").slideUp("slow",
function() {
this.remove();
log.info("Removing feedback div...");
}
);
}
else{
log.info("Setting timeout, THEN removing target...");
setTimeout("clear_feedback('" + target_container + "')", timeout);
}
}