-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
288 lines (269 loc) · 10.7 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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<html dir="ltr" lang="en">
<head>
<title data-lang="perceptual_color_diff">Perceptual Color Difference</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<meta property="og:image" content="/page-icon-en.png" />
<meta property="og:description" content="This is a questionnaire on color difference. It's simple, friendly, and you can stop whenever you want. Compatible also with phone.
We would appreciate if you answer as many questions as possible and share this!
Thanks!" />
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="language.js"></script>
<script src="create.js"></script>
<script>
var questions = [];
var questionIndex = 0;
var handleClick = false;
var isUpdate = false;
var backEnabled = false;
var wantToAnswer = 50;
var lang_key = 'en';
var pendingAnswer;
$(document).ready(function () {
loadQuestions();
showQuestion(questions[0]);
$('.button_yes').click({ answer: 1 }, answerClick);
$('.button_no').click({ answer: 0 }, answerClick);
$('#lang').click(function () {
lang_key = getText('next_lang');
$('[data-lang]').each(function (i, t) {
$(t).html(getText($(t).attr('data-lang')));
});
$('#lang').text(lang[getText('next_lang')]['lang_name']);
$(document).attr('dir', getText('lang_dir'));
$('html').attr('lang', lang_key);
});
$('#start1').click(function () {
disableBack();
$('.menu').fadeOut(function () {
$('.quiz').fadeIn();
});
});
$('#back_button').click(backClick);
$('#continue_button').click(continueClick);
$('#restart_button').click(restartClick);
$('#menu_button').click(function () {
resetCounter();
$('.thanks').fadeOut(function () {
$('.menu').fadeIn();
});
});
$('#end_button').click(endClick);
window.scrollTo(0, 1);
});
function endClick() {
$('.quiz').fadeOut().promise().done(function () {
wantToAnswer = questionIndex + 50;
disableBack();
$('#q_amount').html(wantToAnswer);
$('.thanks').fadeIn();
});
}
function getText(key_) {
const str = lang[lang_key][key_];
return str.replace(/(?:\r\n|\r|\n)/g, '<br>');
}
function continueClick() {
$('.thanks').fadeOut(function () {
$('.quiz').fadeIn();
});
}
function restartClick() {
resetCounter();
$('.thanks').fadeOut(function () {
$('.quiz').fadeIn();
});
}
function resetCounter() {
questions = questions.slice(questionIndex + 1);
questionIndex = 0;
wantToAnswer = 50;
$('#q_amount').text('50');
$('#q_number').text('1');
showQuestion(questions[0]);
}
function answerClick(event) {
if (!handleClick) return;
handleClick = false;
var className = event.target.className;
answer(questions[questionIndex], event.data.answer);
if (questionIndex + 1 < wantToAnswer) {
next_question();
} else {
$('.quiz').fadeOut().promise().done(function () {
disableBack();
wantToAnswer += 50;
$('#q_amount').html(wantToAnswer);
next_question();
$('.thanks').fadeIn();
});
}
}
function backClick() {
if (backEnabled) {
disableBack();
questionIndex--;
$('#q_number').html(questionIndex + 1);
showQuestion(questions[questionIndex]);
pendingAnswer.clear();
pendingAnswer = false;
}
}
function enableBack() {
backEnabled = true;
$('#back_button').toggleClass("img_disabled", false);
}
function disableBack() {
backEnabled = false;
$('#back_button').toggleClass("img_disabled", true);
}
function next_question() {
questionIndex++;
$('#q_number').html(questionIndex + 1);
if (Object.keys(questions).length - questionIndex < 10) {
loadQuestions();
}
enableBack();
isUpdate = false;
return showQuestion(questions[questionIndex]);
}
function createTimeout(timeoutHandler, delay) {
var timeoutId;
timeoutId = setTimeout(timeoutHandler, delay);
return {
clear: function () {
clearTimeout(timeoutId);
},
trigger: function () {
clearTimeout(timeoutId);
return timeoutHandler();
}
};
}
function answer(q, is_similar) {
if (pendingAnswer) {
pendingAnswer.trigger();
}
const delay = 3000;
const ans = () => {
postAnswer(q, is_similar);
pendingAnswer = false;
disableBack();
};
pendingAnswer = createTimeout(ans, delay);
enableBack();
}
function postAnswer(q, is_similar) {
const urlAddress = 'https://docs.google.com/forms/u/0/d/e/1FAIpQLScbakfMV8RPI-LpBDlDtuIeEoKDHIiiNXODOMjsDlvwe1woHA/formResponse';
const isSimStr = is_similar ? "TRUE" : "FALSE";
const data = { 'entry.192852037': q[0], 'entry.1285917805': q[1], 'entry.134297632': isSimStr };
$.post(urlAddress, data);
}
function loadQuestions() {
var amount = 30;
let moreQuestions = createColorsArray(Math.random().toString(), amount);
questions = [...questions, ...moreQuestions];
}
function showQuestion(q) {
var defer = $.when(changeColor($('#c1'), q[0]),
changeColor($('#c2'), q[1]));
defer.then(function () {
handleClick = true;
});
return defer;
}
function changeColor(_element, color) {
color = "#" + color;
var defer = $.Deferred();
_element.css({
'background-image': 'linear-gradient('
+ color + ', ' + color + ')',
'background-size': '100% 100%',
'transition': 'background-size .3s'
});
setTimeout(function () {
_element.css({
'background-color': color,
'background-size': '0% 100%'
});
setTimeout(function () { defer.resolve(); }, 150);
}, 300);
return defer.promise();
}
</script>
</head>
<body>
<table class="menu">
<tr>
<td class="text" data-lang="about">This is a questionnaire on perceptual color difference.<br>
The purpose of these questions is to gather a dataset of color pairs and their corresponding
similarity.<br>
This dataset will be used to test different color differences and compare them against perceptual color
differences.<br>
We would appreciate very much if you answer as many questions as possible (even answering several
questions would be helpful).<br>
Please answer "dissimilar" only if the colors are totally different.<br>
<br>
Thanks in advance,<br>
<br>
<div style="float: right" ;>David Zar, Student<br>
Dr. Ofir Pele, Supervisor</div>
</td>
</tr>
<tr>
<td class="menu_button" id="start1" data-lang="startquiz1">Start</td>
</tr>
<tr>
<td class="menu_button" id="lang">עברית</td>
</tr>
</table>
<div class="quiz">
<div style="display:flex; flex-flow: column; height: 100%;">
<div class="top" style="display:flex; align-items: center; justify-content: space-between;">
<img id="end_button" class="img_button" src="Delete.png" style="height:5vh; padding: 1.3vh;" />
<div style="
font-size: 2vh;
">
<span data-lang="question">Question</span><span> </span><span style="font-size: 1.8vh;"><span
id="q_number">1</span>/<span id="q_amount">50</span></span>
</div>
<img id="back_button" class="img_button img_disabled" src="Undo.png"
style="height: 5vh; padding: 1.3vh;" />
</div>
<div class="top" style="padding: 1.3vh; border-bottom: 0" data-lang="is_there_any_similarity">Is there
similarity between
these colors?</div>
<div class="top" style="padding: 1.3vh;
font-size: 2vh;
" data-lang="please_answer_only_when">Please answer "dissimilar" only if the colors are totally different.</div>
<div id="c1" class="color" style="flex: 1">
</div>
<div id="c2" class="color" style="flex: 1">
</div>
<div class="quiz buttons" style="display: flex">
<div class="button button_yes" data-lang="similar">Similar</div>
<div class="button button_no" data-lang="unsimilar">Dissimilar</div>
</div>
</div>
</div>
<table class="thanks">
<tr>
<td class="text" data-lang="thanks!">Thank you for your answers.<br>
Now you can close the window, return to the menu or continue answering (which would be much
appreciated!)<br>
You can close the window at any time, your answers will be automatically saved.<br>
Thanks!</td>
</tr>
<tr>
<td class="thanks_button" id="restart_button" data-lang="restart">Restart</td>
</tr>
<tr>
<td class="thanks_button" id="continue_button" data-lang="continue">Continue</td>
</tr>
<tr>
<td class="thanks_button" id="menu_button" data-lang="menu">Menu</td>
</tr>
</table>
</body>
</html>