mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
quiz/question javascript MDL-24170 Enter in a shortanswer question preview should not flag the question.
That bit of JavaScript from mod/quiz/attempt.php is needed in question preview too, so refactor a bit. I was disappointed to find that the $PAGE->requires->js_module('core_question_engine'); line was needed in quiz_get_js_module, but it seems to be. Also change non-Moodle-y string "End test..." to "Finish attempt..."
This commit is contained in:
parent
48c19b2551
commit
157434a522
@ -445,6 +445,11 @@ class page_requirements_manager {
|
||||
'fullpath' => '/group/module.js',
|
||||
'requires' => array('node', 'overlay', 'event-mouseenter'));
|
||||
break;
|
||||
case 'core_question_engine':
|
||||
$module = array('name' => 'core_question_engine',
|
||||
'fullpath' => '/question/qengine.js',
|
||||
'requires' => array('node', 'event'));
|
||||
break;
|
||||
case 'core_rating':
|
||||
$module = array('name' => 'core_rating',
|
||||
'fullpath' => '/rating/module.js',
|
||||
|
@ -1193,7 +1193,7 @@ class quiz_attempt_nav_panel extends quiz_nav_panel_base {
|
||||
protected function get_end_bits() {
|
||||
global $PAGE;
|
||||
$output = '';
|
||||
$output .= '<a href="' . s($this->attemptobj->summary_url()) . '" class="endtestlink">' . get_string('endtest', 'quiz') . '</a>';
|
||||
$output .= '<a href="' . s($this->attemptobj->summary_url()) . '" class="endtestlink">' . get_string('finishattemptdots', 'quiz') . '</a>';
|
||||
$output .= $this->attemptobj->get_timer_html();
|
||||
return $output;
|
||||
}
|
||||
|
@ -348,6 +348,7 @@ $string['filloutnumericalanswer'] = 'You provide at least one possible answer an
|
||||
$string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. \'*\' can be used as a wildcard to match any characters. The first matching answer will be used to determine the score and feedback.';
|
||||
$string['filloutthreequestions'] = 'You must provide at least three questions with matching answers. You can provide extra wrong answers by giving an answer with a blank question. Entries where both the question and the answer are blank will be ignored.';
|
||||
$string['fillouttwochoices'] = 'You must fill out at least two choices. Choices left blank will not be used.';
|
||||
$string['finishattemptdots'] = 'Finish attempt...';
|
||||
$string['finishreview'] = 'Finish review';
|
||||
$string['forceregeneration'] = 'force regeneration';
|
||||
$string['formatnotfound'] = 'Import/export format {$a} not found';
|
||||
|
@ -1255,10 +1255,12 @@ function quiz_check_safe_browser() {
|
||||
}
|
||||
|
||||
function quiz_get_js_module() {
|
||||
global $PAGE;
|
||||
$PAGE->requires->js_module('core_question_engine');
|
||||
return array(
|
||||
'name' => 'mod_quiz',
|
||||
'fullpath' => '/mod/quiz/module.js',
|
||||
'requires' => array('base', 'dom', 'event-delegate', 'event-key'),
|
||||
'requires' => array('base', 'dom', 'event-delegate', 'event-key', 'core_question_engine'),
|
||||
'strings' => array(
|
||||
array('timesup', 'quiz'),
|
||||
array('functiondisabledbysecuremode', 'quiz'),
|
||||
|
@ -7,26 +7,12 @@
|
||||
M.mod_quiz = M.mod_quiz || {};
|
||||
|
||||
M.mod_quiz.init_attempt_form = function(Y) {
|
||||
Y.one('#responseform').setAttribute('autocomplete', 'off');
|
||||
Y.on('key', function (e) {
|
||||
if (!e.target.test('a') && !e.target.test('input[type=submit]') &&
|
||||
!e.target.test('input[type=img]')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}, '#responseform', 'press:13');
|
||||
M.core_question_engine.init_form(Y, '#responseform');
|
||||
Y.on('submit', M.mod_quiz.timer.stop, '#responseform');
|
||||
};
|
||||
|
||||
M.mod_quiz.init_review_form = function(Y) {
|
||||
Y.all('.questionflagsavebutton').remove();
|
||||
|
||||
Y.on('key', function (e) {
|
||||
if (!e.target.test('a') && !e.target.test('input[type=submit]') &&
|
||||
!e.target.test('input[type=img]')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}, '.questionflagsaveform', 'press:13');
|
||||
|
||||
M.core_question_engine.init_form(Y, '.questionflagsaveform');
|
||||
Y.on('submit', function(e) { e.halt(); }, '.questionflagsaveform');
|
||||
};
|
||||
|
||||
|
@ -219,6 +219,8 @@
|
||||
}
|
||||
$number = 1;
|
||||
echo '<form method="post" action="'.$url->out_omit_querystring().'" enctype="multipart/form-data" id="responseform">', "\n";
|
||||
$PAGE->requires->js_init_call('M.core_question_engine.init_form', array('#responseform'));
|
||||
|
||||
print_question($questions[$id], $curstate, $number, $quiz, $options, $context);
|
||||
|
||||
echo '<div class="controls">';
|
||||
|
23
question/qengine.js
Normal file
23
question/qengine.js
Normal file
@ -0,0 +1,23 @@
|
||||
M.core_question_engine = M.core_question_engine || {};
|
||||
|
||||
/**
|
||||
* Initialise a form that contains questions printed using print_question.
|
||||
* This has the effect of:
|
||||
* 1. Turning off browser autocomlete.
|
||||
* 2. Stopping enter from submitting the form (or toggling the next flag) unless
|
||||
* keyboard focus is on the submit button or the flag.
|
||||
* 3. Removes any '.questionflagsavebutton's, since we have JavaScript to toggle
|
||||
* the flags using Ajax.
|
||||
* @param Y the Yahoo object. Needs to have the DOM and Event modules loaded.
|
||||
* @param form something that can be passed to Y.one, to find the form element.
|
||||
*/
|
||||
M.core_question_engine.init_form = function(Y, form) {
|
||||
Y.one(form).setAttribute('autocomplete', 'off');
|
||||
Y.on('key', function (e) {
|
||||
if (!e.target.test('a') && !e.target.test('input[type=submit]') &&
|
||||
!e.target.test('input[type=img]')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}, form, 'press:13');
|
||||
Y.one(form).all('.questionflagsavebutton').remove();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user