I have the following Coffeescript code:
# Coffeescript
setMessage = (message, options = {}) ->
t = statusArea.text(message)
if options['fade']
t.addClass('yellow')
t.fadeOut 4000, ->
$(this).removeClass 'yellow'
// Javascript
setMessage = function(message, options) {
var t;
if (options == null) options = {};
t = statusArea.text(message);
if (options['fade']) {
t.addClass('yellow');
return t.fadeOut(4000, function() {
return $(this).removeClass('yellow');
});
}
};
which is meant to display a status message inside a LI element. If options['fade']
is set to anything, then I invoke the fading stuff. The first thing that happens in my program flow is that I issue an Ajax call to populate a SELECT and post a "making remote call" message with a fade (i.e., with options['fade']
set to true
) to the status area. This can be almost instantaneous or it can take a while. It depends on the size of the result and network traffic. Once the SELECT is populated, I post a "ready" message without a fade.
The problem occurs when the response is almost instantaneous. In that case, the text is replaced with "ready" but the animation continues, fading the message out (i.e., fading the LI element out).
Is there an accepted way to terminate the previous transition, if any, before starting another one?