forked from junyiacademy/perseus_old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
454 lines (416 loc) · 14 KB
/
index.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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<!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/fonts/fonts.css" />
<link rel="stylesheet/less" type="text/css" href="lib/katex/katex.less" />
<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" style="display:none;">
<button id="toJSON">toJSON</button>
<button id="scorePreview">Score</button>
<button id="permalink">permalink</button>
<span>Seed:</span><span id="problemNum"></span>
<span>Features:</span><span id="enabledFeatures"></span>
</div>
<div style="width:100%; text-align:center; margin: 20px;" id='edit-button-collector'>
</div>
<table>
<tr>
<td>qid:</td>
<td>
<span id='qid'></span>
</td>
</tr>
<tr>
<td>科目:</td>
<td>
<input id='subject'></input>
</td>
</tr>
<tr>
<td>是否開放題目:</td>
<td>
<select id='is_hidden'>
<option value="False">公開</option>
<option value="True">隱藏</option>
</input>
</td>
</tr>
<tr>
<td>題目來源:</td>
<td>
<input id='source'></input>
</td>
</tr>
<tr>
<td>難度:</td>
<td>
<select id='level'>
<option value="1">簡單</option>
<option value="2">中等</option>
<option value="3">進階</option>
</select>
</td>
</tr>
<tr>
<td>範圍:</td>
<td>
<textarea rows="3" cols="20" id='cover_range'></textarea>
</td>
</tr>
<tr>
<td>相關影片:</td>
<td>
<textarea rows="3" cols="20" id='related_video'></textarea>
</td>
</tr>
<tr>
<td>下架時間:</td>
<td>
<input id='expire_date' placeholder='範例格式:2025/12/31'></input>(若不限定下架時間則不用填)
</td>
</tr>
</table>
<!-- Begin Perseus HTML -->
<div id="perseus-container">
</div>
<!-- End Perseus HTML -->
<div style="width:100%; text-align:center; margin: 20px;" id='save-button-collector'>
<span class="simple-button green" id="save">儲存改變</span>
<span class="simple-button orange" id="quit">取消編輯</span>
</div>
<!-- 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/marked.js"></script>
<script src="lib/react-with-addons.js"></script>
<script src="lib/rcss.js"></script>
<script src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full&delayStartupUntil=configured"></script>
<script src="lib/katex/katex.js"></script>
<script src="lib/mathquill/mathquill.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-1.js"], initPerseus);
// pre built with source maps
// require(["build/perseus.debug.js"], initPerseus);
// built on demand
// require(["src/perseus.js"], initPerseus);
});
function initPerseus(Perseus) {
window.Perseus = Perseus;
var defaultQuestion = {
"question": {
"content": "請在這裡填入問題",
"widgets": {}
},
"answerArea": {
"type": "radio",
"options": {
"content": "",
"widgets": {}
},
"calculator": false
},
"hints": []
};
var editor;
var problemNum = _.random(1, 99);
var enabledFeatures = {
highlight: true,
toolTipFormats: true,
useMathQuill: true
};
url = window.location.hash.split('?')[0].substring(1);
var question_dic = {}
var init_data = Perseus.Util.parseQueryString(url);
var new_perseus_question = false;
if (init_data.qid == '-1'){
new_perseus_question = true;
}
if (new_perseus_question == false){
if ($('#edit-button-collector').children().length == 0) {
$('#edit-button-collector').append('<span class="simple-button green" id="prev_question">編輯上一題</span>');
$('#edit-button-collector').append('<span class="simple-button green" id="next_question">編輯下一題</span>');
}
$('#prev_question').on('click',function(e){
if(question_dic.qid == 0){
alert('沒有上一題囉!');
return;
}
data={
'secret':question_dic.secret,
'iv':question_dic.iv,
'qid_offset':"-1"
};
getQuestion(data, 'offset-question/');
});
$('#next_question').on('click',function(e){
if(question_dic.qid == question_dic.question_amount-1){
alert('沒有下一題囉!');
return;
}
data={
'secret':question_dic.secret,
'iv':question_dic.iv,
'qid_offset':"1"
};
getQuestion(data, 'offset-question/');
});
}
$('#toJSON').on('click', function() {
console.log(JSON.stringify(editor, null, 4));
});
$('#scorePreview').on('click', function() {
console.log(editor.scorePreview());
});
$('#permalink').on('click', function(e) {
window.location.hash = "content=" +
encodeURIComponent(JSON.stringify(editor));
e.preventDefault();
});
$('#save').on('click',function(e){
if(question_dic.can_manage_all_questions == 'True') {
can_manage_all_questions = true;
}
else if (question_dic.can_manage_all_questions == 'False') {
can_manage_all_questions = false;
}
else {
can_manage_all_questions = question_dic.can_manage_all_questions;
}
if (!new_perseus_question && !question_dic.uploader_id) {
return_string = "No-Uploader-Name";
}
else if (!new_perseus_question && !can_manage_all_questions && question_dic.uploader_id != question_dic.user_id) {
return_string = "No-Authorization";
}
else {
return_string = "Have-Authorization";
}
if (return_string == "No-Authorization" || return_string == "No-Uploader-Name") {
alert("很抱歉,您沒有權限編輯第" + question_dic.qid +"題。");
}
else {
if (confirm("修改將儲存於資料庫")) {
is_hidden = $('select#is_hidden').val();
subject = $('input#subject').val();
if (subject == '科目為必填' || subject == ''){
alert('一定要填科目喔!請填入這一題的科目,謝謝!');
return;
}
source = $('input#source').val();
level = $('select#level').val();
cover_range = $('textarea#cover_range').val();
if (cover_range == '範圍為必填' || cover_range == ''){
alert('一定要填範圍喔!請填入這一題的範圍,謝謝!');
return;
}
related_video = $('textarea#related_video').val();
expire_date = $('input#expire_date').val();
question = JSON.stringify(editor);
host_name = question_dic.host_name;
data = {'qid':question_dic.qid,
'is_hidden':is_hidden,
'subject':subject,
'source':source,
'level':level,
'cover_range':cover_range,
'related_video':related_video,
'expire_date':expire_date,
'can_manage_all_questions':question_dic.can_manage_all_questions,
'secret':question_dic.secret,
'iv':question_dic.iv,
'question':question
};
if (new_perseus_question == true) {
newQuestion(data, 'save-perseus-question');
}else{
getQuestion(data, 'save-edit/');
}
}
}
});
$('#quit').on('click',function(e){
if (confirm("取消修改的話,未儲存之所有修改將不會儲存")) {
parent.close();
}
});
function getQuestion(data, func){
if (new_perseus_question) {
default_question_dic = {
'is_hidden': true,
'subject': '科目為必填',
'source': '',
'level': 1,
'cover_range': ['範圍為必填'],
'related_video': []
};
$.extend(default_question_dic, init_data);
question_dic = default_question_dic;
renderQuestion(default_question_dic);
}
else {
$.ajax({
url: 'http://' + init_data.host_name + '/questionpanel/questionmanager/' + func,
data: data,
dataType: 'json',
method: "POST",
success:function(data){
if(data == 'Have_No_Authority'){
alert("您沒有足夠權限,將跳轉至題庫管理頁面。");
parent.window.location = 'http://' + init_data.host_name + '/questionpanel/questionmanager/';
}
else{
question_dic = data;
renderQuestion(data);
}
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.status + " " + thrownError + "\n請檢查連線狀況");
}
});
}
};
function newQuestion(data, func){
host_name = init_data.host_name;
$.ajax({
url: 'http://' + host_name + '/questionpanel/makeperseusquestion/' + func,
data: data,
dataType: 'json',
method: "POST",
success:function(data){
if(data == 'Have_No_Authority'){
// user has no authority, redirect to junyiacademy.org
alert("您沒有足夠權限,將跳轉至首頁。");
parent.window.location = 'http://' + init_data.host_name;
}
else{
question_dic = data;
renderQuestion(data);
}
},
error:function(xhr, ajaxOptions, thrownError){
alert(xhr.status + " " + thrownError + "\n請檢查連線狀況");
}
});
}
$('#problemNum').text(problemNum);
$('#enabledFeatures').html(_.map(enabledFeatures, function(enabled, feature) {
return '<span style="margin-left: 5px; background: ' +
(enabled ? "#aaffaa" : "#ffcccc") + ';">' + feature + '</span>';
}).join(''));
function renderQuestion(question_dic) {
var question = question_dic.question ? JSON.parse(question_dic.question) : defaultQuestion;
new_perseus_question = false;
if (question_dic.qid == '-1'){
new_perseus_question = true;
}
$('span#qid').html(question_dic.qid);
if (question_dic.is_hidden === true) {
$('select#is_hidden').val('True');
}
else {
$('select#is_hidden').val('False');
}
$('input#subject').val(question_dic.subject);
$('input#source').val(question_dic.source);
$('select#level').val(question_dic.level);
$('textarea#cover_range').val(question_dic.cover_range);
$('textarea#related_video').val(question_dic.related_video);
$('input#expire_date').val(question_dic.expire_date);
if (question_dic.message) {
confirm(question_dic.message);
}
var editorProps = _.extend(question, {
problemNum: problemNum,
enabledFeatures: enabledFeatures,
developerMode: true,
imageUploader: function(image, callback) {
_.delay(callback, 1000, "http://fake.image.url");
},
apiOptions: {
__onInputError: function() {
var args = _.toArray(arguments);
console.log.apply(console, ["onInputError:"].concat(args));
return false;
},
__interceptInputFocus: function() {
var args = _.toArray(arguments);
console.log.apply(console, ["interceptInputFocus:"].concat(args));
return;
}
}
});
editor = React.renderComponent(
Perseus.StatefulEditorPage(editorProps, null),
document.getElementById("perseus-container")
);
// Some hacks to make debugging nicer
window.editorPage = editor.refs.editor;
window.itemRenderer = window.editorPage.renderer;
}
Perseus.init({skipMathJax: false}).then(function() {
init_data['qid_offset'] = 0;
getQuestion(init_data, 'offset-question/');
}).then(function() {
}, function(err) {
console.error(err);
});
}
})();
</script>
</body>
</html>