Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / externals / dojo / demos / flashCards / src.js
1 dojo.require("dojo.parser");
2
3 dojo.require("dijit.Dialog");
4 dojo.require("dijit.form.Button");
5 dojo.require("dijit.layout.LayoutContainer");
6 dojo.require("dijit.layout.ContentPane");
7 dojo.require("dojox.analytics.Urchin")
8 dojo.require("demos.flashCards.src.MathFlashCard");
9 dojo.require("demos.flashCards.src.Teacher");
10
11 //global storage point for our fade animations
12 var messageFadeEvent = null;
13
14 //reset the score board
15 var resetScore = function(){
16 var card = dijit.byId("card");
17 dojo.byId("remainingTd").innerHTML = card.numberProblems;
18 dojo.byId("correctTd").innerHTML = 0;
19 dojo.byId("incorrectTd").innerHTML = 0;
20 dojo.byId("tooSlowTd").innerHTML = 0;
21 dojo.style("scoreTable", "display", "");
22 };
23
24 var goodAnswers = ["Great job. Did you know that doing math regularly keeps you sharp?", "Hey, this is correct, did you ever concider joining a math competition?", "I am impressed! Not so many students are good in math, congratulations!"];
25 var indexGood = 0;
26 var countGood = 0;
27
28 var badAnswers = ["Hmm, you are letting me down! Did you practice enough?", "This is wrong, why don't you know such a simple answer?", "I might have to send you back to school, this is not good"];
29 var indexBad = 0;
30
31 var slowAnswers = ["Hmm, I thought you could have beena little faster to be honest", "You could have counted the result on your fingers my friend.", "Slow slow slow, what are we going to do about this?"];
32 var indexSlow = 0;
33
34 var countBad = 0;
35
36 //start the flashcards, result of pressing "getStarted"
37 var getStarted = function(){
38 dijit.byId("teacher").speak("Hi student! Let's go. Just enter the correct results and press enter.");
39
40 //call the card widgets getStarted() method
41 var c = dijit.byId("card");
42 c.getStarted();
43
44 //display(unhide) the card
45 dojo.style(c.domNode,"display","");
46
47 //hide the getStarted Button
48 dojo.style("start", "display", "none");
49
50 //reset the score board
51 resetScore();
52
53 //attach to the onCorrect event of the card. When this event happens
54 //we want to display a fading message and update the score board
55 dojo.connect(c, "onCorrect", function(e){
56 if (messageFadeEvent){
57 messageFadeEvent.stop();
58 }
59
60 countGood++;
61 countBad = 0;
62 if (countGood == 2){
63 dijit.byId("teacher").frown(false);
64 }
65
66 dojo.byId("correctTd").innerHTML = c.correctAnswers;
67
68 if (c.started){
69 dojo.byId("remainingTd").innerHTML = c.numberProblems - c.currentProblem;
70 // FIXME: which node?
71 dojo.removeClass("incorrect");
72 dojo.addClass("correct");
73
74 dijit.byId("teacher").speak(goodAnswers[indexGood], 5000);
75 indexGood++;
76 if (indexGood == goodAnswers.length) { indexGood=0; }
77 }
78 });
79
80 //attach to the onIncorrect event of the card. When this event happens
81 //we want to display a fading message and update the score board
82 dojo.connect(c, "onIncorrect", function(e){
83 if(messageFadeEvent){
84 messageFadeEvent.stop();
85 }
86
87 countBad++;
88 countGood = 0;
89 if (countBad == 2){
90 dijit.byId("teacher").frown(true);
91 }
92
93 dojo.byId("incorrectTd").innerHTML = c.incorrectAnswers;
94
95 if(c.started){
96 dojo.byId("remainingTd").innerHTML = c.numberProblems - c.currentProblem;
97 dojo.addClass("incorrect");
98 dojo.removeClass("correct");
99
100 dijit.byId("teacher").speak(badAnswers[indexBad], 5000);
101 indexBad++;
102 if (indexBad == badAnswers.length) { indexBad=0; }
103 }
104 });
105
106 //attach to the onTooSlow event of the card. When this event happens
107 //we want to display a fading message and update the score board
108 dojo.connect(c, "onTooSlow", function(e){
109 if(messageFadeEvent){
110 messageFadeEvent.stop();
111 }
112
113 countBad++;
114 countGood = 0;
115 if (countBad == 2){
116 dijit.byId("teacher").frown(true);
117 }
118
119 dojo.byId("tooSlowTd").innerHTML = c.tooSlow;
120
121 if(c.started){
122 dojo.byId("remainingTd").innerHTML = c.numberProblems - c.currentProblem;
123 // FIXME: which node?
124 dojo.addClass("incorrect");
125 dojo.removeClass("correct");
126
127 dijit.byId("teacher").speak(slowAnswers[indexSlow], 5000);
128 indexSlow++;
129 if (indexSlow == slowAnswers.length) { indexSlow=0; }
130 }
131
132 });
133
134 //attach to the onEnd event of the card. When this event happens
135 //we want to display a final message,update the score board, and show
136 //the restart button
137
138 dojo.connect(c, "onEnd", function(correct, total, slow){
139 if (messageFadeEvent){
140 messageFadeEvent.stop();
141 }
142
143 //create ending message/summary
144 var msg = "You got " + correct + " out of " + total + " correct.";
145 if(slow > 0){
146 msg += " You were too slow on ";
147 if(slow == 1){
148 msg += "1 problem.";
149 } else {
150 msg += slow + " problems.";
151 }
152 }
153
154 if (c.correctAnswers > 8){
155 dijit.byId("teacher").frown(false);
156 }
157
158 dijit.byId("teacher").speak(msg);
159
160 dojo.style(c.domNode, "display", "none");
161 dojo.style(dojo.byId("restart"), "display", "");
162 dojo.byId("remainingTd").innerHTML = "0";
163
164 });
165
166 //attach to the restart method of the card. We dont' want to reset the
167 //score onEnd since people want a chance to review their score, this won't
168 //happen until they actually click restart
169 dojo.connect(c, "restart", resetScore);
170 };
171
172 //the restart function
173 var restart = function(){
174 dojo.style(dojo.byId("restart"),"display","none");
175 dojo.style(dijit.byId("card").domNode,"display","");
176 dijit.byId("teacher").speak("What a delightful student you are, keep practicing! Your way to success.");
177 dijit.byId("card").restart();
178 };
179
180 dojo.addOnLoad(function(){
181
182 dojo.parser.parse();
183
184 setInterval(function(){
185 dijit.byId("teacher").blink();
186 }, 2500);
187
188 // stall this just a little
189 setTimeout(function(){
190 new dojox.analytics.Urchin({
191 acct: "UA-3572741-1",
192 GAonLoad: function(){
193 this.trackPageView("/demos/flashCards");
194 }
195 });
196 }, 1500);
197
198 });