Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/html/entry.js
blob: 5107cd816a76fde211fa1ccd1ee4f8716e994f17 (plain)
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
// Entry component with image, text and sound
enyo.kind({
	name: "Abcd.Entry",
	kind: "Abcd.Item",
	published: { index: "", imageonly: false, textonly: false, soundonly: false },
	classes: "entry",
	components: [
		{ name: "spinner", kind: "Image", src: "images/spinner-light.gif", classes: "spinner"},	
		{ name: "contentBox", showing: false, components: [
			{ name: "itemImage", classes: "entryImage", kind: "Image", onload: "imageLoaded" },
			{ name: "soundIcon", kind: "Image", classes: "entrySoundIcon" },
			{ name: "itemText", classes: "entryText" }
		]},
		{kind: "Signals", onEndOfSound: "endOfSound"}		
	],
	events: {
		onEntrySoundEnded: ""
	},
	
	// Constructor
	create: function() {
		this.inherited(arguments);
		this.sound = null;
		this.imageonlyChanged();
		this.textonlyChanged();
		this.soundonlyChanged();
		this.indexChanged();		
	},
	
	// Display only when image is load
	imageLoaded: function() {
		if (this.index !== "") {
			this.$.spinner.hide();
			this.$.contentBox.show();
		}
	},
	
	// Unique visibility options
	imageonlyChanged: function() {
		if (this.imageonly)
			Abcd.changeVisibility(this, {itemImage: true, soundIcon: false, itemText: false});
	},
	
	textonlyChanged: function() {
		if (this.textonly)
			Abcd.changeVisibility(this, {itemImage: false, soundIcon: false, itemText: true});
	},
	
	soundonlyChanged: function() {
		if (this.soundonly)
			Abcd.changeVisibility(this, {itemImage: false, soundIcon: true, itemText: false});
	},
	
	// Localization changed, update text & sound 
	setLocale: function() {
		this.indexChanged();
		this.inherited(arguments);
	},
	
	// Card setup
	indexChanged: function() {
		// Get content
		var entry = Abcd.entries[this.index];
		var image = "images/database/"+entry.code+".png";
		var text = __$FC(entry.text);
		if (Abcd.context.casevalue == 1)
			text = text.toUpperCase();
			
		// Get sound
		if (this.soundonly) this.$.soundIcon.addClass("entrySoundIconOnly");		
		if (entry[Abcd.context.lang]) {
			this.sound = "audio/"+Abcd.context.lang+"/database/"+entry.code;
			this.$.soundIcon.setSrc("images/sound_off"+(this.soundonly?1:0)+".png");
		} else {
			this.sound = null;
			this.$.soundIcon.setSrc("images/sound_none"+(this.soundonly?1:0)+".png");
		}
		
		// Display all
		this.$.itemImage.setAttribute("src", image);
		this.$.itemText.removeClass("entryText0");
		this.$.itemText.removeClass("entryText1");
		this.$.itemText.removeClass("entryText2");
		this.$.itemText.addClass("entryText"+Abcd.context.casevalue);
		if (this.imageonly) this.$.itemImage.addClass("entryImageOnly");
		this.$.itemText.setContent(text);
		if (this.textonly) this.$.itemText.addClass("entryTextOnly");
	},
	
	// Play sound using the media
	play: function(media) {
		if (this.sound != null) {
			this.$.soundIcon.setSrc("images/sound_on"+(this.soundonly?1:0)+".png");	
			media.play(this.sound);
		}
	},
	
	endOfSound: function(e, s) {
		if (s == this.sound) {
			this.doEntrySoundEnded();
			this.$.soundIcon.setSrc("images/sound_off"+(this.soundonly?1:0)+".png");
		}
	},

	abort: function() {
		 if (this.$.soundIcon !== undefined)
			this.$.soundIcon.setSrc("images/sound_off"+(this.soundonly?1:0)+".png");	
	}
});