forked from christabor-archive/metal-gear-codec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgs-player.js
63 lines (52 loc) · 1.34 KB
/
mgs-player.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
/*!
* Metal Gear Solid Codec.
* (c) 2013 Chris Tabor <[email protected]>
* See license for more information
* <3
* https://github.com/christabor/metal-gear-codec/
*/
;(function($){
$.fn.mgsCodec = function(options) {
var defaults = {
interval_speed: 300,
animation_timeout: 1500,
transcription: '.transcription p'
},
opts = $.extend(defaults, options),
self = this,
notes = this.find(opts.transcription),
current_note = 0,
volume_indicator = this.find('#svg-volume-indicator-total'),
max_volume = volume_indicator.height();
notes.hide();
this.find('img').hide();
function triggerClick() {
// advance dialogue to next note
notes.eq(current_note).fadeIn(200);
// hide previous
notes.eq(current_note).prevAll().hide(100);
// increment forward
current_note += 1;
return;
}
function animateCodecBar() {
// randomize the height of the bar to simulate volume
volume_indicator.height(Math.random()*max_volume);
return;
}
function init() {
self.find('img').each(function(k, elem){
var _elem = $(elem);
_elem.fadeIn(400);
});
// show first note
notes.eq(0).show();
self.on('click', triggerClick);
setTimeout(function(){
setInterval(animateCodecBar, opts.interval_speed);
}, opts.animation_timeout);
return;
}
this.hide().slideToggle(200, init);
};
})(jQuery);