开发者

How can I trigger the Twitter intents events programmatically?

The Facebook JS SDK has the equivalent of jQuery's trigger() function, FB.Event.fire that allows you to trigger the handlers you attach for particular events. Its helpful for my unit tests in QUnit. It works basically as yo开发者_如何学JAVAu'd expect it to; FB.Event.fire("comment.create", location.href); fires my handlers for the comment.create event.

Twitter's object for Web Intents, twttr appears to have something that looks like it could be similar, twttr.events.trigger(), but its undocumented.

Except, I can't figure out how to trigger it correctly in code, without it throwing an error.

How can I programmatically test the handlers that I attach to this object?

For code like:

twttr.events.bind("click", function(intent){
    console.dir(intent);
});

I'd expect to be able to trigger it by doing something like: twttr.events.trigger("click")

Everything I try results in an error, and I'm not able to decipher the obfuscated source code.

I've put up some basic code on the JSFiddle: http://jsfiddle.net/YL6SN/


Hello Yahel nice question,

It should work if you call this:

twttr.events.trigger("click", {});

It expects a second parameter that is the object that is passed back to your callback. When it happens naturally this object is populated with other parameters

{target: b,region: "intent",type: "click",data: {}}

If you pass an empty object like I proposed it will work as well but in your callback you receive the object only with the type property since this is added by the trigger.

And that was exactly the error you triggered when you don't pass a second parameter. It tries to add the type parameter to undefined and and then dies.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜