clr commited on
Commit
3a1d650
1 Parent(s): 5d22013

Create js.php

Browse files
Files changed (1) hide show
  1. js/js.php +117 -0
js/js.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* --------------------------------------------------*/
2
+ /* ------------- MEDIA PLAYBACK ----------------- */
3
+ /* ---------------------https://web.archive.org/web/20220121094229/ */
4
+ /* https://childes.talkbank.org/browser/index.php?url=Eng-UK/MPI-EVA-Manchester/Eleanor/020006b.cha */
5
+ /*-----------------------------*/
6
+ $(function (){
7
+
8
+ // Add "timeupdate" listener to "#speakera".
9
+ var vid = document.getElementById("speakera");
10
+ vid.addEventListener("timeupdate", function(){
11
+ updatePosition(this.currentTime);
12
+ });
13
+
14
+ // Listen for user to pause video.
15
+ vid.addEventListener("pause", function(){
16
+ $( '.movControl' ).html("&#9654"); // Change all bullets to "play".
17
+ });
18
+
19
+ // Listen for user to play video. ** i added this
20
+ vid.addEventListener("play", function(){
21
+ $( '.movControl' ).html("&#9632"); // Change all bullets to "stop".
22
+ });
23
+
24
+
25
+ // Click on utterance line.
26
+ $("body").on('click', 'span[name=utterance]',
27
+ function(event) {
28
+ var vid = document.getElementById("speakera");
29
+
30
+ // If user clicked "stop" on a playing line, pause video, remove ".playing", change icon to "play".
31
+ if(!vid.paused) {
32
+ vid.pause();
33
+ }
34
+
35
+ else {
36
+ var newTime = $(this).attr("beg");
37
+ vid.currentTime = newTime / 1000;
38
+ // currentTime needs to be in SEC
39
+
40
+ vid.play();
41
+
42
+ var segmentDur = $(this).attr("end") - newTime
43
+ // segmentDur needs to be in MS
44
+
45
+ setTimeout(function(){
46
+ document.getElementById('speakera').pause();
47
+ }, segmentDur);
48
+
49
+ }
50
+
51
+ }
52
+ );
53
+
54
+
55
+ getIntervals();
56
+ });
57
+
58
+
59
+
60
+ // Create "intervals[]" from each <span name="utterance"> using its beg/end to get the begin/end times.
61
+ var intervals = [];
62
+ function getIntervals() {
63
+ $( 'span[name=utterance]' ).each(function( index ) {
64
+ intervals.push({"begin": $( this ).prop('beg'), "end": $( this ).prop('end')});
65
+ });
66
+ }
67
+
68
+
69
+
70
+
71
+ // Set $ref as not playing.
72
+ function notPlaying($ref) {
73
+ $ref.removeClass('uttPlaying');
74
+ $ref.children(".movControl").html("&#9654;"); // Show "play" icon.
75
+ $ref.children(".movControl").removeClass("playing");
76
+ }
77
+
78
+ // Set $ref as playing.
79
+ function isPlaying($ref) {
80
+ $ref.addClass('uttPlaying');
81
+ $ref.children(".movControl").html("&#9632;"); // Show "stop" icon.
82
+ $ref.children(".movControl").addClass("playing");
83
+ }
84
+
85
+
86
+ // Returns true if $elem is beyond the current scrolled view.
87
+ function isScrolledOutOfView($elem) {
88
+ var $window = $(window);
89
+
90
+ var windowTop = $window.scrollTop();
91
+ var windowBottom = windowTop + $window.height();
92
+
93
+ var elemTop = $elem.offset().top;
94
+ var elemBottom = elemTop + $elem.height();
95
+
96
+ return ((elemBottom > windowBottom) || (elemTop < windowTop));
97
+ }
98
+
99
+ // Callback function for timeupdate event.
100
+ function updatePosition( currentTime ) {
101
+ var msTime = currentTime * 1000;
102
+
103
+ for ( c = 0; c < intervals.length; c++ ) {
104
+ if ((msTime >= intervals[c].begin) && (msTime < intervals[c].end)) {
105
+ notPlaying($( 'span[name=utterance]' )); // Mark everything as "not playing".
106
+ isPlaying($( '#' + intervals[c].begin )); // Mark line corresponding to currentTime as "playing".
107
+
108
+ // Auto-scroll if playing line is out of view.
109
+ if (isScrolledOutOfView($('.playing'))) {
110
+ $('html, body').animate({
111
+ scrollTop: ($(".playing").offset().top - ($(window).height() / 2))
112
+ }, 500);
113
+ }
114
+ }
115
+ //$( 'span[name=utterance]' ).removeClass('uttPlaying'); // No interval defined at currentTime.
116
+ }
117
+ }