forked from husseinmozannar/SOQAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_open.html
112 lines (102 loc) · 5.01 KB
/
demo_open.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
<!DOCTYPE html>
<html dir="rtl" lang="ar">
<head>
<meta charset="utf-8">
<script>
function hit(question) {
// document.getElementById("spinner").setAttribute('style', 'display: none;');
// for (var i = 0; i < 5; i++) {
// var ans = document.getElementById("answer" + i);
// ans.innerText = "الجواب ال" + i;
// //ans.setAttribute('style', 'display: block; opacity: 1;');
// }
// document.getElementById("answersDiv").setAttribute('style', 'display: block; opacity: 1;');
var xhr = new XMLHttpRequest();
xhr.open("POST", '/answer', true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.onreadystatechange = function () {
console.log(xhr.status);
if (xhr.readyState === 4 && xhr.status === 200) {
var json = JSON.parse(xhr.responseText);
console.log(json.answer);
document.getElementById("spinner").setAttribute('style', 'display: none;');
for (var i = 0; i < 5; i++) {
var ans = document.getElementById("answer" + i);
//ans.innerText += (i == json.answer.length) ? json.answer[i] : json.answer[i] + "\n";
ans.innerText = json.answer[i];
//ans.setAttribute('style', 'display: block; opacity: 1;');
}
document.getElementById("answersDiv").setAttribute('style', 'display: block; opacity: 1;');
}
};
var params = JSON.stringify({ "question": question });
xhr.send(params);
console.log("sent");
}
</script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="static/demo_open.css" >
<link href="https://fonts.googleapis.com/css?family=Raleway:900&display=swap" rel="stylesheet" >
<link href="https://fonts.googleapis.com/css?family=Cairo&display=swap" rel="stylesheet">
</head>
<body>
<div style="height:233px;margin-top:160px" id="lga">
<div class="main">
<h1>SOQAL </h1>
</div>
<div class="example" style="margin:auto; width: 582px;">
<input type="text" class="y" id="question" placeholder="ابحث ..." name="search">
<button id="GetAnswer" type="submit"><i class="fa fa-search"></i></button>
</div>
<div class="answers">
<div class="spinner" id="spinner">
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
<div id="answersDiv">
<table id="answersTable">
<tr>
<td><div class="numberCircle">١</div></td>
<td><h2 class="answertext" id="answer0">الجواب</h2></td>
</tr>
<tr>
<td><div class="numberCircle">٢</div></td>
<td><h2 class="answertext" id="answer1">الجواب</h2></td>
</tr>
<tr>
<td><div class="numberCircle">٣</div></td>
<td><h2 class="answertext" id="answer2">الجواب</h2></td>
</tr>
<tr>
<td><div class="numberCircle">٤</div></td>
<td><h2 class="answertext" id="answer3">الجواب</h2></td>
</tr>
<tr>
<td><div class="numberCircle">٥</div></td>
<td><h2 class="answertext" id="answer4">الجواب</h2></td>
</tr>
</table>
</div>
</div>
</div>
<script>
var button = document.getElementById("GetAnswer");
button.onclick = function () {
var ques = document.getElementById("question");
var ans = document.getElementById("answer");
console.log("hitting");
document.getElementById("answersDiv").setAttribute('style', 'display: none; opacity: 0;');
document.getElementById("spinner").setAttribute('style', 'display: block;');
hit(ques.value);
};
</script>
<!-- YAMLI CODE START -->
<script type="text/javascript" src="https://api.yamli.com/js/yamli_api.js"></script>
<script type="text/javascript">
if (typeof (Yamli) == "object" && Yamli.init({ uiLanguage: "en", startMode: "onOrUserDefault" })) {
Yamli.yamlifyClass("y", { settingsPlacement: "inside" });
}
</script>
<!-- YAMLI CODE END -->
</body>
</html>