-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.html
105 lines (86 loc) · 2.92 KB
/
task.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
<!-- Based on JQuery and Parsley. Adapted from ProtoTurk example. -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/parsley.js/2.8.1/parsley.js"></script>
<script>
$(document).ready(function() {
addTask("${Identifier_0}", "${Label_0}", "${Text_0}");
addTask("${Identifier_1}", "${Label_1}", "${Text_1}");
addTask("${Identifier_2}", "${Label_2}", "${Text_2}");
addTask("${Identifier_3}", "${Label_3}", "${Text_3}");
addTask("${Identifier_4}", "${Label_4}", "${Text_4}");
$('#mturk_form').parsley();
});
function addTask(identifier, label, text) {
let words = text.split(" ");
let index = 0;
let h2 = document.createElement("h2");
h2.textContent = label;
let table = document.createElement("table");
let label_tr = table.insertRow(-1);
let input_tr = table.insertRow(-1);
words.forEach(word => {
let label_td = label_tr.insertCell(-1);
let input_td = input_tr.insertCell(-1);
let label = document.createElement("label");
let input = document.createElement("input");
let inputid = identifier + "/" + index
index++;
label.setAttribute("for", inputid);
label.textContent = word;
input.setAttribute("name", inputid);
input.id = inputid;
input.setAttribute("type", "text");
input.setAttribute("required", true);
input.setAttribute("size", word.length);
input.setAttribute("data-parsley-pattern", "[su]+");
input.setAttribute("data-parsley-trigger", "change keyup");
input.setAttribute("data-parsley-validation-threshold", 0);
input.setAttribute("data-parsley-error-message", "")
label_td.appendChild(label);
input_td.appendChild(input);
});
$('#taskdiv').append(h2, table);
}
</script>
<style>
/* Style rules copied from: http://parsleyjs.org/src/parsley.css */
input.parsley-success,
select.parsley-success,
textarea.parsley-success {
color: #468847;
background-color: #DFF0D8;
border: 1px solid #D6E9C6;
}
input.parsley-error,
select.parsley-error,
textarea.parsley-error {
color: #B94A48;
background-color: #F2DEDE;
border: 1px solid #EED3D7;
}
.parsley-errors-list {
margin: 2px 0 3px;
padding: 0;
list-style-type: none;
font-size: 0.9em;
line-height: 0.9em;
opacity: 0;
transition: all .3s ease-in;
-o-transition: all .3s ease-in;
-moz-transition: all .3s ease-in;
-webkit-transition: all .3s ease-in;
}
.parsley-errors-list.filled {
opacity: 1;
}
</style>
<h1>Instructions</h1>
<p>
Below each word enter the stress of each syllable, "u" for unstressed and "s" for stressed.
As you type the input will be validated. Valid input will have a green background. Invalid input will have a red background.
Hit Tab to quickly navigate between entries.
</p>
<p> When every entry is valid, click Submit to proceed to the next lines.</p>
<hr>
<div id="taskdiv">
</div>