-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbti.min.js
244 lines (240 loc) · 7.27 KB
/
mbti.min.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
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
var finish = false;
var dapan;
function checknulloremty(data) {
if (typeof data == "undefined" || data == null) return false;
return true;
}
function loadtestiq() {
console.log("Get Inside");
// store.clearAll();
$.getJSON("traloimbti.txt", null, function(data) {
dapan = data;
});
$.getJSON("cauhoimbti.txt", null, function(data) {
var div = $("#baitest");
var div2 = $("#khungdapan");
var txtCauhoi =
"<div class='dendam dt'>Câu số <b style='color:red'>Cauhoi</b>/76</div>";
var khungdapan = "<div class='dapanchu'>";
var Cauhoi = "<div class='cauhoichu'>picture</div>";
var itemTraloi =
"<label class='DaRatio'><input type='radio' name='cauradio' onclick='luudapanchu(idcauhoi,iddapan,stt)'><span>picture</span></label>";
var ocauhoi =
"<li><a class='stt' href='javascript:;' onclick='loadcauhoi(stt)' data-val='stt'>stt</a></li>";
div.html("");
var stt = 0;
var html = "";
var html2 = "";
$.each(data, function(i, item) {
if (stt != item.STT) {
if (stt == 0) {
html =
"<div class='test num" + item.STT + "' style='display: block;'>";
} else
html =
"<div class='test num" + item.STT + "' style='display: none;'>";
html += txtCauhoi.replace("Cauhoi", item.STT);
html += Cauhoi.replace("picture", item.NameQues);
html +=
khungdapan +
itemTraloi
.replace("idcauhoi", item.IDQues)
.replace("iddapan", item.IDAns)
.replace("cauradio", "cauradio" + item.IDQues)
.replace("picture", item.NameAns)
.replace("stt", item.STT);
html2 += ocauhoi
.replace("stt", item.STT)
.replace("stt", item.STT)
.replace("stt", item.STT)
.replace("stt", item.STT);
} else {
if (data.length == i + 1) {
html +=
itemTraloi
.replace("idcauhoi", item.IDQues)
.replace("iddapan", item.IDAns)
.replace("cauradio", "cauradio" + item.IDQues)
.replace("picture", item.NameAns)
.replace("stt", item.STT) + "</div>";
html +=
"<a href='javascript:;' class='cautruoc' onclick='loadcauhoi(" +
(parseInt(item.STT) - 1) +
")'>Quay lại câu " +
(parseInt(item.STT) - 1) +
"</a>";
div.append(html);
html2 += "</ul>";
div2.append(html2);
html = "";
html2 = "";
store.set("tongcauhoi", item.STT);
} else if (stt != data[i + 1].STT) {
html +=
itemTraloi
.replace("idcauhoi", item.IDQues)
.replace("iddapan", item.IDAns)
.replace("cauradio", "cauradio" + item.IDQues)
.replace("picture", item.NameAns)
.replace("stt", item.STT) + "</div>";
if (item.STT != "1") {
html +=
"<a href='javascript:;' class='cautruoc' onclick='loadcauhoi(" +
(parseInt(item.STT) - 1) +
")'>Quay lại câu " +
(parseInt(item.STT) - 1) +
"</a>";
}
div.append(html);
} else
html += itemTraloi
.replace("idcauhoi", item.IDQues)
.replace("iddapan", item.IDAns)
.replace("cauradio", "cauradio" + item.IDQues)
.replace("picture", item.NameAns)
.replace("stt", item.STT);
}
stt = item.STT;
});
});
console.log("Done");
}
function loadcauhoi(num) {
$("#khungdapan>ul>li>a").removeClass("active");
var id = "." + num;
$(id).addClass("active");
$(".test").hide();
var cau = ".num" + num;
$(cau).show();
}
function checktontaikey(key) {
var old_key = store.get(key);
if (checknulloremty(old_key)) {
store.remove(old_key);
return false;
}
return true;
}
function checkkey(key) {
return store.get(key) !== undefined;
}
function luudapanchu(cauhoi, dapan, stt) {
checktontaikey(cauhoi);
store.set(cauhoi, dapan);
var len = store.get("tongcauhoi");
var divcauhoi = $("." + stt);
divcauhoi.addClass("done");
if (len == divcauhoi.text() && !finish) {
finish = true;
if (checkfinish(true) == 0) {
xemketqua();
}
} else {
if (finish) {
if (checkfinish(false) == 0) {
xemketqua();
} else goto_QuesNoAns();
} else {
window.setTimeout(function() {
loadcauhoi(stt + 1);
}, 100);
}
}
}
function goto_QuesNoAns() {
$.each($("#khungdapan>ul>li>a"), function(i, v) {
if ($(v).hasClass("done") == false) {
window.setTimeout(function() {
loadcauhoi($(v).attr("data-val"));
}, 100);
return false;
}
});
}
function checkfinish(bool_mes) {
var message = "";
var num = 0;
$.each($("#khungdapan>ul>li>a"), function(i, v) {
if ($(v).hasClass("done") == false) {
message += $(v).text() + ", ";
num++;
}
});
if (num == 0) return 0;
else {
if (bool_mes) alert("Bạn còn các câu: " + message + "chưa hoàn thành.");
return num;
}
}
function tinhdiem() {
var diemA = 0,
diemB = 0,
diemC = 0,
diemD = 0;
var mbti = "";
$.each(dapan, function(i, item) {
if (checkkey(item.IDQues)) {
if (store.get(item.IDQues) == item.IDAns) {
if (item.Group == 0) diemA++;
else if (item.Group == 1) diemB++;
else if (item.Group == 2) diemC++;
else diemD++;
}
} else {
if (item.Group == 0) diemA++;
else if (item.Group == 1) diemB++;
else if (item.Group == 2) diemC++;
else diemD++;
}
});
if (diemA < 10) mbti = "I";
else mbti = "E";
if (diemB < 12) mbti += "N";
else mbti += "S";
if (diemC < 12) mbti += "F";
else mbti += "T";
if (diemD < 12) mbti += "P";
else mbti += "J";
return mbti;
store.clearAll();
}
function tinhdiem2(numbertest) {
var data = store.get("dapan");
var diem = 0;
var luutru = [numbertest];
$.each(data, function(i, item) {
if (checkkey(item.IDQues)) {
if (store.get(item.IDQues) != item.IDAns) {
diem++;
} else {
luutru.push(item.IDQues);
}
} else {
diem++;
}
});
var TokenHeaderValue = $("#TokenHeaderValue").val();
$.ajax({
url: "/IQ/TruePercent",
type: "POST",
headers: {
RequestVerificationToken: TokenHeaderValue
},
data: { model: JSON.stringify(luutru) },
async: false,
success: function(data) {}
});
return diem;
store.clearAll();
}
function xemketqua() {
var a =
"<h3 class='text-center'>Chúc mừng bạn vừa hoàn thành xong bài test.</h3><br /><div class='text-center'><a href='javascript:' class='btn btn-primary' id='xemketqua' onclick='dienthongtin();'>Xem kết quả</a></div><div style='text-align:center;width:100%;margin-top:15px;'><a href='javascript:' onclick='quaylai();'><u>Coi lại bài test</u></a></div>";
$("#updatetestiq").html(a);
$("#updatetestiq").show();
$("#updatetestiq2").hide();
}
function quaylai() {
$("#updatetestiq").hide();
$("#updatetestiq2").show();
}