/
twitter.js
32 lines (25 loc) · 1.04 KB
/
twitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var twitterPictures = new Array();
function refreshTwitter(){
$.get("getTwitter.php").done(function(data){
twitterPictures = new Array();
var tweets = jQuery.parseJSON(data);
console.log("Amount of tweets: " + tweets.length);
for (var i = 0; i < tweets.length ; i++){
console.log("adding twitter image: "+ i);
twitterPictures[i] =( "<img src='" + tweets[i].image +"' ></img><br/>"
+"<div class='social_username'><img class='social_username' src=" + tweets[i].profile_picture+ "></img> @"
+ tweets[i].user + "</div><br/>"
+ tweets[i].text);
}
});
}
var currentTweet = 0;
function rotateTweet(){
if(twitterPictures.length > 0){ //added this as the pictures may still be loading on first run
console.log ("shown tweet" + currentTweet + "of "+ twitterPictures.length);
$(".instagram_logo").hide();
$(".twitter_logo").show();
$(".social").html(twitterPictures[currentTweet]);
currentTweet = (currentTweet==twitterPictures.length-1) ? 0 : currentTweet + 1;
}
}