Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/2_English_What_SomeOne_Is_Doing/js/lesson.js
blob: 9ba65387ee57a29a604d5c7a092de35966aff3a9 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/***** Functions for the game *****/
var i,j,flag;
var box_size = 25;   //size of the drop box for the word banks of exercise
var dragPosition;
var dropPosition;
var randOptions = [];   //store the rand Options for the 15 images
var wordBankNames=new Array("drinking","studying","swimming","singing","chasing","riding","crying","looking","flying","pouring","talking","sweeping","teaching","fighting","dancing");
var lessonImgAnswers = new Array(
						"Preeti is cleaning the house",
						"Preeti is making tea",
						"Preeti is teaching her children",
						"Preeti is cooking food",
						"Preeti is eating",
						"Preeti is working",
						"Preeti is collecting grass",
						"Preeti is feeding cows",
						"Preeti is playing with her children",
						"Preeti is helping her children do school work",
						"Preeti is eating",
						"Preeti is preparing dinner",
						"Preeti is reading a book",
						"Preeti is telling a story to her children",
						"Preeti is sleeping"	
						);
var correctCounter=0;
var box_size = 25;
var exercise_num;   //store the exercise number
var lesson_num;     //store the lesson number
var correctCounter;
var selectedOptionBox;   //value of selectedOptionBox
var lessonImageNo;
var t;

function playSound(surl) {
	document.getElementById('dummyspan').innerHTML="<embed src='assets/audio/"+surl+".ogg' height=0 width=0 autostart=true loop=false>";
}

function delay(){	
	document.delayForm.delayval.value = 1;
	$('#lessonAns').show();
	var soundNo	= lessonImageNo+1;
	playSound(soundNo);
	document.getElementById("lessonAnswers").innerHTML = lessonImgAnswers[lessonImageNo];
}

function lesson_display(lessonImgNo){
	//alert(lessonImgAnswers[lessonImgNo]);
	lessonImageNo = lessonImgNo;
	$('#lessonDisplay').show();   
	$('#lessonAns').hide();
	playSound('what_is_preeti_doing');
	t=setTimeout('delay()',2000);
	//delay for next sound
	
	   
}

function show_gaps(size){
	for(i=0;i<size;i++){
		document.write('&nbsp;');
	}
	
}

function generate_random_no()	{                //generate random number
	var rand_no = Math.floor(15*Math.random());
	return rand_no;
}
function generate_random_positions(){
	randOptions[0]=generate_random_no();  
	for(i=1; i<15; i++){
		do{
			flag = 0;
			randOptions[i] = generate_random_no();
			for(j=0; j<i; j++){
				if(randOptions[i]===randOptions[j]){
					flag++;
				}
			}
		}while(flag != 0 );  //end of do while loop	
	}
	
}
function control_display_exercises(){   //controls the displaying of lesson
	
	if(correctCounter == 3){
		$('a#anchorNext').show();
	}
	if(correctCounter == 6){
		$('a#anchorNext').show();
	}
	if(correctCounter == 9){
		$('a#anchorNext').hide();
		$('a#anchorPrev').hide();
		$('a#anchorPlayAgain').show();
   	}
}

function load_images(){
	generate_random_positions();
	//alert(randOptions);
	var	x;
	for(i=0; i<15; i++){
		x= randOptions[i];
		document.getElementById("imgdrag"+i).innerHTML = wordBankNames[x];
	}
}

$(document).ready(function(){
	lesson_start();
	function lesson_start(){    
		lesson_num =1;
		$('#lessonDisplay').hide();
		$('#lessonArea').show();
		$('#exerciseArea').hide();
		$('a#anchorGoToLesson').hide();
		$('a#anchorGoToExercise').show();
		$('a#anchorPrevLesson').hide();
		$('#lesson2').hide();
		$('#lesson3').hide();
	}
	
	$('a#anchorNextLesson').click(function(){
		if(lesson_num == 1){	
			lesson_num = 2;
			$('a#anchorNextLesson').show();
			$('a#anchorPrevLesson').show();
			$('#lesson1').hide();
			$('#lesson3').hide();
			$('#lesson2').fadeIn(2000);
			
		}
		else if(lesson_num == 2){
			lesson_num = 3;
			$('a#anchorNextLesson').hide();
			$('a#anchorPrevLesson').show();
			$('#lesson1').hide();
			$('#lesson2').hide();
			$('#lesson3').fadeIn(2000);
			
		}
	});

	$('a#anchorPrevLesson').click(function(){
		if(lesson_num == 2){
			lesson_num = 1 ;
			$('a#anchorNextLesson').show();
			$('a#anchorPrevLesson').hide();
			$('#lesson2').hide();
			$('#lesson3').hide();
			$('#lesson1').fadeIn(2000);
		}
		else if(lesson_num == 3){
			lesson_num = 2;
			$('a#anchorNextLesson').show();
			$('a#anchorPrevLesson').show();
			$('#lesson1').hide();
			$('#lesson3').hide();
			$('#lesson2').fadeIn(2000);
		}
	});

	
	
	function exercise_start(){                //Start the exercise
		
		// drop blocks for the wordBank names to drop
		for(i =0; i<9;i++){
			document.getElementById("imgdrop"+i+"").innerHTML = '';
			document.getElementById("imgdrop"+i+"").innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		}
     	 
		
		
		exercise_num = 1;
		correctCounter = 0;
		selectedOptionBox = 0;    //value of selectedOptionBox
		$('#lessonArea').hide();
		$('#exerciseArea').show();
		$('a#anchorPlayAgain').hide();
		$('a#anchorPrev').hide();
		$('a#anchorNext').hide();
		$('#exercise1').fadeIn(2000);
		$('#exercise2').hide();
		$('#exercise3').hide();
		$('a#anchorGoToExercise').hide();
		$('a#anchorGoToLesson').show();
		load_images();
		}
		
	/******* Display Control Of Exercises *****/
		$('a#anchorGoToExercise').click(function(){
			playSound('trigger');
			exercise_start();
		});
		$('a#anchorGoToLesson').click(function(){
			playSound('trigger');
			lesson_start();
		});
		
		$('a#anchorNext').click(function(){
			if(exercise_num == 1){	
				exercise_num = 2;
				$('a#anchorNext').hide();
				//$('a#anchorPrev').show();
				$('#exercise1').hide();
				$('#exercise3').hide();
				$('#exercise2').fadeIn(2000);
				
			}
			else if(exercise_num == 2){
				exercise_num = 3;
				$('a#anchorNext').hide();
				//$('a#anchorPrev').show();
				$('#exercise1').hide();
				$('#exercise2').hide();
				$('#exercise3').fadeIn(2000);
				
			}
		});
	
		/*
		  $('a#anchorPrev').click(function(){
			if(exercise_num == 2){
				exercise_num = 1 ;
				$('a#anchorNext').show();
				$('a#anchorPrev').hide();
				$('#exercise2').hide();
				$('#exercise3').hide();
				$('#exercise1').fadeIn(2000);
			}
			else if(exercise_num == 3){
				exercise_num = 2;
				$('a#anchorNext').show();
				$('a#anchorPrev').show();
				$('#exercise1').hide();
				$('#exercise3').hide();
				$('#exercise2').fadeIn(2000);
			}
		});
		*/
		$('a#anchorPlayAgain').click(function(){
			exercise_start();
		});
	/******* Drag and Drop Framework Section *******/
	    $('#sideBar .wordBank')
	    
        // Set the element as draggable.
        .attr('draggable', 'true')

        // Handle the start of dragging to initialize.
        .bind('dragstart', function(ev) {
        	switch (ev.target.id) {
        	case 'imgdrag0':
        		selectedOptionBox = randOptions[0] ; dragPosition=0;     break;
          	case 'imgdrag1':
            		selectedOptionBox = randOptions[1] ; dragPosition=1;     break;
            case 'imgdrag2':
               	selectedOptionBox = randOptions[2] ; dragPosition = 2;   break;
            case 'imgdrag3':
               	selectedOptionBox = randOptions[3] ; dragPosition = 3;  break;
            case 'imgdrag4':
               	selectedOptionBox = randOptions[4] ; dragPosition = 4;   break;
            case 'imgdrag5':
               	selectedOptionBox = randOptions[5] ; dragPosition = 5;   break;
            case 'imgdrag6':
               	selectedOptionBox = randOptions[6] ;  dragPosition = 6;  break;
            case 'imgdrag7':
               	selectedOptionBox = randOptions[7] ; dragPosition = 7;   break;
            case 'imgdrag8':
               	selectedOptionBox = randOptions[8] ;  dragPosition = 8;  break;
            case 'imgdrag9':
              	selectedOptionBox = randOptions[9] ;  dragPosition = 9;  break;
            case 'imgdrag10':
             	selectedOptionBox = randOptions[10] ;  dragPosition = 10;  break;
            case 'imgdrag11':
             	selectedOptionBox = randOptions[11] ;  dragPosition = 11;  break;
            case 'imgdrag12':
             	selectedOptionBox = randOptions[12] ;  dragPosition = 12;  break;
            case 'imgdrag13':
             	selectedOptionBox = randOptions[13] ;  dragPosition = 13;  break;
            case 'imgdrag14':
             	selectedOptionBox = randOptions[14] ;  dragPosition = 14;  break;
            }
    // document.display.selectedBox.value = selectedOptionBox;
    //alert(selectedOptionBox);
            //alert(dragPosition);
      
            var dt = ev.originalEvent.dataTransfer;
            dt.setData("Text", "Dropped in zone!");
            return true;
            
            

            

        });

	
	 // Set up the drop zone.
   $('#exerciseArea').bind('dragenter', function(ev) {  // Update the drop zone class on drag enter/leave
	
       if (!$(ev.target).hasClass('dropBox')) return true;
           $(ev.target).addClass('dragover');  return false;
       })
	
       .bind('dragleave', function(ev) {
           if (!$(ev.target).hasClass('dropBox')) return true;
           $(ev.target).removeClass('dragover');   return false;
       })

       // Allow drops of any kind into the zone.
       .bind('dragover', function(ev) {
           if (!$(ev.target).hasClass('dropBox')) return true;
           return false;
       })

       // Handle the final drop...
       .bind('drop', function(ev) {
           if (!$(ev.target).hasClass('dropBox')) return true;
           switch (ev.target.id) {
     		case 'imgdrop0':
      			 	dropPosition = 0;		break;
     		case 'imgdrop1':
     			 	dropPosition = 1;		break;
     		case 'imgdrop2':
     			  	dropPosition = 2;		break;
     		case 'imgdrop3':
     			  	dropPosition = 3;		break;
     		case 'imgdrop4':
     			 	dropPosition = 4;		break;
     		case 'imgdrop5':
     			 	dropPosition = 5;		break;
     		case 'imgdrop6':
     			 	dropPosition = 6;		break;
     		case 'imgdrop7':
     			  	dropPosition = 7;		break;
     		case 'imgdrop8':
 			  		dropPosition = 8;		break;
      
           }
         //  alert("dropped");
          //document.display.droppedBox.value = droppedOptionBox;
          
         //  alert(dropPosition);
           	/** the box is dropped and now the calculation begins **/
              if(dropPosition == selectedOptionBox){
               document.getElementById("imgdrag"+dragPosition+"").innerHTML = "";
               document.getElementById("imgdrop"+dropPosition+"").innerHTML = "";
               document.getElementById("imgdrop"+dropPosition+"").innerHTML = wordBankNames[selectedOptionBox];
        	   //append or prepend can be used to put the image inside the div
        	   correctCounter++;
        	   control_display_exercises();
        	   
        	
        }
          
           ev.stopPropagation();
           return false;
        });
   
	
});