-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.js
37 lines (34 loc) · 1.04 KB
/
save.js
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
function pack(toggle=true){
var out = {title:null,data:[]};
out.title = document.querySelector("#ctitle").value;
for (i of info){
var v;
var t = i.type;
if (t=="text"){
v = document.querySelector("#"+i.id).innerHTML;
}
else if (t=="mq" || t=="dmq"){
v= i.mathfield.latex();
}
else if (t=="break"){
v= null;
}
else if (t=="problem"){
v = {
q:i.qfield.latex(),
a:i.afield.latex(),
h1:document.getElementById(i.h1field).value,
h2:document.getElementById(i.h2field).value,
s:document.getElementById(i.sfield).value
}
}
out.data.push({"type":t, "value":v})
}
var jsonse = JSON.stringify(out);
var blob = new Blob([jsonse], {type: "application/json"});
var title=out.title + ".json";
if (title==".json"){title="course.json"}
saveAs(blob, title);
if (toggle){
$('.navbar-toggler').click(); }
}