Using ash's "ready" function discovery, I needed to add some polling so that I would only remove the loading message if any tweets actually loaded. To test this, I would add the following to my hosts file to simulate an error fetching the tweets:
127.0.0.1 api.twitter.com
Note that my polling only executes 10 times with an interval of 200ms. This is because I don't want the code to poll indefinitely when the tweets seem to load within the first 2 seconds (if they are going to load at all). You can tailor these values to suite your situation.
function pollForTweets() {
if (jQuery("div#twitter-feed").find("div.twtr-tweet").length > 0) {
jQuery("div#twitter-load").remove();
return;
}
pollForTweets.pollCounter = pollForTweets.pollCounter || 0;
if (pollForTweets.pollCounter < 10) {
pollForTweets.pollCounter++;
setTimeout('pollForTweets()', 200);
}
}
new TWTR.Widget({
id: 'twitter-feed',
version: 2,
.
.
.
features: {
scrollbar: false,
loop: false,
live: false,
behavior: 'all'
},
ready: function () {
pollForTweets();
}
}).render().setUser('twitter').start();