Embedded tweets completion event?

2019-04-08 19:29发布

问题:

Using Twitter's embed code for single tweets causes a script called widget.js to be loaded. This script is responsible for dynamically generating the HTML of the tweet.

Is there an event triggered by widget.js when the rendering of an embedded tweet is complete? How can my code find out that rendering is complete?

I need this because I am trying to use jQuery Masonry to layout a set of tweets. Masonry fixes the container height for each tweet before the tweets are fully rendered, causing overlap. I'd like to be notified that all tweets are fully rendered in order to refresh the Masonry layout.

回答1:

I ended up using a jQuery "watch" plugin (e.g. https://github.com/darcyclarke/jQuery-Watch-Plugin) to watch for DOM changes on the container div.



回答2:

If you look into the uncompressed code here searching for "render" yields this interesting conditional

    if (this._rendered) {
        var anchor = this.byClass('twtr-join-conv', 'a');
        anchor.href = 'http://twitter.com/' + this._getWidgetPath();
    }

and somewhat lower in the code is

    this._rendered = true;
    // call the ready handler
    this._ready();
    return this;

you might be able to explore...