1 var topicPoubelle = 13; |
1 var topicPoubelle = 13; |
2 |
2 |
3 var adjust = 54; |
3 var adjust = 54; |
4 |
4 |
5 var deltaT = new Date("Wed, 02 May 2012 19:00:00 +0000") / 1000 + adjust; |
5 var deltaT = new Date("Wed, 02 May 2012 19:00:00 +0000") / 1000 + adjust; |
|
6 |
|
7 function secsToString(seconds) { |
|
8 var hours = Math.floor(seconds/3600), |
|
9 minutes = Math.floor(seconds/60) % 60, |
|
10 secs = Math.floor(seconds % 60); |
|
11 function pad(n) { |
|
12 var r = n.toString(); |
|
13 while (r.length < 2) { |
|
14 r = "0" + r; |
|
15 } |
|
16 return r; |
|
17 } |
|
18 return (hours ? (hours + ":") : "") + pad(minutes) + ":" + pad(secs); |
|
19 } |
6 |
20 |
7 function solrUrl(table, params) { |
21 function solrUrl(table, params) { |
8 var u = "http://159.217.144.101:8050/sia-solr/" + table + "/select?" + $.param(params) + "&wt=json&json.wrf=?"; |
22 var u = "http://159.217.144.101:8050/sia-solr/" + table + "/select?" + $.param(params) + "&wt=json&json.wrf=?"; |
9 console.log(u); |
23 console.log(u); |
10 return u; |
24 return u; |
11 } |
25 } |
12 |
26 |
13 function showData() { |
27 function showData() { |
14 |
28 |
|
29 data.chapters = []; |
|
30 |
|
31 data.segments.forEach(function(segment, index) { |
|
32 var topics = segment.topics.filter(function(t) { |
|
33 return t.topic !== topicPoubelle; |
|
34 }).map(function(t) { |
|
35 return t.topic |
|
36 }); |
|
37 var openchapters = data.chapters.filter(function(c) { |
|
38 return c.open; |
|
39 }); |
|
40 openchapters.forEach(function(c) { |
|
41 var i = topics.indexOf(c.topic); |
|
42 if (i == -1) { |
|
43 c.open = false; |
|
44 } else { |
|
45 c.endMMSO = index; |
|
46 c.endTime = segment.end; |
|
47 topics.splice(i, 1); |
|
48 } |
|
49 }); |
|
50 |
|
51 if (topics.length) { |
|
52 topics.forEach(function(t) { |
|
53 data.chapters.push({ |
|
54 startMMSO: index, |
|
55 endMMSO: index, |
|
56 startTime: segment.start, |
|
57 endTime: segment.end, |
|
58 topic: t, |
|
59 open: true |
|
60 }) |
|
61 }) |
|
62 } |
|
63 }); |
|
64 |
15 data.topiclabels.forEach(function(v) { |
65 data.topiclabels.forEach(function(v) { |
16 var words = _(v.words).map(function(v, k) { |
66 var words = _(v.words).map(function(v, k) { |
17 return { |
67 return { |
18 word: k, |
68 word: k, |
19 weight: v |
69 weight: v |
47 var s = p.split('='); |
97 var s = p.split('='); |
48 pageParams[s[0]] = s[1].split(",").map(function(t) { return decodeURIComponent(t)}); |
98 pageParams[s[0]] = s[1].split(",").map(function(t) { return decodeURIComponent(t)}); |
49 }) |
99 }) |
50 |
100 |
51 var ordertag = 0; |
101 var ordertag = 0; |
52 |
|
53 function secsToString(seconds) { |
|
54 var hours = Math.floor(seconds/3600), |
|
55 minutes = Math.floor(seconds/60) % 60, |
|
56 secs = Math.floor(seconds % 60); |
|
57 function pad(n) { |
|
58 var r = n.toString(); |
|
59 while (r.length < 2) { |
|
60 r = "0" + r; |
|
61 } |
|
62 return r; |
|
63 } |
|
64 return (hours ? (hours + ":") : "") + pad(minutes) + ":" + pad(secs); |
|
65 } |
|
66 |
102 |
67 $(".duration").text(secsToString(data.duration)); |
103 $(".duration").text(secsToString(data.duration)); |
68 |
104 |
69 var nmmso = data.segments.length; |
105 var nmmso = data.segments.length; |
70 |
106 |
118 var topics = Array.prototype.slice.call( |
154 var topics = Array.prototype.slice.call( |
119 $(".topic.selected").map(function() { |
155 $(".topic.selected").map(function() { |
120 return parseInt($(this).attr("data-topic-id")); |
156 return parseInt($(this).attr("data-topic-id")); |
121 }) |
157 }) |
122 ); |
158 ); |
123 for (var i = 0; i < data.segments.length; i++) { |
159 for (var i = 0; i < data.chapters.length; i++) { |
124 var mmso = data.segments[i]; |
160 var chap = data.chapters[i]; |
125 if (mmso.start >= player.currentTime && hasTopics(mmso, topics)) { |
161 if (chap.startTime > player.currentTime && topics.indexOf(chap.topic) !== -1) { |
126 player.setCurrentTime(mmso.start); |
162 player.setCurrentTime(chap.startTime); |
|
163 throttledShowLocal(); |
|
164 return; |
|
165 } |
|
166 } |
|
167 /* If next not found, loop around ! */ |
|
168 for (var i = 0; i < data.chapters.length; i++) { |
|
169 var chap = data.chapters[i]; |
|
170 if (topics.indexOf(chap.topic) !== -1) { |
|
171 player.setCurrentTime(chap.startTime); |
|
172 throttledShowLocal(); |
|
173 return; |
|
174 } |
|
175 } |
|
176 } |
|
177 |
|
178 function goToPrev() { |
|
179 var topics = Array.prototype.slice.call( |
|
180 $(".topic.selected").map(function() { |
|
181 return parseInt($(this).attr("data-topic-id")); |
|
182 }) |
|
183 ); |
|
184 for (var i = data.chapters.length; i--;) { |
|
185 var chap = data.chapters[i]; |
|
186 if (chap.startTime < (player.currentTime - 2) && topics.indexOf(chap.topic) !== -1) { |
|
187 player.setCurrentTime(chap.startTime); |
|
188 throttledShowLocal(); |
|
189 return; |
|
190 } |
|
191 } |
|
192 /* If previous not found, loop around ! */ |
|
193 for (var i = data.chapters.length; i--;) { |
|
194 var chap = data.chapters[i]; |
|
195 if (topics.indexOf(chap.topic) !== -1) { |
|
196 player.setCurrentTime(chap.startTime); |
127 throttledShowLocal(); |
197 throttledShowLocal(); |
128 return; |
198 return; |
129 } |
199 } |
130 } |
200 } |
131 } |
201 } |
500 var tweetTemplate = _.template( |
570 var tweetTemplate = _.template( |
501 '<li class="tweet" data-timestamp="<%= timestamp %>" data-topic-id="<%= topic.topic %>">' |
571 '<li class="tweet" data-timestamp="<%= timestamp %>" data-topic-id="<%= topic.topic %>">' |
502 + '<% if (show_link) { %><a href="#" data-user-id="<%- data.from_user_id %>"><% } %>' |
572 + '<% if (show_link) { %><a href="#" data-user-id="<%- data.from_user_id %>"><% } %>' |
503 + '<img src="<%- data.profile_image_url %>" /><% if (show_link) { %></a><% } %>' |
573 + '<img src="<%- data.profile_image_url %>" /><% if (show_link) { %></a><% } %>' |
504 + '<p><% if (show_link) { %><a href="#" data-user-id="<%- data.from_user_id %>"><% } %>' |
574 + '<p><% if (show_link) { %><a href="#" data-user-id="<%- data.from_user_id %>"><% } %>' |
505 + '@<%- data.from_user_name %>:<% if (show_link) { %></a><% } %> <%= htext %></p></li>'), |
575 + '@<%- data.from_user_name %>:<% if (show_link) { %></a><% } %> <%= htext %></p>' |
|
576 + '<% if (show_time) { %><p><%- secsToString(timestamp) %></p><% } %>' |
|
577 + '</li>'), |
506 callnum = 0, |
578 callnum = 0, |
507 tweetstructure = {}, |
579 tweetstructure = {}, |
508 requestedtweets = {}, |
580 requestedtweets = {}, |
509 _NTWEETS = 50, |
581 _NTWEETS = 50, |
510 selectedWord = false; |
582 selectedWord = false; |
561 |
633 |
562 if (tweetstoshow.length < 8) { |
634 if (tweetstoshow.length < 8) { |
563 var randtweets = data.randomtweets.filter(function(tw) { |
635 var randtweets = data.randomtweets.filter(function(tw) { |
564 return (tw.timestamp > (localpos - localduration / 2)) && (tw.timestamp < (localpos + localduration / 2)) |
636 return (tw.timestamp > (localpos - localduration / 2)) && (tw.timestamp < (localpos + localduration / 2)) |
565 }); |
637 }); |
|
638 if (selectedWord) { |
|
639 var rx = new RegExp(selectedWord.replace(/(\W)/gm,'\\$1'),'im'); |
|
640 randtweets = randtweets.filter(function(tw) { |
|
641 return rx.test(tw.data.text); |
|
642 }); |
|
643 } |
566 var mod = Math.ceil(randtweets.length / 8); |
644 var mod = Math.ceil(randtweets.length / 8); |
567 randtweets = randtweets.filter(function(v,k) { |
645 randtweets = randtweets.filter(function(v,k) { |
568 return !(k % mod); |
646 return !(k % mod); |
569 }); |
647 }); |
570 tweetstoshow = tweetstoshow.concat(randtweets); |
648 tweetstoshow = tweetstoshow.concat(randtweets); |
753 var player = new Player(); |
832 var player = new Player(); |
754 |
833 |
755 player.duration = data.duration; |
834 player.duration = data.duration; |
756 |
835 |
757 player.on("play", function() { |
836 player.on("play", function() { |
758 $(".play-button").html("▐ ▌"); |
837 $(".play-button").attr("title","Pause").addClass("playing"); |
759 }); |
838 }); |
760 player.on("pause", function() { |
839 player.on("pause", function() { |
761 $(".play-button").text("▶"); |
840 $(".play-button").attr("title","Lecture").removeClass("playing"); |
762 }); |
841 }); |
763 player.on("timeupdate", function(t) { |
842 player.on("timeupdate", function(t) { |
764 playTime.text(secsToString(t)); |
843 playTime.text(secsToString(t)); |
765 globalIndic.css("top", yscale * t); |
844 globalIndic.css("top", yscale * t); |
766 if (localyscale) { |
845 if (localyscale) { |
777 if (player.paused) { |
856 if (player.paused) { |
778 player.play(); |
857 player.play(); |
779 } else { |
858 } else { |
780 player.pause(); |
859 player.pause(); |
781 } |
860 } |
|
861 return false; |
782 }); |
862 }); |
783 |
863 |
784 $(".next-button").click(goToNext); |
864 $(".next-button").click(function() { |
785 |
865 goToNext(); |
|
866 return false; |
|
867 }); |
|
868 |
|
869 $(".prev-button").click(function() { |
|
870 goToPrev(); |
|
871 return false; |
|
872 }); |
|
873 |
786 $(".topics-block").on("mouseenter", ".topic", function() { |
874 $(".topics-block").on("mouseenter", ".topic", function() { |
787 var el = $(this); |
875 var el = $(this); |
788 el.addClass("hover"); |
876 el.addClass("hover"); |
789 showTopicViz(); |
877 showTopicViz(); |
790 }).on("mouseleave", ".topic", function() { |
878 }).on("mouseleave", ".topic", function() { |
920 timestamp: tweet.timestamp, |
1008 timestamp: tweet.timestamp, |
921 topic: {topic: -1}, |
1009 topic: {topic: -1}, |
922 weight: 0, |
1010 weight: 0, |
923 data: tweet, |
1011 data: tweet, |
924 htext: _(tweet.text).escape(), |
1012 htext: _(tweet.text).escape(), |
925 show_link: false |
1013 show_link: false, |
|
1014 show_time: true |
926 }); |
1015 }); |
927 },""); |
1016 },""); |
928 $(".user-tweets").show(); |
1017 $(".user-tweets").show(); |
929 $(".user-tweets-list").html(html); |
1018 $(".user-tweets-list").html(html); |
930 $(".user-name").text(tweets[0].from_user_name); |
1019 $(".user-name").text(tweets[0].from_user_name); |