-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·342 lines (296 loc) · 14 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>milkers image selector</title>
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.isotope.min.js"></script>
<script src="js/jquery-isotope-example.js"></script>
<script src="js/highslide/highslide/highslide.js"></script>
<script src="js/jquery-1.10.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery-isotope-example.css">
</head>
<body onload="addElement()">
<!-- -->
<div>Thank you for taking this survey. Upon completing it, please click the button at the bottom of the page to submit your work.
<br>You can click on any image to see the image number(i.e. set#user_#_<i>imageNumber</i>).<br>
<b>Please read the following <a href="rules.html" target="_blank" style="color:red;">instructions</a> before taking the survey.</b>
</div>
<!-- p>Num of images: <input type="text" id="userInputNum" value="6"></input></p -->
<!-- <p>Folder name: <input type="text" id="userInputFolder" value="images"></input></p> -->
<div id="placeholder"></div>
<br>
<script type="text/javascript">
function biggerImage(name){
alert(name);
}
var images = [];
// var userInputNum = document.getElementById("userInputNum").value;
var userInputNum = 300;//number of images shown to the user.
// var userInputFolder = document.getElementById("userInputFolder").value;
var userInputFolder = getQueryVariable("param1");//reads folder name from query string.
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
// alert('Query Variable ' + variable + '=' + pair[1]);
return pair[1];
}
}
alert('Query Variable ' + variable + ' not found');
}
var orImageSizes = [];
for (var i = 1; i <= userInputNum; i++) {
var newDiv = document.createElement("div");
newDiv.id = "imagediv_"+i;//should define an id for each dynamic div here.
var tempWidth = 400;//sets the size of each image on the page.
newDiv.setAttribute("style", "width:"+(tempWidth+10)+"px;height:" +(tempWidth+100)+"px;float:left;border:2px solid;background:#dddddd;");
images[i] = new Image(); // creates an image
images[i].class = "image";
images[i].src = "userFolders/" + userInputFolder.substring(0,4) + "/" + userInputFolder.substring(4,userInputFolder.length) + "/" + i + ".jpg"; // gets image location from table
// images[i].src = "userFolders/" + userInputFolder + "/" + i + ".jpg";
images[i].name = userInputFolder + "_" + i; // name property of the image.
orImageSizes[2*i-1] = images[i].width;
orImageSizes[2*i] = images[i].height;
// images[i].onload=function(){
// // alert('load success jpg');
// }
// images[i].onerror=function(){
// alert('load fail jpg');
// images[i].src = userInputFolder + "/" + i + ".gif";
// }
// if (typeof this.src == 'undefined') {
// images[i].src = userInputFolder + "/" + i + ".png"; // gets image location from table
// };
// if(typeof this.src == 'undefined'){
// images[i].src = userInputFolder + "/" + i + ".gif"; // gets image location from table
// };
// images[i].onload = function(){
// alert('image:' + this.src + ' width:'+ this.width + ' height:' + this.height);
// }
// images[i].setAttribute("width", tempWidth);
// images[i].setAttribute("height", tempWidth);
if (images[i].addEventListener){
images[i].addEventListener("click", function () { /* Do something */
var nameLength = this.name.length;
var start = nameLength-5;
var index = this.name.substring(start,start+1);
// alert(this.name + ' size is ' + orImageSizes[2*parseInt(index)-1] + ' by ' + orImageSizes[2*parseInt(index)] + ' index=' + index);
//alert(this.name + ' size is ' + this.width + ' by ' + orImageSizes[2*parseInt(index)] + ' index=' + index);
alert("This is image " + this.name);
});
}
// if (images[i].addEventListener){
// images[i].addEventListener("click", biggerImage('baba'));
// }
else if (images[i].attachEvent){ // addEventListener isn't always supported
images[i].attachEvent("onTouchDown", function () { /* Do something */
alert(images[i].name + " no event listener!");
});
}
images[i].style.height = tempWidth + "px";
images[i].style.width = tempWidth + "px";
images[i].style.marginLeft = (5)+"px"; // pushes images 5 pixels to the left
images[i].style.marginTop = (5)+"px"; // pushes images 5 pixels to the left
//document.body.appendChild(images[i]); // append newly created image to body
/*
var tempImg = document.getElementsByName("imagename_" + i + ".jpg")[0];
tempImg.onmouseover=function(){
alert(tempImg.name);
};*/
var checkIn1 = document.createElement("input");
checkIn1.type = "checkbox";
checkIn1.id = "image_"+i+"_cb1";
var label1 = document.createElement('label');
label1.htmlFor = "image_"+i+"_cb1";//it should be same with id of checkIn1
// label1.style.color = '#FF0505';
label1.appendChild(document.createTextNode('Anger'));//emotion_1
var checkIn2 = document.createElement("input");
checkIn2.type = "checkbox";
checkIn2.id = "image_"+i+"_cb2";
var label2 = document.createElement('label');
label2.htmlFor = "image_"+i+"_cb2";
// label2.style.color = '#FFBF80';
label2.appendChild(document.createTextNode('Anticipation'));
var checkIn3 = document.createElement("input");
checkIn3.type = "checkbox";
checkIn3.id = "image_"+i+"_cb3";
var label3 = document.createElement('label');
label3.htmlFor = "image_"+i+"_cb3";
// label3.style.color = '#FFFF00';
label3.appendChild(document.createTextNode('Joy'));
var checkIn4 = document.createElement("input");
checkIn4.type = "checkbox";
checkIn4.id = "image_"+i+"_cb4";
var label4 = document.createElement('label');
label4.htmlFor = "image_"+i+"_cb4";
// label4.style.color = '#9ACD32';
label4.appendChild(document.createTextNode('Trust'));
var checkIn5 = document.createElement("input");
checkIn5.type = "checkbox";
checkIn5.id = "image_"+i+"_cb5";
var label5 = document.createElement('label');
label5.htmlFor = "image_"+i+"_cb5";
// label5.style.color = '#00CC00';
label5.appendChild(document.createTextNode('Fear'));
var checkIn6 = document.createElement("input");
checkIn6.type = "checkbox";
checkIn6.id = "image_"+i+"_cb6";
var label6 = document.createElement('label');
label6.htmlFor = "image_"+i+"_cb6";
// label6.style.color = '#0066CC';
label6.appendChild(document.createTextNode('Surprise'));
var checkIn7 = document.createElement("input");
checkIn7.type = "checkbox";
checkIn7.id = "image_"+i+"_cb7";
var label7 = document.createElement('label');
label7.htmlFor = "image_"+i+"_cb7";
// label7.style.color = '#CC00CC';
label7.appendChild(document.createTextNode('Sadness'));
var checkIn8 = document.createElement("input");
checkIn8.type = "checkbox";
checkIn8.id = "image_"+i+"_cb8";
var label8 = document.createElement('label');
label8.htmlFor = "image_"+i+"_cb8";
// label8.style.color = '#FF33FF';
label8.appendChild(document.createTextNode('Disgust'));
var checkIn9 = document.createElement("input");
checkIn9.type = "checkbox";
checkIn9.id = "image_"+i+"_cb9";
var label9 = document.createElement('label');
label9.htmlFor = "image_"+i+"_cb9";
// label9.style.color = '#D3D3D3';//light gray
label9.appendChild(document.createTextNode('Neutral'));//emotion_9
//Add single image to newDiv
newDiv.appendChild(images[i]);
//Create a 3 x 3 table of choices and add it below image.
var mytable = document.createElement("table");
mytable.id = "mytable";
mytable.style.marginLeft = (10)+"px";
var tbody = document.createElement("tbody");
//first row
var row1 = document.createElement("tr");
var cell1 = document.createElement("td");
cell1.appendChild(checkIn1);
cell1.appendChild(label1);
var cell2 = document.createElement("td");
cell2.appendChild(checkIn2);
cell2.appendChild(label2);
var cell3 = document.createElement("td");
cell3.appendChild(checkIn3);
cell3.appendChild(label3);
var cell4 = document.createElement("td");
cell4.appendChild(checkIn4);
cell4.appendChild(label4);
row1.appendChild(cell1);
row1.appendChild(cell2);
row1.appendChild(cell3);
row1.appendChild(cell4);
//second row
var row2 = document.createElement("tr");
var cell5 = document.createElement("td");
cell5.appendChild(checkIn5);
cell5.appendChild(label5);
var cell6 = document.createElement("td");
cell6.appendChild(checkIn6);
cell6.appendChild(label6);
var cell7 = document.createElement("td");
cell7.appendChild(checkIn7);
cell7.appendChild(label7);
var cell8 = document.createElement("td");
cell8.appendChild(checkIn8);
cell8.appendChild(label8);
row2.appendChild(cell5);
row2.appendChild(cell6);
row2.appendChild(cell7);
row2.appendChild(cell8);
//third row
var row3 = document.createElement("tr");
var cell9 = document.createElement("td");
// cell9.appendChild(checkIn9);
// cell9.appendChild(label9);
var cell10 = document.createElement("td");
// cell10.appendChild(checkIn9);
// cell10.appendChild(label9);
var cell11 = document.createElement("td");
// cell11.appendChild(checkIn9);
// cell11.appendChild(label9);
var cell12 = document.createElement("td");
cell12.appendChild(checkIn9);
cell12.appendChild(label9);
row3.appendChild(cell9);
row3.appendChild(cell10);
row3.appendChild(cell11);
row3.appendChild(cell12);
//add all rows to table
tbody.appendChild(row1);
tbody.appendChild(row2);
tbody.appendChild(row3);
mytable.appendChild( tbody );
newDiv.appendChild( mytable );
// newDiv.appendChild(checkIn1);
// newDiv.appendChild(label1);
// add the newly created element and its content into the DOM
my_div = document.getElementById("org_div2");
document.body.insertBefore(newDiv, my_div);//inserts newDiv before my_div like a stack.
}//end of for
</script>
<div style="overflow:hidden;clear:both;">
<div id='org_div2'><br></div>
<!--button onclick="createResultPage()">Result button</button-->
<!--input id='finalcheckbox' type="radio" onclick="createResultPage()" /> Please check before submit your result!-->
<button id='computeresultsbutton' onclick="createResultPage()">Submit your votes!</button>
<br>
</div>
<br><br>
<script type="text/javascript">
function createResultPage(){
//iterate over all checkboxes
//Create a new resultJson each time user clicks result button.
//json result collectors.
var isEveryImageChecked = false;
var resultData = {};
var imResults = [];
resultData.imResults = imResults;
for (var i = 1; i <= userInputNum; i++) {
isEveryImageChecked = false;
for(var j = 1; j <= 9; j++){
var tmpCbx = document.getElementById('image_'+i+'_cb'+j);
if(tmpCbx.checked){
// alert('image '+i+' checkbox '+j+' is checked.');
var tempImage = {"imageName":images[i].name, "emotion":"emotion_"+j};
resultData.imResults.push(tempImage);
// document.getElementById('placeholder').innerHTML = JSON.stringify(resultData);
isEveryImageChecked = true;
}
}
if(!isEveryImageChecked){
alert('please check this image=> ' + images[i].name);
break;
}
}
if(isEveryImageChecked){
// newwindow=window.open();
// newdocument=newwindow.document;
alert("Thank you we saved your result.");
document.getElementById('finalResult').value = JSON.stringify(resultData);
document.getElementById('userfoldername').value = userInputFolder;
// document.getElementById('finalsendbutton').style.display = "";
document.getElementById('finalsendbutton').click();
// newdocument.write(JSON.stringify(resultData));
// newdocument.close();
}
}
</script>
<div>--</div>
<form action="mytest.php" method="POST">
<input type="hidden" name="name" id="userfoldername" />
<!--Age: <input type="text" name="age" /-->
<input type="hidden" name="jsonResult" id="finalResult" />
<input id="finalsendbutton" type="submit" style="display:none" value="Send Result!" />
</form>
<br><br>
</body>
</html>