﻿// This is a self invoking function. // The $ parameter allows you to reference the jQuery item.(function($) {// fn is essentially the same as prototype.// so this will be used like $('#jqueryItem).twitterize(username)$.fn.twitterize = function(username,options) {		//check to see if the username has been set.	if (username) {				//create an object full of your default settings.		var defaultSettings = {			count:'1'		}				// 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;				$.getJSON(url,				//This function is called when twitter responds with the appropriate information.		function(data) {						holder.append("<table id='twitter'>");			$('#twitter').append("<tr id='twitterHeaderRow'>");			$('#twitterHeaderRow').append("<th id='twitterTweetHeader'>");			$('#twitterTweetHeader').append("<a href='http://twitter.com/#!/kimasendorf' target='_blank'>@kimasendorf</a>");			$('#twitterHeaderRow').append("<th id='twitterDateHeader'>");			$('#twitterDateHeader').append("Date");						//Step through each tweet.			$.each(data, function(i, item) {								var date = new Date(item.created_at);								$('#twitter').append("<tr id='tweetRow"+ i +"'>");				$('#tweetRow'+ i).append("<td id='tweet"+ i +"'>");				//place the tweet within a paragraph tag.				$('#tweet'+ i).append(item.text.makeLinks());				$('#tweetRow'+ i).append("<td id='date"+ i +"'>");				$('#date'+ i).append("<a href='http://twitter.com/#!/kimasendorf/status/"+ item.id_str +"' target='_blank'>"+ date.getFullYear() +"-"+ (date.getMonth()+1) +"-"+ date.getDate() +" "+ date.getHours() +":"+ date.getMinutes() +":"+ date.getSeconds() +"</a>");			});		});	    	}else{		//Username paramater hasn't been set.		console.debug("jquery plugin twitterize requires a username! Check your parameters");	}		//Changes urls within the tweet into 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);		});	};	//Return itselfreturn this;};// We pass "jQuery" to the self invoking function// so we can use whatever alias of jQeury that we like.// So instead of "$" you could also use any other// valid JavaScript variable name.})(jQuery);
