This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
/
index.html
209 lines (170 loc) · 6.38 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
<!doctype html>
<!-- The DOCTYPE declaration above will set the -->
<!-- browser's rendering engine into -->
<!-- "Standards Mode". Replacing this declaration -->
<!-- with a "Quirks Mode" doctype may lead to some -->
<!-- differences in layout. -->
<html dir='rtl' lang='he'>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="ImitatorGWT.css">
<link type="text/css" rel="stylesheet" href="clean.css">
<title>הקובץ התשיעי</title>
<script src="js/socket.io/socket.io.js"></script>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.deserialize.js"></script>
<script src="Imitator.port.js"></script>
</head>
<body class='puzzles' dir='rtl' lang='he'>
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
<p id='login' dir='rtl'></p>
<h1 dir='rtl' lang='he'>הקובץ התשיעי</h1>
<form dir='rtl' id='form'>
<select id="corpus" name="corpus">
<option value="ShmonaKvazim">כתבי הרב קוק</option>
<option value="Rambam">כתבי הרמב"ם</option>
<option value="Herzl">כתבי הרצל</option>
</select>
<input type='hidden' name='numChoices' value='4' />
<button id='sendButton' onclick='createPuzzle(); return false;'>צור חידה חדשה</button>
</form>
<div style='display:none' id='puzzles' dir='rtl' lang='he'>
<p>לפניך מספר קטעים. אחד מהם אמיתי והשאר מזוייפים. מהו הקטע האמיתי?</p>
<ol>
<li id='choice0'></li>
<li id='choice1'></li>
<li id='choice2'></li>
<li id='choice3'></li>
</ol>
</div>
<div>
<span class='correct'><label>תשובות נכונות: </label> <span id='numCorrect' dir='rtl' lang='he'>0</span></span>
<span class='wrong'><label>תשובות שגויות: </label> <span id='numWrong' dir='rtl' lang='he'>0</span>
</div>
<div> </div>
<div>
<button id='explainButton' dir='rtl' lang='he' onclick='$("#explanations").toggle()'>הראה הסברים</button>
</div>
<div id='explanations' style='display:none' dir='rtl' lang='he'>
<ol>
<li id='explanation0'></li>
<li id='explanation1'></li>
<li id='explanation2'></li>
<li id='explanation3'></li>
</ol>
</div>
<p id='footer'>האתר נבדק על דפדפן פיירפוקס בלבד</p>
<script language="javascript" type="text/javascript">
function commonConnect(serverport, deeplog) {
var server = (
location.protocol=='file:'? "http://localhost:"+serverport:
location.protocol+"//"+location.hostname+":"+serverport);
//deeplog.add(1, "Connecting to "+server+"...");
console.info("CLIENT: connecting to "+server);
var socket = io.connect(server);
socket.on('connect', function() {
//deeplog.replace(1, "Client: Connected to server. Click to see log.");
console.info("CLIENT: connected to "+server);
});
socket.on('disconnect', function(data) {
//deeplog.add(1, "Disconnected from server.");
console.log("CLIENT: good bye, server!");
});
return socket;
}
/**
* @see http://stackoverflow.com/a/647272/827927
*/
function getQueryString() {
var result = {}, queryString = location.search.substring(1),
re = /([^&=]+)=([^&]*)/g, m;
while (m = re.exec(queryString)) {
result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
return result;
}
/**
* @param form
* @return an object whose fields are the fields of the given form.
* Also converts 'any' selected-options to nulls, and handles arrays (fields whose name ends with []).
*/
function formToObject(form) {
var request = {};
$.each(form.serializeArray(), function(i, field) {
if (field.name.endsWith("[]")) { // field is an array:
field.name = field.name.substr(0,field.name.length-2);
if (!request[field.name])
request[field.name] = [];
request[field.name].push(field.value);
} else {
request[field.name] = (field.value=='any'? null: field.value);
}
});
return request;
}
/* initialization */
var socket=null, form=null, deeplog=null;
var replies = [];
$(document).ready(function() {
if (getQueryString()["explain"])
$("#explainButton").show();
else
$("#explainButton").hide();
$("#sendButton").text("צור חידה חדשה");
$("#sendButton").prop('disabled', false);
//deeplog = new DeepLog($("#deeplog"));
form = $('#form');
socket = commonConnect(serverport, deeplog);
socket.on('puzzle', onPuzzle)
});
/* puzzles */
function createPuzzle() {
var request = formToObject(form);
console.log("CLIENT: got a request to create a puzzle: "+JSON.stringify(request));
$("#sendButton").text("יוצר חידה...");
$("#sendButton").prop('disabled', true);
socket.emit('createPuzzle', request);
}
function onPuzzle(result) {
console.log("CLIENT: got a puzzle!");
for (var iChoice=0; iChoice<result.length; ++iChoice) {
var choice = $("#choice"+iChoice);
var explanation = $("#explanation"+iChoice);
if (choice) {
//console.log(JSON.stringify(result[iChoice]));
choice.html(result[iChoice].choice);
choice.attr("class", "");
//replies[iChoice] = result[iChoice].reply;
choice.attr("reply", result[iChoice].reply);
choice.click(function() {
var reply = this.attr("reply");
markChoiceAsCorrectOrWrong(this, /נכון/.test(reply));
alert(iChoice+": "+reply);
//choicesRegistrations[iChoiceFinal].removeHandler();
//choicesRegistrations[iChoiceFinal] = null;
});
}
if (explanation)
explanation.html(result[iChoice].explanation.replace(/[.] /, ".<br/>"));
}
$("#puzzles").show();
$("#sendButton").text("צור חידה חדשה");
$("#sendButton").prop('disabled', false);
}
function markChoiceAsCorrectOrWrong(choiceLabel, isCorrect) {
if (isCorrect) {
//setNumCorrect(numCorrect+1);
choiceLabel.attr("class", "correct");
} else {
//setNumWrong(numWrong+1);
choiceLabel.attr("class", "wrong");
}
}
</script>
</body>
</html>