Help needed to extend Twitter 'plugin' to also display date created
in Developing jQuery Plugins
•
10 years ago
Hi all,
I have built this Twitter plugin by going through some tutorials. It works great but I would also like to display the date and time the tweet was created as well.
I was hoping someone might be able to help me modify this code:
Any help would be greatly appreciated!
-
(function($){
//Creating Function called Twitterize
$.fn.twitterize = function(username,options){
//check to see if the username has been set.
if (username){
//SET DEFAULT AMOUNT OF TWEETS TO GET
var defaultSettings = {
count:'20'
}
// Finds which default settings have been overwritten by the options object
// and creates a new object with all the new and untouched settings.
var settings = $.extend(defaultSettings, options);
// The URL for the Twitter JSON API.
var url = "http://twitter.com/status/user_timeline/"+username+".json?count="+settings.count+"&callback=?";
//Variable to get around scope problem in callback function.
var holder = this;
//Contact Twitter
$.getJSON(url,
//This function is called when twitter responds with the appropriate information.
function(data){
//Step through each tweet.
$.each(data, function(i, item) {
//place the tweet within a paragraph tag within the main div.
holder.append("<p>"+item.text.makeLinks()+"</p>");
});
});
}
else{
//IF Username paramater has not been set.
console.debug("jquery plugin twitterize requires a username! Check your parameters");
}
//MAKE LINKS
String.prototype.makeLinks = function() {
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(str) {
return str.link(str);
});
};
$(document).ready(function() {
//Calling Twitterize - Assigning to Element and User
$('#tweets').twitterize('username');
});
<div id="tweets"></div>
1