Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 261 lines (232 sloc) 8.042 kb
385089d Igor Terzic initial string
igorT authored
1 <!DOCTYPE html>
2 <head>
3
65eec09 Ben Alpert Content-Type meta tag for libxml2 compatibility
spicyj authored
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
385089d Igor Terzic initial string
igorT authored
5 <title>Exercise maker</title>
db23de0 Igor Terzic Prototype finished
igorT authored
6 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
7 <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js" type="text/javascript"></script>
8 <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/ui-lightness/jquery-ui.css" />
9 <script src="../" type="text/javascript"></script>
385089d Igor Terzic initial string
igorT authored
10 <script>
c0ef368 Igor Terzic variable progress
igorT authored
11 var variables = [];
db23de0 Igor Terzic Prototype finished
igorT authored
12 var inputArray = [];
13 var solutionArray = [];
14 var hintsArray = [];
c0ef368 Igor Terzic variable progress
igorT authored
15 function Variable( text, name ){
16 this.text = text;
17 this.name = name;
18 this.toJs = function() {
19 return this.text;
c2cb4db Ben Alpert Whitespace :)
spicyj authored
20 }
c0ef368 Igor Terzic variable progress
igorT authored
21 }
db23de0 Igor Terzic Prototype finished
igorT authored
22
23 function creatingNewVariable( span, varName ) {
24 var askVar = "Random number <input type='radio' name='varType' value = 'ran' />From <input id='fromV' /> To <input id='toV'/> ";
25 askVar += "<br> Custom function <input type='radio' name='varType' value = 'cust' /><input id='function' />";
26 $newVariableDialog = $('<div></div>').html( askVar, varName ).dialog({
27 title: 'Pick a var',
28 width: 400,
29 height: 300,
30 modal: true,
31 autoOpen: true,
32 buttons: {
33 "Confirm": function() {
34 if( $('input[name=varType]:checked').val() === 'ran' ){
35 variables.push( new Variable ( "randRange(" + $('#fromV').val() + ' , ' + $('#toV').val() + ")" , varName ));
36 }
37 else{
38 variables.push( new Variable ( $("#function").val() , varName));
39 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
40 if ( ( $(span).attr('id').substring(0,1) === 'q') ) {
db23de0 Igor Terzic Prototype finished
igorT authored
41 inputArray[ $( span ).attr( 'id' ).substring( 1 ) ] = " <var>" + varName + "</var> " ;
42 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
43 else if ( $(span).attr('id').substring(0,1) === 's') {
db23de0 Igor Terzic Prototype finished
igorT authored
44 solutionArray[ $( span ).attr( 'id' ).substring( 1 ) ] = " <var>" + varName + "</var> ";
45 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
46 else if ( $(span).attr('id').substring(0,1) === 'h') {
db23de0 Igor Terzic Prototype finished
igorT authored
47 hintsArray[ $( span ).attr( 'id' ).substring( 1 ) ] = " <var>" + varName + "</var> ";
48 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
49
db23de0 Igor Terzic Prototype finished
igorT authored
50 $(this).dialog("close");
51 $(this).remove();
52 }
53 }
54 })
55 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
56
c0ef368 Igor Terzic variable progress
igorT authored
57 function genVars( vars ){
c2cb4db Ben Alpert Whitespace :)
spicyj authored
58 toReturn = '<div class="vars">';
c0ef368 Igor Terzic variable progress
igorT authored
59 for( x = 0; x< vars.length; x++ ) {
db23de0 Igor Terzic Prototype finished
igorT authored
60 toReturn += '<var id = "' + vars[x].name + '">' + vars[x].toJs()+ '</var>'
c0ef368 Igor Terzic variable progress
igorT authored
61 }
62 toReturn += '</div>';
63 return toReturn;
64 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
65
c0ef368 Igor Terzic variable progress
igorT authored
66 function genQuestion( text ) {
c2cb4db Ben Alpert Whitespace :)
spicyj authored
67
c0ef368 Igor Terzic variable progress
igorT authored
68 return '<div class="question">' + text + '</div>';
c2cb4db Ben Alpert Whitespace :)
spicyj authored
69
c0ef368 Igor Terzic variable progress
igorT authored
70 }
db23de0 Igor Terzic Prototype finished
igorT authored
71
72 function genSolution( text ) {
73 return '<div class="solution">' + text + ' </div>';
74 }
75
76
77 function genHints( text ){
78 return "" + '<div class="hints"> ' + text + ' </div>';
79
80 }
81
c0ef368 Igor Terzic variable progress
igorT authored
82 function addVariable( span ){
db23de0 Igor Terzic Prototype finished
igorT authored
83 $(span).attr('id').substring(1);
84 var alreadyThere = "";
85 for ( x = 0; x < variables.length; x++ ) {
86 alreadyThere += variables[x].name + " <input type='radio' name='var' value = '" + variables[x].name + "' />"
87 }
88 alreadyThere += "NewOne <input type='radio' name='var' value = '_New' /><input type='textbox' id = 'varName' /> "
c2cb4db Ben Alpert Whitespace :)
spicyj authored
89
db23de0 Igor Terzic Prototype finished
igorT authored
90 $variableDialog = $('<div></div>').html(alreadyThere).dialog({
91 title: 'Randomize a number',
92 width: 400,
93 height: 300,
94 modal: false,
95 autoOpen: true,
96 buttons: {
97 "Confirm": function() {
98 if( $('input[name=var]:checked').val() !== "_New" ){
c2cb4db Ben Alpert Whitespace :)
spicyj authored
99 if( $(span).attr('id').substring(0,1) === 'q') {
db23de0 Igor Terzic Prototype finished
igorT authored
100 inputArray[ $( span ).attr( 'id' ).substring( 1 ) ] = " <var>" +$('input[name=var]:checked').val() + "</var> ";
101 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
102 else if ( $(span).attr('id').substring(0,1) === 's') {
db23de0 Igor Terzic Prototype finished
igorT authored
103 solutionArray[ $( span ).attr( 'id' ).substring( 1 ) ] = " <var>" +$('input[name=var]:checked').val() + "</var> ";
104 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
105 else if ( $(span).attr('id').substring(0,1) === 'h') {
db23de0 Igor Terzic Prototype finished
igorT authored
106 hintsArray[ $( span ).attr( 'id' ).substring( 1 ) ] = " <var>" +$('input[name=var]:checked').val() + "</var> ";
107 }
108 }
109 else{
110 creatingNewVariable( span, $("#varName").val() );
c2cb4db Ben Alpert Whitespace :)
spicyj authored
111
db23de0 Igor Terzic Prototype finished
igorT authored
112 }
113 generate();
114 $(this).dialog("close");
115 $(this).remove();
116 }
117 }
118 })
119
c2cb4db Ben Alpert Whitespace :)
spicyj authored
120
c0ef368 Igor Terzic variable progress
igorT authored
121 }
db23de0 Igor Terzic Prototype finished
igorT authored
122
c0ef368 Igor Terzic variable progress
igorT authored
123 function populateQuestion(){
124 var input = $("#question").val();
db23de0 Igor Terzic Prototype finished
igorT authored
125 if ( inputArray.length < 2 ){
126 inputArray = input.split(' ');
127 }
c0ef368 Igor Terzic variable progress
igorT authored
128 var toReturn = "";
129 var openVar = false
130 for( x = 0; x< inputArray.length; x++ ) {
db23de0 Igor Terzic Prototype finished
igorT authored
131 if( inputArray[x].substring(0,5) == "</var" || inputArray[x].substring( inputArray[x].length - 6) == "</var>" ){
c2cb4db Ben Alpert Whitespace :)
spicyj authored
132 openVar = false;
c0ef368 Igor Terzic variable progress
igorT authored
133 toReturn += inputArray[x];
134 }
135 else if( openVar || inputArray[x].substring(0,5) == "<var>"){
136 openVar = true;
137 toReturn += inputArray[x];
138 }
139 else {
140 toReturn += "<span id='q" + x + "' onClick='addVariable(this)' > " + inputArray[x] + "</span>";
141 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
142
c0ef368 Igor Terzic variable progress
igorT authored
143 }
144 $("#questionInput").html( toReturn );
c2cb4db Ben Alpert Whitespace :)
spicyj authored
145 return;
c0ef368 Igor Terzic variable progress
igorT authored
146 }
db23de0 Igor Terzic Prototype finished
igorT authored
147
148 function populateSolution(){
c2cb4db Ben Alpert Whitespace :)
spicyj authored
149
db23de0 Igor Terzic Prototype finished
igorT authored
150 var input = $("#solution").val();
151 if ( solutionArray.length < 1 ){
152 solutionArray = input.split(" ");
153 }
154 var toReturn = "";
155 var openVar = false
156 for( x = 0; x< solutionArray.length; x++ ) {
157 if( solutionArray[x].substring(0,5) == "</var" || solutionArray[x].substring( solutionArray[x].length - 6) == "</var>" ){
c2cb4db Ben Alpert Whitespace :)
spicyj authored
158 openVar = false;
db23de0 Igor Terzic Prototype finished
igorT authored
159 toReturn += solutionArray[x];
160 }
161 else if( openVar || solutionArray[x].substring(0,5) == "<var>"){
162 openVar = true;
163 toReturn += solutionArray[x];
164 }
165 else {
166 toReturn += "<span id='s" + x + "' onClick='addVariable(this)' > " + solutionArray[x] + "</span>";
167 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
168
db23de0 Igor Terzic Prototype finished
igorT authored
169 }
170 alert(toReturn);
171 $("#solutionInput").html( toReturn );
172 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
173
174 function populateHints(){
db23de0 Igor Terzic Prototype finished
igorT authored
175 var input = $("#hints").val();
176 if ( hintsArray.length < 2 ){
177 hintsArray = input.split(" ");
178 }
179 var toReturn = "";
180 var openVar = false
181 for( x = 0; x< hintsArray.length; x++ ) {
182 if( hintsArray[x].substring(0,5) == "</var" || hintsArray[x].substring( hintsArray[x].length - 6) == "</var>" ){
c2cb4db Ben Alpert Whitespace :)
spicyj authored
183 openVar = false;
db23de0 Igor Terzic Prototype finished
igorT authored
184 toReturn += hintsArray[x];
185 }
186 else if( openVar || hintsArray[x].substring(0,5) == "<var>"){
187 openVar = true;
188 toReturn += hintsArray[x];
189 }
190 else {
191 toReturn += "<span id='h" + x + "' onClick='addVariable(this)' > " + hintsArray[x] + "</span>";
192 }
c2cb4db Ben Alpert Whitespace :)
spicyj authored
193
db23de0 Igor Terzic Prototype finished
igorT authored
194 }
195 $("#hintsInput").html( toReturn );
196 }
197
a64e674 Igor Terzic reload works
igorT authored
198 function genHead( title ){
c2cb4db Ben Alpert Whitespace :)
spicyj authored
199 var head = '' +
a64e674 Igor Terzic reload works
igorT authored
200 '<!DOCTYPE html>' +
201 '<html data-require="math math-format expressions">' +
202 '<head>' +
203 ' <meta charset="UTF-8" />' +
204 ' <title>' + title + '</title>' +
205 ' <script src="../khan-exercise.js"></script\> ' +
c2cb4db Ben Alpert Whitespace :)
spicyj authored
206 '</head>' ;
a64e674 Igor Terzic reload works
igorT authored
207 return head;
208 }
385089d Igor Terzic initial string
igorT authored
209 function generate(){
c0ef368 Igor Terzic variable progress
igorT authored
210 populateQuestion();
db23de0 Igor Terzic Prototype finished
igorT authored
211 populateSolution();
212 populateHints();
213 alert( genHints( $('#hintsInput' ).html() ) );
c2cb4db Ben Alpert Whitespace :)
spicyj authored
214 var html = genHead($("#title").val()) + '<body><div class="exercise">' + genVars( variables ) +
385089d Igor Terzic initial string
igorT authored
215 '' +
216 ' <div class="problems">' +
c2cb4db Ben Alpert Whitespace :)
spicyj authored
217 ' <div>' + genQuestion( $("#questionInput").html()) +
218 genSolution( $("#solutionInput").html() )
db23de0 Igor Terzic Prototype finished
igorT authored
219 + genHints( $( '#hintsInput' ).html() ) +
220 '</div>' +
385089d Igor Terzic initial string
igorT authored
221 ' </div>' +
222 '</body>' +
223 '</html>';
db23de0 Igor Terzic Prototype finished
igorT authored
224 alert( html );
c2cb4db Ben Alpert Whitespace :)
spicyj authored
225 $("#frame").remove();
226 var $frame = $('<iframe id="frame" style="width:1000px; height:800px;">');
227 $('body').append( $frame );
385089d Igor Terzic initial string
igorT authored
228
c2cb4db Ben Alpert Whitespace :)
spicyj authored
229 setTimeout( function() {
6cbd2fe Igor Terzic can change title
igorT authored
230 var ifrm = document.getElementById('frame');
a64e674 Igor Terzic reload works
igorT authored
231 ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
232 ifrm.document.open();
233 ifrm.document.write(html);
234 ifrm.document.close();
c2cb4db Ben Alpert Whitespace :)
spicyj authored
235
236 }, 1 );
a64e674 Igor Terzic reload works
igorT authored
237 }
385089d Igor Terzic initial string
igorT authored
238 </script>
db23de0 Igor Terzic Prototype finished
igorT authored
239 <body>
240 Title
a64e674 Igor Terzic reload works
igorT authored
241 <input id="title">
c0ef368 Igor Terzic variable progress
igorT authored
242 <br>
db23de0 Igor Terzic Prototype finished
igorT authored
243 Question
c0ef368 Igor Terzic variable progress
igorT authored
244 <textarea id="question" rows = "4" columns = "400" type="text"></textarea>
245 <br>
db23de0 Igor Terzic Prototype finished
igorT authored
246 Solution
247 <input id="solution">
248 <br>
249 Hints
250 <textarea id="hints" rows = "4" columns = "400" type="text"></textarea>
251 <div id = "questionInput"></div>
252 <div id = "solutionInput"></div>
253 <div id = "hintsInput"></div>
254
a64e674 Igor Terzic reload works
igorT authored
255 <input type="button" value="Generate" onClick="generate();">
256 <div id="fr">
257 </div>
c2cb4db Ben Alpert Whitespace :)
spicyj authored
258
385089d Igor Terzic initial string
igorT authored
259 </body>
260 </html>
Something went wrong with that request. Please try again.