-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscripts_ui.js
executable file
·136 lines (114 loc) · 6.31 KB
/
transcripts_ui.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
(function ($) {
Drupal.behaviors.scrollingTranscript = {
attach: function (context, settings) {
$('[data-transcripts-role=transcript]', context)
.addBack('[data-transcripts-role=transcript]')
.once('scrolling-transcript')
.each(function () {
var scroller = ScrollingTranscript.getUI($(this));
scroller.setContainer($(this).parents('.transcript-container'));
kWidget.addReadyCallback(function (playerId) {
//assuming HTML5 video API
//var $iframe = $('.kaltura-embed iframe').first().contents();
//scroller.setVideo($('video,audio', $iframe).attr('preload', 'metadata')[0]);
//if using Kaltura API abstraction
var kaltura = {
playingThrough: true,
playerPlaying: false,
setVideo: function (vid) {
var init = false;
var jump = $.param.fragment();
if (jump != '') {
var volume = vid.evaluate('{video.volume}');
var $tcu = $('#' + jump.replace('tcu/', ''));
vid.kBind('playerSeekEnd.init', function () {
if (!init) {
vid.sendNotification('changeVolume', volume);
init = true;
}
});
vid.kBind('mediaReady.init', function () {
if (!init) {
vid.sendNotification('changeVolume', 0);
vid.sendNotification('doSeek', $tcu.attr('data-begin'));
}
});
this.setOne($tcu);
this.container.scrollTo($tcu);
}
else {
var $first = this.starts[0].$item;
this.container.scrollTo($first);
this.sweetSpot = $first.position().top;
init = true;
}
var that = this;
vid.kBind('playerPlayed', function () {
that.playerPlaying = true;
that.togglePlay('play');
if (that.playingThrough) {
vid.kBind('playerUpdatePlayhead.playThrough', function (now, id) {
that.checkScroll(now);
});
}
});
vid.kBind('playerPaused', function () {
that.playerPlaying = false;
that.togglePlay('pause');
that.unbindPlayListener(true);
});
this.player = vid;
},
playPause: function() {
this.player.sendNotification(this.playerPlaying ? 'doPause' : 'doPlay');
},
unbindPlayListener: function(newThrough) {
this.player.kUnbind(this.playingThrough ? '.playThrough' : '.playOne');
this.playingThrough = newThrough;
},
playOne: function ($tcu, noscroll, begin, end) {
var vid = this.player;
//to support transcript editing where times could be modified
if (begin === undefined) begin = parseFloat($tcu.attr('data-begin'));
if (end === undefined) end = parseFloat($tcu.attr('data-end'));
var seekStarted = false;
var seekEnded = false;
var pauseStarted = false;
this.unbindPlayListener(false);
vid.kBind('playerSeekEnd.playOne', function () {
if (!seekEnded) {
seekEnded = true;
}
});
vid.kBind('playerUpdatePlayhead.playOne', function (now, id) {
if (!seekStarted) {
seekStarted = true;
vid.sendNotification('doSeek', begin);
}
else if (!pauseStarted) {
if (now > end) {
pauseStarted = true;
vid.sendNotification('doPause');
}
}
});
this.endAll();
if (this.resetSweet) {
this.sweetSpot = $tcu.position().top;
}
this.setOne($tcu, noscroll);
this.playingThrough = false;
vid.sendNotification('doPlay');
},
setCurrentTime: function(seconds) {
this.player.sendNotification('doSeek', seconds);
}
};
$.extend(scroller, kaltura);
scroller.setVideo(document.getElementById(playerId));
Drupal.settings.scrollingTranscript[scroller.trid] = scroller;
});
});
}
};
})(jQuery);