forked from Khan/perseus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
240 lines (211 loc) · 7.2 KB
/
test.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Perseus</title>
<link rel="stylesheet" type="text/css" href="ke/css/khan-site.css" />
<link rel="stylesheet" type="text/css" href="ke/css/khan-exercise.css" />
<link rel="stylesheet" type="text/css" href="lib/katex/katex.css" />
<link rel="stylesheet" type="text/css" href="lib/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="lib/mathquill/mathquill.css" />
<link rel="stylesheet/less" type="text/css" href="stylesheets/exercise-content-package/perseus.less" />
<link rel="stylesheet/less" type="text/css" href="stylesheets/perseus-admin-package/editor.less" />
<script>less = {env: 'development', logLevel: 1};</script>
<script src="lib/less.js"></script>
</head>
<body>
<div id="extras">
<button type="button" id="serialize">serialize</button>
<button type="button" id="scorePreview">score</button>
<button type="button" id="permalink">permalink</button>
<button type="button" id="rendered">view rendered</button>
<button type="button" id="input-version">contains only inputs?</button>
<button type="button" id="save-warnings">save warnings</button>
<span>Seed:</span><span id="problemNum"></span>
<span>Features:</span><span id="enabledFeatures"></span>
</div>
<!-- Begin Perseus HTML -->
<div id="perseus-container">
</div>
<!-- End Perseus HTML -->
<!-- put an empty div here so the margin on the perseus editor has something
to "push against" (without the div, the padding goes off the page, and the
add hint button ends up touching the bottom of the page). -->
<div class="clear"></div>
<script src="lib/jquery.js"></script>
<script src="lib/underscore.js"></script>
<script src="lib/react-with-addons.js"></script>
<script src="ke/third_party/MathJax/2.1/MathJax.js?config=KAthJax-8f02f65cba7722b3e529bd9dfa6ac25d&delayStartupUntil=configured"></script>
<script src="lib/katex/katex.js"></script>
<script src="lib/mathquill/mathquill-basic.js"></script>
<script src="lib/kas.js"></script>
<script>
var icu = {
getDecimalFormatSymbols: function() {
return {
decimal_separator: ".",
grouping_separator: ",",
minus: "-"
};
}
};
var KhanUtil = {
debugLog: function() {},
localeToFixed: function(num, precision) {
return num.toFixed(precision);
}
};
var Khan = {
Util: KhanUtil,
error: function() {},
query: {debug: ""},
imageBase: "/ke/images/",
scratchpad: {
enable: function() {},
disable: function() {}
}
};
React.initializeTouchEvents(true);
</script>
<script src="ke/local-only/jed.js"></script>
<script src="ke/local-only/i18n.js"></script>
<script src="ke/local-only/jquery.qtip.js"></script>
<script src="ke/exercises-stub.js"></script>
<script src="ke/local-only/require.js"></script>
<script>
(function() {
requirejs.config({
waitSeconds: 120
});
// Load khan-exercises modules, then perseus
require(["ke-deps.js"], function() {
// pre built
// require(["build/perseus.js"], initPerseus);
// pre built with source maps
// require(["build/perseus.debug.js"], initPerseus);
// built on demand
require(["live-build/perseus.js"], initPerseus);
});
function initPerseus(Perseus) {
window.Perseus = Perseus;
var defaultQuestion = {
"question": {
"content": "",
"images": {},
"widgets": {}
},
"answerArea": {
"type": "multiple",
"options": {
"content": "",
"images": {},
"widgets": {}
},
"calculator": false
},
"itemDataVersion": {
"major": 0,
"minor": 1
},
"hints": []
};
var editor;
var problemNum = Math.floor(Math.random() * 100);
var enabledFeatures = {
highlight: true,
toolTipFormats: true,
useMathQuill: true
};
$('#serialize').on('click', function() {
console.log(JSON.stringify(editor.serialize(), null, 4));
});
$('#scorePreview').on('click', function() {
console.log(editor.scorePreview());
});
$('#permalink').on('click', function(e) {
window.location.hash = "content=" +
Perseus.Util.strongEncodeURIComponent(JSON.stringify(editor.serialize()));
e.preventDefault();
});
$('#rendered').on('click', function(e) {
var link = document.createElement("a");
link.href = "/testrender.html#content=" +
Perseus.Util.strongEncodeURIComponent(JSON.stringify(editor.serialize()));
link.target = "_blank";
link.click();
e.preventDefault();
});
$('#input-version').on('click', function(e) {
e.preventDefault();
// print whether or not this item consists only of
// input-numbers and numeric-inputs.
// just for versioning testing
console.log(Perseus.renderability.isItemRenderableByVersion(
editor.serialize(),
{
'::renderer::': { major: 100, minor: 0 },
'group': { major: 100, minor: 0 },
'sequence': { major: 100, minor: 0 },
'input-number': { major: 100, minor: 0 },
'numeric-input': { major: 100, minor: 0 },
}
));
});
$('#save-warnings').on('click', function(e) {
e.preventDefault();
console.log(editor.getSaveWarnings());
});
$('#problemNum').text(problemNum);
$('#enabledFeatures').html(Object.keys(enabledFeatures).map(function(feature) {
var enabled = enabledFeatures[feature];
return '<span style="margin-left: 5px; background: ' +
(enabled ? "#aaffaa" : "#ffcccc") + ';">' + feature + '</span>';
}).join(''));
var query = Perseus.Util.parseQueryString(window.location.hash.substring(1));
var question = query.content ? JSON.parse(query.content) : defaultQuestion;
Perseus.init({skipMathJax: false}).then(function() {
var _ = window._;
var editorProps = _.extend(question, {
problemNum: problemNum,
enabledFeatures: enabledFeatures,
developerMode: true,
imageUploader: function(image, callback) {
_.delay(callback, 1000, "http://fake.image.url");
},
apiOptions: {
enableOldAnswerTypes: true,
fancyDropdowns: true,
__onInputError: function() {
var args = _.toArray(arguments);
console.log.apply(console, ["onInputError:"].concat(args));
return true;
},
__interceptInputFocus: function() {
var args = _.toArray(arguments);
console.log.apply(console, ["interceptInputFocus:"].concat(args));
return;
},
onFocusChange: function(newPath, oldPath) {
console.log("onFocusChange", newPath, oldPath);
},
__staticRender: true
},
componentClass: Perseus.EditorPage
});
var StatefulEditorPage = React.createFactory(Perseus.StatefulEditorPage);
editor = React.render(
StatefulEditorPage(editorProps, null),
document.getElementById("perseus-container")
);
// Some hacks to make debugging nicer
window.editorPage = editor.refs.editor;
window.itemRenderer = window.editorPage.renderer;
}).then(function() {
}, function(err) {
console.error(err);
});
}
})();
</script>
</body>
</html>