/
pictures.js
65 lines (57 loc) · 1.51 KB
/
pictures.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
define([
"flight/component",
"text!templates/slide.html",
], function ( defineComponent, slideTemplate ) {
"use strict";
return defineComponent( slide );
function slide () {
var body = $( "body" );
var sfw, delay, playing, first, timeout;
this.after( "initialize", function () {
this.on( document, "dataPicture", this.picture );
this.on( document, "dataSoundInfo", this.sound );
this.on( document, "dataSoundOver", this.soundOver );
this.on( document, "uiUserWantsToStart", this.getStarted );
});
this.getStarted = function ( event, data ) {
// filth mode
//sfw = data.swf;
sfw = true;
}
this.picture = function ( event, data ) {
var next = $( _.template( slideTemplate, data ) );
var fly = this;
if ( first ) {
first = false;
body.append( next.fadeIn( 1000 ) );
} else {
var previous = body.find( ".slide" );
body.append( next.fadeIn( 2000 ) );
previous.fadeOut( 2000, function () {
this.remove();
});
}
if ( playing ) {
timeout = setTimeout(function () {
fly.trigger( document, "uiNeedsPicture", { sfw: sfw } );
}, delay);
}
}
this.sound = function ( event, data ) {
playing = first = true;
if ( data.bpm ) {
// if there is a bpm, let's set the timeout to 4 bars.
delay = ( data.bpm / 60 * 4000 );
} else {
delay = 10000;
}
this.trigger( document, "uiNeedsPicture", {
sfw: sfw
});
}
this.soundOver = function () {
playing = false;
window.clearTimeout( timeout );
}
}
})