开发者

Re-evaluate third-party processing JavaScript?

I have a number of widgets on my site that depend on running third party JavaScript to create them. For example, I have a Facebook comments box and a Twitter "tweet" button. Both of these things require me to run some JavaScript to create the widget. For example, for the Facebook comment box, their JavaScript converts

<fb:comments numposts="10" width="425" publish_feed="true"></fb:comments>

Into a full-featured Facebook iframe widget. This works OK if I want to create th开发者_如何学Goese elements statically, but now I'm interested in dynamically building such an element later on. Is there some simple way to, for example, re-evaluate the Facebook-supplied http://connect.facebook.net/en_US/all.js file to get it to build one of these widgets on the fly?


It may not be documented, but looking at that source, it has:

FB.Array.forEach(FB.XFBML._tagInfos, function (f) {
    if (!f.xmlns) f.xmlns = 'fb';
    var g = FB.XFBML._getDomElements(c, f.xmlns, f.localName);
    for (var e = 0; e < g.length; e++) {
        b++;
        FB.XFBML._processElement(g[e], f, d);
    }
});

d is a function that ultimately fires some kind of "render" event.

The _tagInfos array has definitions for things like:

localName: 'comments',
className: 'FB.XFBML.Comments'

So maybe you can call:

FB.XFBML._processElement(someElement, { 
    localName: 'comments', 
    className: 'FB.XFBML.Comments'
}, function() {
    FB.Event.fire('xfbml.render');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜