Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-38538 quiz autosave: fix JavaScript errors.

1. Make cancelling the delay more robust.
2. Ignore changes in flag state. They are already saved using AJAX.
3. Typo that caused an error when there was no TinyMCE on the page.
  • Loading branch information...
commit e3485c5f75c99440e5c73d3119cd15355342edaa 1 parent aa81e35
@timhunt timhunt authored
View
8 mod/quiz/yui/build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave-coverage.js
@@ -26,7 +26,7 @@ _yuitest_coverage["build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js"]
path: "build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js",
code: []
};
-_yuitest_coverage["build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js"].code=["YUI.add('moodle-mod_quiz-autosave', function (Y, NAME) {","","// 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/>.","","","/**"," * Auto-save functionality for during quiz attempts."," *"," * @package mod_quiz"," * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","M.mod_quiz = M.mod_quiz || {};","M.mod_quiz.autosave = {"," /** Delays and repeat counts. */"," TINYMCE_DETECTION_DELAY: 500,"," TINYMCE_DETECTION_REPEATS: 20,"," WATCH_HIDDEN_DELAY: 1000,",""," /** Selectors. */"," SELECTORS: {"," QUIZ_FORM: '#responseform',"," VALUE_CHANGE_ELEMENTS: 'input, textarea',"," CHANGE_ELEMENTS: 'input, select',"," HIDDEN_INPUTS: 'input[type=hidden]'"," },",""," /** Script that handles the auto-saves. */"," AUTOSAVE_HANDLER: M.cfg.wwwroot + '/mod/quiz/autosave.ajax.php',",""," /** The delay between a change being made, and it being auto-saved. */"," delay: 120000,",""," /** The form we are monitoring. */"," form: null,",""," /** Whether the form has been modified since the last save started. */"," dirty: false,",""," /** Timer object for the delay between form modifaction and the save starting. */"," delay_timer: null,",""," /** Y.io transaction for the save ajax request. */"," save_transaction: null,",""," /** Properly bound key change handler. */"," editor_change_handler: null,",""," hidden_field_values: {},",""," /**"," * Initialise the autosave code."," * @param delay the delay, in seconds, between a change being detected, and"," * a save happening."," */"," init: function(delay) {"," this.form = Y.one(this.SELECTORS.QUIZ_FORM);"," if (!this.form) {"," return;"," }",""," this.delay = delay * 1000;",""," this.form.delegate('valuechange', this.value_changed, this.SELECTORS.VALUE_CHANGE_ELEMENTS, this);"," this.form.delegate('change', this.value_changed, this.SELECTORS.CHANGE_ELEMENTS, this);"," this.form.on('submit', this.stop_autosaving, this);",""," this.init_tinymce(this.TINYMCE_DETECTION_REPEATS);",""," this.save_hidden_field_values();"," this.watch_hidden_fields();"," },",""," save_hidden_field_values: function() {"," this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(hidden) {"," var name = hidden.get('name');"," if (!name) {"," return;"," }"," this.hidden_field_values[name] = hidden.get('value');"," }, this);"," },",""," watch_hidden_fields: function() {"," this.detect_hidden_field_changes();"," Y.later(this.WATCH_HIDDEN_DELAY, this, this.watch_hidden_fields);"," },",""," detect_hidden_field_changes: function() {"," this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(hidden) {"," var name = hidden.get('name'),"," value = hidden.get('value');"," if (!name) {"," return;"," }"," if (!(name in this.hidden_field_values) || value !== this.hidden_field_values[name]) {"," this.hidden_field_values[name] = value;"," this.value_changed({target: hidden});"," }"," }, this);"," },",""," /**"," * @param repeatcount Because TinyMCE might load slowly, after us, we need"," * to keep trying every 10 seconds or so, until we detect TinyMCE is there,"," * or enough time has passed."," */"," init_tinymce: function(repeatcount) {"," if (typeof tinymce === 'undefined') {"," if (repeatcount > 0) {"," Y.later(this.TINYMCE_DETECTION_DELAY, this, self.init_tinymce,repeatcount - 1);"," }"," return;"," }",""," this.editor_change_handler = Y.bind(this.editor_changed, this);"," tinyMCE.onAddEditor.add(Y.bind(this.init_tinymce_editor, this));"," },",""," /**"," * @param repeatcount Because TinyMCE might load slowly, after us, we need"," * to keep trying every 10 seconds or so, until we detect TinyMCE is there,"," * or enough time has passed."," */"," init_tinymce_editor: function(notused, editor) {"," editor.onChange.add(this.editor_change_handler);"," editor.onRedo.add(this.editor_change_handler);"," editor.onUndo.add(this.editor_change_handler);"," editor.onKeyDown.add(this.editor_change_handler);"," },",""," value_changed: function(e) {"," if (e.target.get('name') === 'thispage') {"," return; // Not interesting."," }"," this.start_save_timer_if_necessary();"," },",""," editor_changed: function(editor) {"," this.start_save_timer_if_necessary();"," },",""," start_save_timer_if_necessary: function() {"," this.dirty = true;",""," if (this.delay_timer || this.save_transaction) {"," // Already counting down or daving."," return;"," }",""," this.start_save_timer();"," },",""," start_save_timer: function() {"," this.cancel_delay();"," this.delay_timer = Y.later(this.delay, this, this.save_changes);"," },",""," cancel_delay: function() {"," if (this.delay_timer) {"," this.delay_timer.cancel();"," }"," this.delay_timer = null;"," },",""," save_changes: function() {"," this.cancel_delay();"," this.dirty = false;",""," if (this.is_time_nearly_over()) {"," this.stop_autosaving();"," return;"," }",""," this.save_transaction = Y.io(this.AUTOSAVE_HANDLER, {"," method: 'POST',"," form: {id: this.form},"," on: {complete: this.save_done},"," context: this"," });"," },",""," save_done: function() {"," this.save_transaction = null;",""," if (this.dirty) {"," this.start_save_timer();"," }"," },",""," is_time_nearly_over: function() {"," return M.mod_quiz.timer && M.mod_quiz.timer.endtime &&"," (new Date().getTime() + 2*this.delay) > M.mod_quiz.timer.endtime;"," },",""," stop_autosaving: function() {"," this.cancel_delay();"," this.delay_timer = true;"," if (this.save_transaction) {"," this.save_transaction.abort();"," }"," }","};","","","}, '@VERSION@', {\"requires\": [\"base\", \"node\", \"event\", \"event-valuechange\", \"node-event-delegate\", \"io-form\"]});"];
+_yuitest_coverage["build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js"].code=["YUI.add('moodle-mod_quiz-autosave', function (Y, NAME) {","","// 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/>.","","","/**"," * Auto-save functionality for during quiz attempts."," *"," * @package mod_quiz"," * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}"," * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later"," */","","M.mod_quiz = M.mod_quiz || {};","M.mod_quiz.autosave = {"," /** Delays and repeat counts. */"," TINYMCE_DETECTION_DELAY: 500,"," TINYMCE_DETECTION_REPEATS: 20,"," WATCH_HIDDEN_DELAY: 1000,",""," /** Selectors. */"," SELECTORS: {"," QUIZ_FORM: '#responseform',"," VALUE_CHANGE_ELEMENTS: 'input, textarea',"," CHANGE_ELEMENTS: 'input, select',"," HIDDEN_INPUTS: 'input[type=hidden]'"," },",""," /** Script that handles the auto-saves. */"," AUTOSAVE_HANDLER: M.cfg.wwwroot + '/mod/quiz/autosave.ajax.php',",""," /** The delay between a change being made, and it being auto-saved. */"," delay: 120000,",""," /** The form we are monitoring. */"," form: null,",""," /** Whether the form has been modified since the last save started. */"," dirty: false,",""," /** Timer object for the delay between form modifaction and the save starting. */"," delay_timer: null,",""," /** Y.io transaction for the save ajax request. */"," save_transaction: null,",""," /** Properly bound key change handler. */"," editor_change_handler: null,",""," hidden_field_values: {},",""," /**"," * Initialise the autosave code."," * @param delay the delay, in seconds, between a change being detected, and"," * a save happening."," */"," init: function(delay) {"," this.form = Y.one(this.SELECTORS.QUIZ_FORM);"," if (!this.form) {"," return;"," }",""," this.delay = delay * 1000;",""," this.form.delegate('valuechange', this.value_changed, this.SELECTORS.VALUE_CHANGE_ELEMENTS, this);"," this.form.delegate('change', this.value_changed, this.SELECTORS.CHANGE_ELEMENTS, this);"," this.form.on('submit', this.stop_autosaving, this);",""," this.init_tinymce(this.TINYMCE_DETECTION_REPEATS);",""," this.save_hidden_field_values();"," this.watch_hidden_fields();"," },",""," save_hidden_field_values: function() {"," this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(hidden) {"," var name = hidden.get('name');"," if (!name) {"," return;"," }"," this.hidden_field_values[name] = hidden.get('value');"," }, this);"," },",""," watch_hidden_fields: function() {"," this.detect_hidden_field_changes();"," Y.later(this.WATCH_HIDDEN_DELAY, this, this.watch_hidden_fields);"," },",""," detect_hidden_field_changes: function() {"," this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(hidden) {"," var name = hidden.get('name'),"," value = hidden.get('value');"," if (!name) {"," return;"," }"," if (!(name in this.hidden_field_values) || value !== this.hidden_field_values[name]) {"," this.hidden_field_values[name] = value;"," this.value_changed({target: hidden});"," }"," }, this);"," },",""," /**"," * @param repeatcount Because TinyMCE might load slowly, after us, we need"," * to keep trying every 10 seconds or so, until we detect TinyMCE is there,"," * or enough time has passed."," */"," init_tinymce: function(repeatcount) {"," if (typeof tinymce === 'undefined') {"," if (repeatcount > 0) {"," Y.later(this.TINYMCE_DETECTION_DELAY, this, this.init_tinymce, [repeatcount - 1]);"," }"," return;"," }",""," this.editor_change_handler = Y.bind(this.editor_changed, this);"," tinyMCE.onAddEditor.add(Y.bind(this.init_tinymce_editor, this));"," },",""," /**"," * @param repeatcount Because TinyMCE might load slowly, after us, we need"," * to keep trying every 10 seconds or so, until we detect TinyMCE is there,"," * or enough time has passed."," */"," init_tinymce_editor: function(notused, editor) {"," editor.onChange.add(this.editor_change_handler);"," editor.onRedo.add(this.editor_change_handler);"," editor.onUndo.add(this.editor_change_handler);"," editor.onKeyDown.add(this.editor_change_handler);"," },",""," value_changed: function(e) {"," if (e.target.get('name') === 'thispage' || e.target.get('name').match(/_:flagged$/)) {"," return; // Not interesting."," }"," this.start_save_timer_if_necessary();"," },",""," editor_changed: function(editor) {"," this.start_save_timer_if_necessary();"," },",""," start_save_timer_if_necessary: function() {"," this.dirty = true;",""," if (this.delay_timer || this.save_transaction) {"," // Already counting down or daving."," return;"," }",""," this.start_save_timer();"," },",""," start_save_timer: function() {"," this.cancel_delay();"," this.delay_timer = Y.later(this.delay, this, this.save_changes);"," },",""," cancel_delay: function() {"," if (this.delay_timer && this.delay_timer !== true) {"," this.delay_timer.cancel();"," }"," this.delay_timer = null;"," },",""," save_changes: function() {"," this.cancel_delay();"," this.dirty = false;",""," if (this.is_time_nearly_over()) {"," this.stop_autosaving();"," return;"," }",""," this.save_transaction = Y.io(this.AUTOSAVE_HANDLER, {"," method: 'POST',"," form: {id: this.form},"," on: {complete: this.save_done},"," context: this"," });"," },",""," save_done: function() {"," this.save_transaction = null;",""," if (this.dirty) {"," this.start_save_timer();"," }"," },",""," is_time_nearly_over: function() {"," return M.mod_quiz.timer && M.mod_quiz.timer.endtime &&"," (new Date().getTime() + 2*this.delay) > M.mod_quiz.timer.endtime;"," },",""," stop_autosaving: function() {"," this.cancel_delay();"," this.delay_timer = true;"," if (this.save_transaction) {"," this.save_transaction.abort();"," }"," }","};","","","}, '@VERSION@', {\"requires\": [\"base\", \"node\", \"event\", \"event-valuechange\", \"node-event-delegate\", \"io-form\"]});"];
_yuitest_coverage["build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js"].lines = {"1":0,"27":0,"28":0,"71":0,"72":0,"73":0,"76":0,"78":0,"79":0,"80":0,"82":0,"84":0,"85":0,"89":0,"90":0,"91":0,"92":0,"94":0,"99":0,"100":0,"104":0,"105":0,"107":0,"108":0,"110":0,"111":0,"112":0,"123":0,"124":0,"125":0,"127":0,"130":0,"131":0,"140":0,"141":0,"142":0,"143":0,"147":0,"148":0,"150":0,"154":0,"158":0,"160":0,"162":0,"165":0,"169":0,"170":0,"174":0,"175":0,"177":0,"181":0,"182":0,"184":0,"185":0,"186":0,"189":0,"198":0,"200":0,"201":0,"206":0,"211":0,"212":0,"213":0,"214":0};
_yuitest_coverage["build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js"].functions = {"init:70":0,"(anonymous 2):89":0,"save_hidden_field_values:88":0,"watch_hidden_fields:98":0,"(anonymous 3):104":0,"detect_hidden_field_changes:103":0,"init_tinymce:122":0,"init_tinymce_editor:139":0,"value_changed:146":0,"editor_changed:153":0,"start_save_timer_if_necessary:157":0,"start_save_timer:168":0,"cancel_delay:173":0,"save_changes:180":0,"save_done:197":0,"is_time_nearly_over:205":0,"stop_autosaving:210":0,"(anonymous 1):1":0};
_yuitest_coverage["build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js"].coveredLines = 64;
@@ -193,7 +193,7 @@ if (typeof tinymce === 'undefined') {
_yuitest_coverline("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", 124);
if (repeatcount > 0) {
_yuitest_coverline("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", 125);
-Y.later(this.TINYMCE_DETECTION_DELAY, this, self.init_tinymce,repeatcount - 1);
+Y.later(this.TINYMCE_DETECTION_DELAY, this, this.init_tinymce, [repeatcount - 1]);
}
_yuitest_coverline("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", 127);
return;
@@ -225,7 +225,7 @@ editor.onKeyDown.add(this.editor_change_handler);
value_changed: function(e) {
_yuitest_coverfunc("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", "value_changed", 146);
_yuitest_coverline("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", 147);
-if (e.target.get('name') === 'thispage') {
+if (e.target.get('name') === 'thispage' || e.target.get('name').match(/_:flagged$/)) {
_yuitest_coverline("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", 148);
return; // Not interesting.
}
@@ -266,7 +266,7 @@ this.delay_timer = Y.later(this.delay, this, this.save_changes);
cancel_delay: function() {
_yuitest_coverfunc("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", "cancel_delay", 173);
_yuitest_coverline("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", 174);
-if (this.delay_timer) {
+if (this.delay_timer && this.delay_timer !== true) {
_yuitest_coverline("build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js", 175);
this.delay_timer.cancel();
}
View
6 mod/quiz/yui/build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave-debug.js
@@ -123,7 +123,7 @@ M.mod_quiz.autosave = {
init_tinymce: function(repeatcount) {
if (typeof tinymce === 'undefined') {
if (repeatcount > 0) {
- Y.later(this.TINYMCE_DETECTION_DELAY, this, self.init_tinymce,repeatcount - 1);
+ Y.later(this.TINYMCE_DETECTION_DELAY, this, this.init_tinymce, [repeatcount - 1]);
}
return;
}
@@ -147,7 +147,7 @@ M.mod_quiz.autosave = {
},
value_changed: function(e) {
- if (e.target.get('name') === 'thispage') {
+ if (e.target.get('name') === 'thispage' || e.target.get('name').match(/_:flagged$/)) {
return; // Not interesting.
}
Y.log('Detected a value change in element ' + e.target.get('name') + '.');
@@ -176,7 +176,7 @@ M.mod_quiz.autosave = {
},
cancel_delay: function() {
- if (this.delay_timer) {
+ if (this.delay_timer && this.delay_timer !== true) {
this.delay_timer.cancel();
}
this.delay_timer = null;
View
2  mod/quiz/yui/build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave-min.js
@@ -1 +1 @@
-YUI.add("moodle-mod_quiz-autosave",function(e,t){M.mod_quiz=M.mod_quiz||{},M.mod_quiz.autosave={TINYMCE_DETECTION_DELAY:500,TINYMCE_DETECTION_REPEATS:20,WATCH_HIDDEN_DELAY:1e3,SELECTORS:{QUIZ_FORM:"#responseform",VALUE_CHANGE_ELEMENTS:"input, textarea",CHANGE_ELEMENTS:"input, select",HIDDEN_INPUTS:"input[type=hidden]"},AUTOSAVE_HANDLER:M.cfg.wwwroot+"/mod/quiz/autosave.ajax.php",delay:12e4,form:null,dirty:!1,delay_timer:null,save_transaction:null,editor_change_handler:null,hidden_field_values:{},init:function(t){this.form=e.one(this.SELECTORS.QUIZ_FORM);if(!this.form)return;this.delay=t*1e3,this.form.delegate("valuechange",this.value_changed,this.SELECTORS.VALUE_CHANGE_ELEMENTS,this),this.form.delegate("change",this.value_changed,this.SELECTORS.CHANGE_ELEMENTS,this),this.form.on("submit",this.stop_autosaving,this),this.init_tinymce(this.TINYMCE_DETECTION_REPEATS),this.save_hidden_field_values(),this.watch_hidden_fields()},save_hidden_field_values:function(){this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(e){var t=e.get("name");if(!t)return;this.hidden_field_values[t]=e.get("value")},this)},watch_hidden_fields:function(){this.detect_hidden_field_changes(),e.later(this.WATCH_HIDDEN_DELAY,this,this.watch_hidden_fields)},detect_hidden_field_changes:function(){this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(e){var t=e.get("name"),n=e.get("value");if(!t)return;if(!(t in this.hidden_field_values)||n!==this.hidden_field_values[t])this.hidden_field_values[t]=n,this.value_changed({target:e})},this)},init_tinymce:function(t){if(typeof tinymce=="undefined"){t>0&&e.later(this.TINYMCE_DETECTION_DELAY,this,self.init_tinymce,t-1);return}this.editor_change_handler=e.bind(this.editor_changed,this),tinyMCE.onAddEditor.add(e.bind(this.init_tinymce_editor,this))},init_tinymce_editor:function(e,t){t.onChange.add(this.editor_change_handler),t.onRedo.add(this.editor_change_handler),t.onUndo.add(this.editor_change_handler),t.onKeyDown.add(this.editor_change_handler)},value_changed:function(e){if(e.target.get("name")==="thispage")return;this.start_save_timer_if_necessary()},editor_changed:function(e){this.start_save_timer_if_necessary()},start_save_timer_if_necessary:function(){this.dirty=!0;if(this.delay_timer||this.save_transaction)return;this.start_save_timer()},start_save_timer:function(){this.cancel_delay(),this.delay_timer=e.later(this.delay,this,this.save_changes)},cancel_delay:function(){this.delay_timer&&this.delay_timer.cancel(),this.delay_timer=null},save_changes:function(){this.cancel_delay(),this.dirty=!1;if(this.is_time_nearly_over()){this.stop_autosaving();return}this.save_transaction=e.io(this.AUTOSAVE_HANDLER,{method:"POST",form:{id:this.form},on:{complete:this.save_done},context:this})},save_done:function(){this.save_transaction=null,this.dirty&&this.start_save_timer()},is_time_nearly_over:function(){return M.mod_quiz.timer&&M.mod_quiz.timer.endtime&&(new Date).getTime()+2*this.delay>M.mod_quiz.timer.endtime},stop_autosaving:function(){this.cancel_delay(),this.delay_timer=!0,this.save_transaction&&this.save_transaction.abort()}}},"@VERSION@",{requires:["base","node","event","event-valuechange","node-event-delegate","io-form"]});
+YUI.add("moodle-mod_quiz-autosave",function(e,t){M.mod_quiz=M.mod_quiz||{},M.mod_quiz.autosave={TINYMCE_DETECTION_DELAY:500,TINYMCE_DETECTION_REPEATS:20,WATCH_HIDDEN_DELAY:1e3,SELECTORS:{QUIZ_FORM:"#responseform",VALUE_CHANGE_ELEMENTS:"input, textarea",CHANGE_ELEMENTS:"input, select",HIDDEN_INPUTS:"input[type=hidden]"},AUTOSAVE_HANDLER:M.cfg.wwwroot+"/mod/quiz/autosave.ajax.php",delay:12e4,form:null,dirty:!1,delay_timer:null,save_transaction:null,editor_change_handler:null,hidden_field_values:{},init:function(t){this.form=e.one(this.SELECTORS.QUIZ_FORM);if(!this.form)return;this.delay=t*1e3,this.form.delegate("valuechange",this.value_changed,this.SELECTORS.VALUE_CHANGE_ELEMENTS,this),this.form.delegate("change",this.value_changed,this.SELECTORS.CHANGE_ELEMENTS,this),this.form.on("submit",this.stop_autosaving,this),this.init_tinymce(this.TINYMCE_DETECTION_REPEATS),this.save_hidden_field_values(),this.watch_hidden_fields()},save_hidden_field_values:function(){this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(e){var t=e.get("name");if(!t)return;this.hidden_field_values[t]=e.get("value")},this)},watch_hidden_fields:function(){this.detect_hidden_field_changes(),e.later(this.WATCH_HIDDEN_DELAY,this,this.watch_hidden_fields)},detect_hidden_field_changes:function(){this.form.all(this.SELECTORS.HIDDEN_INPUTS).each(function(e){var t=e.get("name"),n=e.get("value");if(!t)return;if(!(t in this.hidden_field_values)||n!==this.hidden_field_values[t])this.hidden_field_values[t]=n,this.value_changed({target:e})},this)},init_tinymce:function(t){if(typeof tinymce=="undefined"){t>0&&e.later(this.TINYMCE_DETECTION_DELAY,this,this.init_tinymce,[t-1]);return}this.editor_change_handler=e.bind(this.editor_changed,this),tinyMCE.onAddEditor.add(e.bind(this.init_tinymce_editor,this))},init_tinymce_editor:function(e,t){t.onChange.add(this.editor_change_handler),t.onRedo.add(this.editor_change_handler),t.onUndo.add(this.editor_change_handler),t.onKeyDown.add(this.editor_change_handler)},value_changed:function(e){if(e.target.get("name")==="thispage"||e.target.get("name").match(/_:flagged$/))return;this.start_save_timer_if_necessary()},editor_changed:function(e){this.start_save_timer_if_necessary()},start_save_timer_if_necessary:function(){this.dirty=!0;if(this.delay_timer||this.save_transaction)return;this.start_save_timer()},start_save_timer:function(){this.cancel_delay(),this.delay_timer=e.later(this.delay,this,this.save_changes)},cancel_delay:function(){this.delay_timer&&this.delay_timer!==!0&&this.delay_timer.cancel(),this.delay_timer=null},save_changes:function(){this.cancel_delay(),this.dirty=!1;if(this.is_time_nearly_over()){this.stop_autosaving();return}this.save_transaction=e.io(this.AUTOSAVE_HANDLER,{method:"POST",form:{id:this.form},on:{complete:this.save_done},context:this})},save_done:function(){this.save_transaction=null,this.dirty&&this.start_save_timer()},is_time_nearly_over:function(){return M.mod_quiz.timer&&M.mod_quiz.timer.endtime&&(new Date).getTime()+2*this.delay>M.mod_quiz.timer.endtime},stop_autosaving:function(){this.cancel_delay(),this.delay_timer=!0,this.save_transaction&&this.save_transaction.abort()}}},"@VERSION@",{requires:["base","node","event","event-valuechange","node-event-delegate","io-form"]});
View
6 mod/quiz/yui/build/moodle-mod_quiz-autosave/moodle-mod_quiz-autosave.js
@@ -122,7 +122,7 @@ M.mod_quiz.autosave = {
init_tinymce: function(repeatcount) {
if (typeof tinymce === 'undefined') {
if (repeatcount > 0) {
- Y.later(this.TINYMCE_DETECTION_DELAY, this, self.init_tinymce,repeatcount - 1);
+ Y.later(this.TINYMCE_DETECTION_DELAY, this, this.init_tinymce, [repeatcount - 1]);
}
return;
}
@@ -144,7 +144,7 @@ M.mod_quiz.autosave = {
},
value_changed: function(e) {
- if (e.target.get('name') === 'thispage') {
+ if (e.target.get('name') === 'thispage' || e.target.get('name').match(/_:flagged$/)) {
return; // Not interesting.
}
this.start_save_timer_if_necessary();
@@ -171,7 +171,7 @@ M.mod_quiz.autosave = {
},
cancel_delay: function() {
- if (this.delay_timer) {
+ if (this.delay_timer && this.delay_timer !== true) {
this.delay_timer.cancel();
}
this.delay_timer = null;
View
6 mod/quiz/yui/src/autosave/js/autosave.js
@@ -121,7 +121,7 @@ M.mod_quiz.autosave = {
init_tinymce: function(repeatcount) {
if (typeof tinymce === 'undefined') {
if (repeatcount > 0) {
- Y.later(this.TINYMCE_DETECTION_DELAY, this, self.init_tinymce,repeatcount - 1);
+ Y.later(this.TINYMCE_DETECTION_DELAY, this, this.init_tinymce, [repeatcount - 1]);
}
return;
}
@@ -145,7 +145,7 @@ M.mod_quiz.autosave = {
},
value_changed: function(e) {
- if (e.target.get('name') === 'thispage') {
+ if (e.target.get('name') === 'thispage' || e.target.get('name').match(/_:flagged$/)) {
return; // Not interesting.
}
Y.log('Detected a value change in element ' + e.target.get('name') + '.');
@@ -174,7 +174,7 @@ M.mod_quiz.autosave = {
},
cancel_delay: function() {
- if (this.delay_timer) {
+ if (this.delay_timer && this.delay_timer !== true) {
this.delay_timer.cancel();
}
this.delay_timer = null;
Please sign in to comment.
Something went wrong with that request. Please try again.