-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.js
executable file
·230 lines (210 loc) · 7.43 KB
/
module.js
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
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* JavaScript library for the quiz module.
*
* @package mod
* @subpackage questionnaire
* @copyright
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Javascript for hiding/displaying children questions on preview page of
* questionnaire with conditional branching.
*/
function dependdrop(qId, children) {
var e = document.getElementById(qId);
var choice = e.options[e.selectedIndex].value;
depend (children, choice);
}
function depend (children, choices) {
children = children.split(',');
choices = choices.split(',');
var childrenlength = children.length;
var choiceslength = choices.length;
child = null;
choice = null;
for (var i = 0; i < childrenlength; i++) {
child = children[i];
var q = document.getElementById(child);
if (q) {
var radios = q.getElementsByTagName('input');
var radiolength = radios.length;
var droplists = q.getElementsByTagName('select');
var droplistlength = droplists.length;
var textareas = q.getElementsByTagName('textarea');
var textarealength = textareas.length;
for (var k = 0; k < choiceslength; k++) {
choice = choices[k];
if (child == choice) {
// If this browser version accepts classList.
if (typeof document !== "undefined" && ("classList" in document.createElement("a"))) {
q.classList.add('qn-container');
// If this browser version DOES NOT accept classList (e.g. MSIE < 10)
} else {
addClass(q, 'qn-container');
}
for (var j = 0; j < radiolength; j++) {
radio = radios[j];
radio.disabled=false;
}
for (var m = 0; m < droplistlength; m++) {
droplist = droplists[m];
droplist.disabled=false;
}
delete children[i];
} else if (children[i]){
if (typeof document !== "undefined" && ("classList" in document.createElement("a"))) {
q.classList.remove('qn-container');
q.classList.add('hidedependquestion');
} else {
removeClass(q, 'qn-container');
}
addClass(q, 'hidedependquestion');
for (var j = 0; j < radiolength; j++) {
radio = radios[j];
radio.disabled=true;
radio.checked=false;
radio.value='';
}
for (var m = 0; m < droplistlength; m++) {
droplist = droplists[m];
droplist.selectedIndex = 0;
droplist.disabled=true;
droplist.checked=false;
}
for (var n = 0; n < textarealength; n++) {
textarea = textareas[n];
textarea.value = '';
}
}
}
}
}
}
// End conditional branching functions.
/*
* A workaround for MSIE versions < 10 which do not recognize classList. Answer by Paulpro at:
* http://stackoverflow.com/questions/6787383/what-is-the-solution-to-remove-add-a-class-in-pure-javascript.
* */
function addClass(el, aclass){
el.className += ' '+aclass;
}
function removeClass(el, aclass){
var elClass = ' '+el.className+' ';
while(elClass.indexOf(' '+aclass+' ') != -1)
elClass = elClass.replace(' '+aclass+' ', '');
el.className = elClass;
}
// End classList workaround.
// When respondent enters text in !other field, corresponding
// radio button OR check box is automatically checked.
function other_check(name) {
other = name.split("_");
var f = document.getElementById("phpesp_response");
for (var i=0; i<=f.elements.length; i++) {
if (f.elements[i].value == "other_"+other[1]) {
f.elements[i].checked=true;
break;
}
}
}
// Automatically empty an !other text input field if another Radio button is clicked.
function other_check_empty(name, value) {
var f = document.getElementById("phpesp_response");
for (var i=0; i<f.elements.length; i++) {
if ((f.elements[i].name == name) && f.elements[i].value.substr(0,6) == "other_") {
f.elements[i].checked=true;
var otherid = f.elements[i].name + "_" + f.elements[i].value.substring(6);
var other = document.getElementsByName (otherid);
if (value.substr(0,6) != "other_") {
other[0].value = "";
} else {
other[0].focus();
}
var actualbuttons = document.getElementsByName (name);
for (var i=0; i<=actualbuttons.length; i++) {
if (actualbuttons[i].value == value) {
actualbuttons[i].checked=true;
break;
}
}
break;
}
}
}
// In a Rate question type of sub-type Order : automatically uncheck a Radio button
// when another radio button in the same column is clicked.
function other_rate_uncheck(name, value) {
col_name = name.substr(0, name.indexOf("_"));
var inputbuttons = document.getElementsByTagName("input");
for (var i=0; i<=inputbuttons.length - 1; i++) {
button = inputbuttons[i];
if (button.type == "radio" && button.name != name && button.value == value
&& button.name.substr(0, name.indexOf("_")) == col_name) {
button.checked = false;
}
}
}
// Empty an !other text input when corresponding Check Box is clicked (supposedly to empty it).
function checkbox_empty(name) {
var actualbuttons = document.getElementsByName (name);
for (var i=0; i<=actualbuttons.length; i++) {
if (actualbuttons[i].value.substr(0,6) == "other_") {
name = name.substring(0,name.length-2) + actualbuttons[i].value.substring(5);
var othertext = document.getElementsByName (name);
if (othertext[0].value == "" && actualbuttons[i].checked == true) {
othertext[0].focus();
} else {
othertext[0].value = "";
}
break;
}
}
}
M.mod_questionnaire = M.mod_questionnaire || {};
M.mod_questionnaire.init_attempt_form = function(Y) {
M.core_formchangechecker.init({formid: 'phpesp_response'});
};
M.mod_questionnaire.init_sendmessage = function(Y) {
Y.on('click', function(e) {
Y.all('input.usercheckbox').each(function() {
this.set('checked', 'checked');
});
}, '#checkall');
Y.on('click', function(e) {
Y.all('input.usercheckbox').each(function() {
this.set('checked', '');
});
}, '#checknone');
Y.on('click', function(e) {
Y.all('input.usercheckbox').each(function() {
if (this.get('alt') == 0) {
this.set('checked', 'checked');
} else {
this.set('checked', '');
}
});
}, '#checknotstarted');
Y.on('click', function(e) {
Y.all('input.usercheckbox').each(function() {
if (this.get('alt') == 1) {
this.set('checked', 'checked');
} else {
this.set('checked', '');
}
});
}, '#checkstarted');
};