-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
56 lines (50 loc) · 1.86 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$(document).ready(function(){
var count = streams.home.length - 1;
var allTweets = $('#tweetbox-all')
var individualTweets = $('#tweetbox-user')
//hide single twittler users box on start up
individualTweets.hide()
//tweet retrieval function
var fetchTweets = function(start,end,data,location){
for(var i = start; i < end; i++){
var tweet = data[i]
var user = $('<article class="panel-heading"><a class="users" href="#"></a></div>');
var post = $('<article class="panel-body"></div>');
//'Posted about x time ago'
var time = $('<article class="text-muted" id="timestamp" data-livestamp="'+ tweet.created_at +'"></span>');
user.children().text("@" + tweet.user);
post.text(tweet.message)
location.prepend(post);
location.prepend(time)
location.prepend(user);
}
};
//get default tweets
fetchTweets(0,count + 1,streams.home,allTweets)
//refreshes twittler feed every four seconds
setInterval(function(){
var currentCount = streams.home.length;
if(currentCount > count){
fetchTweets(count + 1,currentCount,streams.home,allTweets)
count = currentCount;
}
},4000);
//handles user click event
$("#tweetbox-all").on("click",".users",function(){
//hides all tweets
$("#tweetbox-all").hide()
//shows @user's tweets
$("#tweetbox-user").show()
var singleUser = ($(this).text().split("").slice(1).join(""))
var userData = streams.users[singleUser]
console.log(userData[0])
$(".navInfo").text($(this).text() +"'s tweets").append("<br><br><a id='allTweets' href='#'>View all tweets</a>")
fetchTweets(0,userData.length,userData,individualTweets);
})
//navigates to twittler feed
$("#infoBox").on("click","#allTweets",function(){
$("#tweetbox-user").children().remove();
$("#tweetbox-all").show();
$(".navInfo").text("All tweets")
})
});