Created
February 29, 2012 11:01
-
-
Save thinkphp/1940001 to your computer and use it in GitHub Desktop.
creating a custom widget using Dijit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(["dojo/io/script","dojo/dom","dojo/_base/array","custom/widget"],function(jsonp,dom,util,Widget){ | |
| var container = dom.byId("twitterbadge"), | |
| jsonpArgs = { | |
| url: "http://twitter.com/statuses/user_timeline.json", | |
| callbackParamName: "callback", | |
| content: { | |
| screen_name: "thinkphp", | |
| count: 8 | |
| }, | |
| load: function(data){ | |
| var tweets = []; | |
| util.forEach(data, function(tweet){ | |
| tweet.text = tweet.text.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1" target="_blank">$1<\/a>').replace(/@([a-zA-Z0-9_]+)/gi,'<a href="http://twitter.com/$1" target="_blank">@$1<\/a>').replace(/#([a-zA-Z0-9_]+)/gi,'<a href="http://search.twitter.com/search?q=%23$1" target="_blank">#$1<\/a>'); | |
| new Widget({'name': tweet.user.name,'avatar':tweet.user.profile_image_url,'bio': tweet.text}).placeAt(container) | |
| }); | |
| }, | |
| error: function(error){ | |
| container.innerHTML = "An unexpected error occurred: " + error; | |
| } | |
| } | |
| jsonp.get(jsonpArgs) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment