Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created February 29, 2012 11:01
Show Gist options
  • Select an option

  • Save thinkphp/1940001 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/1940001 to your computer and use it in GitHub Desktop.
creating a custom widget using Dijit
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