/
panels.js
40 lines (35 loc) · 1.04 KB
/
panels.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
define([
"flight/component",
"text!templates/panel.html",
], function ( defineComponent, panelTemplate ) {
"use strict";
return defineComponent( panels );
function panels () {
panelTemplate = _.template( panelTemplate );
this.after( "initialize", function () {
this.on( document, "dataPicture", this.loadPanel );
this.on( document, "dataSound", this.loadPanel );
this.on( document, "dataSoundOver", this.hide );
this.trigger( "uiNeedsPicture" );
});
this.loadPanel = function ( event, data ) {
var panel = $( panelTemplate( data ) );
// data has a .type of "picture" or "sound", making this easier:
var target = $( ".panel." + data.type );
if ( target.length ) {
target.children().fadeOut( 2400 );
target.replaceWith( panel )
target.children().fadeIn( 2400 )
} else {
panel.css( "display", "none" );
$( "body" ).append( panel );
panel.fadeIn( 1000 );
}
}
this.hide = function ( event, data ) {
$( ".panel" ).fadeOut(function () {
this.remove();
});
}
}
});