-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathquestions.js
160 lines (146 loc) · 5.34 KB
/
questions.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
var counter;
$(document).ready(function () {
$(".question").addClass("animated fadeInRightBig");
$(".options").addClass("animated fadeInLeftBig");
$(".lowbtn").addClass("animated fadeInLeftBig");
$(function(){
$(".options").on("click", function(){
console.log('selected');
$(".options").removeClass("selected");
$(this).addClass("selected");
});
});
var question;
var req = new XMLHttpRequest();
req.open("GET", '/questions/reality/request', true);
req.setRequestHeader("Content-Type", "application/json");
req.onreadystatechange = function() {
if(this.readyState == 4 && this.status ==200) {
question = JSON.parse(this.responseText);
counter = question.question_number;
document.getElementById('ques').innerHTML = question.question;
document.getElementById('option1').innerHTML = question.option1;
document.getElementById('option2').innerHTML = question.option2;
document.getElementById('option3').innerHTML = question.option3;
document.getElementById('option4').innerHTML = question.option4;
}
}
req.send();
});
$(".options").on("click", function(){
console.log('selected');
$(".options").removeClass("selected");
$(this).addClass("selected");
});
function loadQuestion(){
$(".options").removeClass("selected");
counter = question.question_number;
document.getElementById('ques').innerHTML = question.question;
document.getElementById('option1').innerHTML = question.option1;
document.getElementById('option2').innerHTML = question.option2;
document.getElementById('option3').innerHTML = question.option3;
document.getElementById('option4').innerHTML = question.option4;
}
// console.log(question);
function SubmitOption() {
document.getElementById("next").click();
var ans = document.getElementsByClassName("selected")[0].innerHTML;
console.log(ans);
if(!ans) {
document.getElementsByClassName('alert')[0].style.animation = 'showAlert 2s ease-in-out';
}
var data = {
"question": counter,
"answer": ans
};
$(".options").removeClass("selected");
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');
$.ajaxSetup({
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
});
if(counter%5==0 && counter!=0)window.location.href='roulette.html';
$.ajax({
type: "POST",
url: "/answer/ajax/post",
dataType: "json",
data: data,
async:false
});
var req = new XMLHttpRequest();
req.open("GET", '/questions/reality/request', false);
req.setRequestHeader("Content-Type", "application/json");
req.onreadystatechange = function() {
if(this.readyState == 4 && this.status ==200) {
// if(counter%5 === 0) {
// console.log('Next reality!');
// var url = window.location.href;
// // window.location.href =
//
question = JSON.parse(this.responseText);
// score = JSON.parse(this.responseText.score);
// append in html
console.log(question);
loadQuestion();
}
}
console.log(ans);
req.send(JSON.stringify(data));
console.log(data);
}
{
function openNav()
{
document.getElementById('nav').style.height = "100%";
}
function closeNav()
{
document.getElementById('nav').style.height = "0%";
}
function toggleSidebar(ref) {
ref.classList.toggle('active');
document.getElementById('sidebar').classList.toggle('active');
}
function toggleFullScreen() {
if ((document.fullScreenElement && document.fullScreenElement !== null) ||
(!document.mozFullScreen && !document.webkitIsFullScreen)) {
if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}
window.addEventListener('resize', function(){
if(screen.width === window.innerWidth){
$('.final').toggleClass('active');
$('.close').toggleClass('active');
}
});
}