Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/can_cant_plugin/index.html
blob: 5bb4ea5e37679a90abb200d676c1433d46579dc0 (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
<html lang="en">

<head>
<title>Karma - Can and can't </title>
<meta name="keywords" content="karma,javascript,html5,sugar,sugarlabs,gsoc,ole,nepal">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" href="http://karma.sugarlabs.org/favicon.ico">

<link rel="stylesheet" type="text/css" href="../../css/karma.css" />

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../../js/jquery.karma.js"></script>
<script type="text/javascript">

<!--
$(document).ready(function(){
	//
	
	function imageLoadDisplay( src ) {
		$(img).load(function () {
			//nice effect - should I delete it?
			$(this).fadeIn( 800 );
			$("#content").append( this );
		}).attr("src", path.images + src);
	}
	function textDisplay( msg, x, y ) {
		ctx.textAlign = "center";
		ctx.fillText( msg, x, y );
	}
	//canvas stuff -----------
	function drawRectangle() {
		ctx.fillStyle = "rgba(0, 0, 0, 0.7)"; 
		ctx.fillRect( 0, 0, 400, 80 ); 
		ctx.font = "15px sans-serif";
		ctx.fillStyle = "white";
		ctx.fillText( "Q.", 10, 20 );
		ctx.fillText( "Ans.", 10, 45 );
		
	}
	
	
	// canvas!
	
	$("#canvasArrow").click(function(){ 
		if ( clicArrow === 1 ) {
			clicArrow = 0; 
			ctx.clearRect( 0, 0, 400, 80 );
			qn= (qn + 1) % scenario.questions[ sn ].length; //next question
			startActivity( sn );
		} else {
			k.sound( path.sounds + endSound ).play();
			textDisplay( answer, 170, 45 );
			clicArrow ++;
		}
	});
	
	// I draw the arrow
	var ctxArrow = $("#canvasArrow")[0].getContext('2d');
	ctxArrow.fillStyle = "rgb( 255, 255, 255 )";
	ctxArrow.beginPath();
	ctxArrow.moveTo(20,20);
	ctxArrow.lineTo(30,20);
	ctxArrow.lineTo(30,15);
	ctxArrow.lineTo(45,25);
	ctxArrow.lineTo(30,35);
	ctxArrow.lineTo(30,30);
	ctxArrow.lineTo(20,30);
	ctxArrow.lineTo(20,20);
	ctxArrow.fill();
	ctxArrow.closePath()
	
	//
	var audio=$("#audio"); //similar to getElementById...  
	var img = new Image(); //creates an Image element for background
	var ctx = $("#canvas")[0].getContext('2d'); //similar to document.getElementById('canvas')
	
	var k=$.karma("#karma-main");
	k.size(500, 450);
	
	var path={
		images: "images/",
		sounds: "sound_ogg/"
	};
	
	var scenario={
		background:["bg1.png", "bg2.png", "bg3.png", "bg4.png"],
		startSound:[
			["can_a_bird_fly.ogg", "can_a_dog_fly.ogg", "what_can_a_dog_do.ogg" ],
			["can_a_duck_swim.ogg", "can_a_hen_swim.ogg", "what_can_a_hen_do.ogg" ],
			["can_a_student_read_a_book.ogg", "can_a_cow_read_a_book.ogg", "what_can_a_cow_do.ogg" ],
			["can_a_monkey_climb_a_tree.ogg", "can_a_giraffe_climb_a_tree.ogg", "what_can_a_giraffe_do.ogg" ]
			
		],
		questions:[
			[ "Can a bird fly?", "Can a dog fly?", "What can a dog do?" ],
			[ "Can a duck swim?", "Can a hen swim?", "What can a hen do?" ],
			[ "Can a student read a book?", "Can a cow read a book?", "What can a cow do?" ],
			[ "Can a monkey climb a tree?", "Can a giraffe climb a tree?", "What can a giraffe do?" ]
		],
		answers:[
			[ "Yes, it can.",    "No, it can't.",  "A dog can run." ],
			[ "Yes, it can.",    "No, she can't.",  "She can lay eggs." ],
			[ "Yes, she can.",   "No, she can't.",  "She can give milk." ],
			[ "Yes, it can.",   "No, it can't.",  "It can eat the leaves of the tree without climbing." ] //need to fix the last item 
		],
		endSound:[
			[ "yes_it_can.ogg",  "no_it_cant.ogg", "a_dog_can_run.ogg" ],
			[ "yes_it_can.ogg",  "no_she_cant.ogg", "she_can_lay_eggs.ogg" ],
			[ "yes_she_can.ogg", "no_she_cant.ogg", "she_can_give_milk.ogg" ],
			[ "yes_it_can.ogg",  "no_it_cant.ogg", "it_can_eat_the_leaves_of_a_tree_without_climbing.ogg" ]
		]
	};
	
	var clicArrow=0; // how many times have you clicked the arrow?
	var sn=0; //default scenario number
	var qn=0; //default question number

	function reset() {
		clicArrow=0;
		qn=0;
		ctx.clearRect( 0, 0, 400, 80 );
	}
	function startActivity( ) {
		drawRectangle();
		imageLoadDisplay( scenario.background[ sn ] );
		textDisplay( scenario.questions[ sn ][ qn ],190, 20);
		k.sound( path.sounds + scenario.startSound[ sn ][ qn ] ).play();
		endSound= scenario.endSound[ sn ][ qn ];
		answer = scenario.answers[ sn ][ qn ] ;
		
	}
	//it starts the default scenario (sn)
	startActivity( );
	
	//the user choose a specail scenario
	$("#bottom-navigation ul li a").click(function(){
		reset();
		sn=$(this).html() - 1; //need to validate??? :S
		startActivity(  );
	});
	
	
	

});


//-->


</script>
</head>

<body>


	
	<noscript>
	Man, you need to enable JavaScript.
	</noscript>
	
	<div id="karma-main"></div>
    <canvas id="canvas"></canvas>
	<canvas id="canvasArrow"></canvas>
	<div id="content"></div>
	<div id="bottom-navigation">
		<ul>
			<li><a href="#">1</a></li>
			<li><a href="#">2</a></li>
			<li><a href="#">3</a></li>
			<li><a href="#">4</a></li>
		</ul>
	</div>
	
</body>
</html>