Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter widget callback

How do I call a callback when a Twitter widget is rendered?

Using the code they provided:

TWTR.Widget({data: something}).render().setUser('me').start();

Twitter has notoriously spotty service and frequent long load times. How do I add a callback on loading of the TWTR widget, so I can show my users a loader in the meantime?

like image 530
atp Avatar asked Mar 30 '11 20:03

atp


2 Answers

The widget has a _rendered property.

I made an example on jsfiddle. Note that there is no callback, you have to poll it to check if it has rendered. Also, you have to assign it to a variable when you create it, so you can access the _rendered property.

I found this by jsbeautifying the script, so it might not be 100% trustworthy and definitely not supported.

like image 25
Håvard Avatar answered Sep 22 '22 12:09

Håvard


I had to hunt down the author of the library on Twitter, but there is a ready callback: E.g.

new TWTR.Widget({
  id: 'twitter-feed',
  version: 2,
  .
  .
  .
  features: {        
      scrollbar: false,
      .
      .
  },
  ready: function() { 
    jQuery("div#twitter-load").remove();
  }
}).render().setUser('me').start();
like image 65
atp Avatar answered Sep 21 '22 12:09

atp