Callback after twttr.widgets.load processes tweets on the page


#1

I am loading new and new tweets dynamically on the page (infinite scrolling) and I am calling twttr.widgets.load each time I add new tweets for them to be rendered Twitter-like. Is there a way to get some callback/event once they (or each separately) have been processed so that I could do some additional things once they have whole content and size (like reflowing them on the site)?


#2

There’s nothing like that just yet, I’m afraid, but that’s a nice addition to make. I’ll take a look into it.

For now, you might get some milage by watching for DOM mutation events in newer browsers (although that whole API is unstable and being replaced in DOM4, so ymmv), but our initialization code will run replaceChild on all the embed codes with their iframe replacements, so you might be able to use it still.

As I say, we’ll look into giving you a proper callback interface soon.


#3

Yes, watching DOM changes is … ugly. At least for now. I will wait for better interface. Thanks! You are really great and responsive.


#4

Ah, one more thing. It would be great if callback would get information if tweet existed. Currently, I cache html fragment for the tweet and then call twttr.widgets.load over those fragments. If tweet was deleted in meantime, fragment is left as it is. It would be useful to get this information in callback so that I can decide what to do (probably simple remove the tweet and inform the server to check).


#5

Or even better. As Twitter library fetches data about tweets from the server, this data could be passed to the callback. If data would be missing, this means tweet was deleted. If data would be there, developer could use this for example to provide a feedback for current number of retweets (for example, add some CSS to show more popular tweets).


#6

Any followup?


#7

+1 on this.


#8

+1 Would love to see this too


#9

+1


#10

+1


#11

Hey guys! Any progress about calling a callback after tweets are loaded?


#12

I ended up loaded tweets ‘dynamically’ from my own database so in that instance, callbacks are your own responsibility, this can also cut down on twitter calls, but is slightly less than ‘real-time’.

After a year and 5 days, this probably won’t be resolved helpfully anytime soon…

good luck!


#13

+1 for this…


#14

Hi, I have a problem where the Twitter widget gets hidden because my website cannot handle the within the iframe, so the embedable timeline widget looks like:

However it does not work because the resizeMe callback must be called after twitter gets finished with it’s execution (and sets the size), within the iframe. They said " For this, you must set up the twitter feed to make the callback after it is loaded. Typically this is done by using the ready function." - Has anyone faced this problem? Any idea how to make this work?


#15

How I solved this - use DOMNodeInserted or DomNodeRemoved events.

JS Fiddle: http://jsfiddle.net/mojowen/9x3bh/


#16

Those events are deprecated. https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Mutation_events


#17

+1 for this feature, too :slight_smile:


#18

Hi everyone. Since this thread happened we added two new events. Use twttr.events.bind(‘rendered’, ƒ) to get an event for every individual widget that renders in a page, or twttr.events.bind(‘loaded’, ƒ) for the whole set after you call twttr.widgets.load.

See the [node:25877, title=“scripting events documentation”] for more details.

Ben


#19

Thanks, Ben!


#20

can you please post your code for this? i’m trying to do the same thing…