clr commited on
Commit
11dee72
1 Parent(s): 64fb01f

Create js/js.php

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