(function ($){
$.fn.tweetscroll=function (options){
var defaults={
visible_tweets: 10,
username: 'shuttlethemes',
time: false,
replies: false,
date_format: 'style1',
color: 'blue',
};
var tweetscrollOptions=$.extend({}, defaults, options);
tweetscrollOptions['instance_id']=$(this).attr('data-instance-id');
if(!tweetscrollOptions['instance_id'])
tweetscrollOptions['instance_id']="";
tweetscrollOptions['action']='shuttle_widget_tweetscroll_ajax';
return this.each(function (options){
var act=$(this);
var $allTweets;
var requestURL=PiTweetScroll.ajaxrequests;
if(jQuery.isArray(tweetscrollOptions.username)){
var numOfUsers=tweetscrollOptions.username.length;
var tweetsCount, $tweetList;
var restTweets=(tweetscrollOptions.visible_tweets - (Math.floor(tweetscrollOptions.visible_tweets / numOfUsers) * numOfUsers));
var tweetsPerUser=Math.floor(tweetscrollOptions.visible_tweets / numOfUsers);
$allTweets=$('<ul class="tweet-feed">');
jQuery.each(tweetscrollOptions.username, function(index, val){
if(restTweets > 0){
tweetsCount=tweetsPerUser + 1;
restTweets--;
}else{
tweetsCount=tweetsPerUser;
}
$.getJSON(requestURL, tweetscrollOptions, function (data){
$tweetList=createHtml(data, tweetscrollOptions);
$tweetList.find('li').appendTo($allTweets);
if(index==numOfUsers - 1){
$($allTweets).appendTo(act);
setInitialListHeight($allTweets);
/*setInterval(function(){
animateTweets($allTweets);
}, 3000);*/
}});
});
}else{
$.getJSON(requestURL, tweetscrollOptions, function (data){
$allTweets=createHtml(data, tweetscrollOptions);
$($allTweets).appendTo(act);
setInitialListHeight($allTweets);
/*setInterval(function(){
animateTweets($allTweets);
}, 3000);*/
});
}
function setInitialListHeight($allTweets){
var containerSize=0;
}});
function createHtml(data, tweetscrollOptions){
var $tweetList;
var tweetMonth='';
var shortMonths=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var allMonths=["January","February","March","April","May","June","July","August","Septemper","October","November","December"];
$.each(data, function (i, item){
if(i==0){
$tweetList=$('<ul class="tweet-feed ' + tweetscrollOptions.color + '">');
}
if(tweetscrollOptions.replies===false){
if(item.in_reply_to_status_id===null){
$tweetList.append('<li class="tweet-content"><p class="twitter-tweet-' + i + '">' + item.text.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$&" target="_blank" >$&</a> ').replace(/#(.*?)(\s|$)/g, '<a href="http://twitter.com/search?q=%23$1&src=hash" target="_blank" >#$1 </a>').replace(/@(.*?)(\s|\(|\)|$)/g, '<a href="http://twitter.com/$1" target="_blank" >@$1 </a>$2')+'</p></li>');
}}else{
$tweetList.append('<li class="tweet-content"><p class="twitter-tweet-' + i + '">' + item.text.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$&" target="_blank" >$&</a> ').replace(/#(.*?)(\s|$)/g, '<a href="http://twitter.com/search?q=%23$1&src=hash" target="_blank" >#$1 </a>').replace(/@(.*?)(\s|\(|\)|$)/g, '<a href="http://twitter.com/$1" target="_blank" >@$1 </a>$2') + '</p></li>');
}
if(tweetscrollOptions.time==true){
var monthIndex=jQuery.inArray(item.created_at.substr(4, 3), shortMonths);
if(tweetscrollOptions.date_format=='style1'){
tweetMonth=monthIndex + 1;
if(tweetMonth < 10){
tweetMonth='0' + tweetMonth;
}
$tweetList.find('.twitter-tweet-' + i).append('<small> ' + item.created_at.substr(8, 2) + '/' + tweetMonth + '/' + item.created_at.substr(26,4) + '</small>');
}else{
tweetMonth=allMonths[monthIndex];
$tweetList.find('.twitter-tweet-' + i).append('<small> ' + tweetMonth + ' ' + item.created_at.substr(8, 2) + ' ' + item.created_at.substr(26,4) + '</small>');
}}
});
return $tweetList;
}}
})(jQuery);