-
Notifications
You must be signed in to change notification settings - Fork 2
/
scripts.js
executable file
·118 lines (82 loc) · 2.58 KB
/
scripts.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var cTime; //time index
var cycleCount = 0;
var keyFrames = [8, 29, 51, 72, 94]; //in seconds
var flickrImages = [];
var hashtagTweets = [];
$(document).ready(function() {
var video = document.getElementById("player");
video.addEventListener("timeupdate", function() {
if(cTime != parseInt(video.currentTime)){
cTime = parseInt(video.currentTime);
$('#console').html(cTime);
located = $.inArray(cTime, keyFrames);
if(located > -1) {
$.placeImage(flickrImages[located]);
}
}
}, false);
getFlickrImages = function(){
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
{
tags: "drumbeat",
tagmode: "any",
format: "json"
},
function(data) {
$.each(data.items, function(i,item){
bigphoto = (item.media.m).replace("_m.jpg", ".jpg");
flickrImages[i] = $("<img/>").attr("src", bigphoto);
if ( i == 5 ) return false;
});
});
}
var gJs = function(url){
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
head.insertBefore(script, head.firstChild);
}
gJs('http://search.twitter.com/search.json?q=futureofeducation&callback=tCw');
getFlickrImages();
});
var tCw = function (response){
var results = response.results;
$.each(results, function(i, post) {
hashtagTweets[i] = post.text;
});
}
jQuery.placeImage = function (img) {
var image = $('<figure></figure>').appendTo('body');
image.append(img);
var width_body = $('body').width();
var width_image = $(image).width();
var pos_x = (width_body/2) - (width_image/2);
var randomnumber = Math.floor(Math.random()*6);
randomnumber = (randomnumber%2) ? randomnumber : '-'+randomnumber;
$(image).hide().css('left', pos_x);
$(image).fadeIn(1000).delay(4000).fadeOut('slow');
}
jQuery.placeTweet = function(key){
var color = Math.floor(Math.random()*4);
var playerPosition = $('#player').position();
if(key%2 == 0){
var posX = playerPosition.left - 250;
} else {
var posX = playerPosition.left + $('#player').width();
}
var posY=Math.floor(Math.random()*$('body').height());
if(hashtagTweets[key] != undefined){
$('<div />').attr('class', 'tweet'+color).css('top',posY).css('left',posX).appendTo('body').hide().fadeIn('slow').html(hashtagTweets[key]).delay(6000).fadeOut('normal');
}
}
var cycletweets = function(){
len = hashtagTweets.length;
if(cycleCount<len){
cycleCount++;
} else {
cycleCount = 0;
}
$.placeTweet(cycleCount);
setTimeout(cycletweets,4000);
}
setTimeout(cycletweets, 5000);