This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
module.js
149 lines (136 loc) · 5.83 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
// 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 adaptivequiz module.
*
* This module was created as a collaborative effort between Middlebury College
* and Remote Learner.
*
* @package mod_adaptivequiz
* @copyright 2013 onwards Remote-Learner {@link http://www.remote-learner.ca/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
M.mod_adaptivequiz = M.mod_adaptivequiz || {};
M.mod_adaptivequiz.init_attempt_form = function(Y, url, secure) {
// Check if the page is on the password required page
if (null == document.getElementById('id_quizpassword')) {
M.core_question_engine.init_form(Y, '#responseform');
M.core_formchangechecker.init({formid: 'responseform'});
} else {
if ('1' == secure) {
Y.on('click', function(e) {
M.mod_adaptivequiz.secure_window.close(url, 0)
}, '#id_cancel');
}
}
};
M.mod_adaptivequiz.secure_window = {
init: function(Y) {
if (window.location.href.substring(0, 4) == 'file') {
window.location = 'about:blank';
}
Y.delegate('contextmenu', M.mod_adaptivequiz.secure_window.prevent, document, '*');
Y.delegate('mousedown', M.mod_adaptivequiz.secure_window.prevent_mouse, document, '*');
Y.delegate('mouseup', M.mod_adaptivequiz.secure_window.prevent_mouse, document, '*');
Y.delegate('dragstart', M.mod_adaptivequiz.secure_window.prevent, document, '*');
Y.delegate('selectstart', M.mod_adaptivequiz.secure_window.prevent, document, '*');
Y.delegate('cut', M.mod_adaptivequiz.secure_window.prevent, document, '*');
Y.delegate('copy', M.mod_adaptivequiz.secure_window.prevent, document, '*');
Y.delegate('paste', M.mod_adaptivequiz.secure_window.prevent, document, '*');
M.mod_adaptivequiz.secure_window.clear_status;
Y.on('beforeprint', function() {
Y.one(document.body).setStyle('display', 'none');
}, window);
Y.on('afterprint', function() {
Y.one(document.body).setStyle('display', 'block');
}, window);
Y.on('key', M.mod_adaptivequiz.secure_window.prevent, '*', 'press:67,86,88+ctrl');
Y.on('key', M.mod_adaptivequiz.secure_window.prevent, '*', 'up:67,86,88+ctrl');
Y.on('key', M.mod_adaptivequiz.secure_window.prevent, '*', 'down:67,86,88+ctrl');
Y.on('key', M.mod_adaptivequiz.secure_window.prevent, '*', 'press:67,86,88+meta');
Y.on('key', M.mod_adaptivequiz.secure_window.prevent, '*', 'up:67,86,88+meta');
Y.on('key', M.mod_adaptivequiz.secure_window.prevent, '*', 'down:67,86,88+meta');
},
clear_status: function() {
window.status = '';
setTimeout(M.mod_adaptivequiz.secure_window.clear_status, 10);
},
prevent: function(e) {
alert(M.str.adaptivequiz.functiondisabledbysecuremode);
e.halt();
},
prevent_mouse: function(e) {
if (e.button == 1 && /^(INPUT|TEXTAREA|BUTTON|SELECT|LABEL|A)$/i.test(e.target.get('tagName'))) {
// Left click on a button or similar. No worries.
return;
}
e.halt();
},
/**
* Event handler for the adaptivequiz start attempt button.
*/
start_attempt_action: function(e, args) {
if (args.startattemptwarning == '') {
openpopup(e, args);
} else {
M.util.show_confirm_dialog(e, {
message: args.startattemptwarning,
callback: function() {
openpopup(e, args);
},
continuelabel: M.util.get_string('startattempt', 'quiz')
});
}
},
init_close_button: function(Y, url) {
Y.on('click', function(e) {
M.mod_adaptivequiz.secure_window.close(url, 0)
}, '#secureclosebutton');
},
close: function(Y, url, delay) {
setTimeout(function() {
if (window.opener) {
window.opener.document.location.reload();
window.close();
} else {
window.location.href = url;
}
}, delay * 1000);
}
};
M.mod_adaptivequiz.init_comment_popup = function(Y) {
// Add a close button to the window.
var closebutton = Y.Node.create('<input type="button" />');
closebutton.set('value', M.util.get_string('cancel', 'moodle'));
Y.one('#id_submitbutton').ancestor().append(closebutton);
Y.on('click', function() { window.close() }, closebutton);
}
M.mod_adaptivequiz.init_reviewattempt = function(Y) {
Y.one('#adpq_scoring_table').hide();
Y.one('#adpq_scoring_table_link_icon').setContent('▶');
Y.use('node', function(Y) {
Y.delegate('click', function(e) {
if (e.currentTarget.get('id') === 'adpq_scoring_table_link') {
var table = Y.one('#adpq_scoring_table');
table.toggleView();
if (table.getComputedStyle('display') === 'none') {
Y.one('#adpq_scoring_table_link_icon').setContent('▶');
} else {
Y.one('#adpq_scoring_table_link_icon').setContent('▼');
}
}
}, document, 'a');
});
};