ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç build.json000064400000000267152267037770006563 0ustar00{ "name": "moodle-mod_quiz-autosave", "builds": { "moodle-mod_quiz-autosave": { "jsfiles": [ "autosave.js" ] } } } meta/autosave.json000064400000000407152267037770010235 0ustar00{ "moodle-mod_quiz-autosave": { "requires": [ "base", "node", "event", "event-valuechange", "node-event-delegate", "io-form", "datatype-date-format" ] } } js/autosave.js000064400000034035152267037770007372 0ustar00// 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 . /** * Auto-save functionality for during quiz attempts. * * @module moodle-mod_quiz-autosave */ /** * Auto-save functionality for during quiz attempts. * * @class M.mod_quiz.autosave */ M.mod_quiz = M.mod_quiz || {}; M.mod_quiz.autosave = { /** * The amount of time (in milliseconds) to wait between TinyMCE detections. * * @property TINYMCE_DETECTION_DELAY * @type Number * @default 500 * @private */ TINYMCE_DETECTION_DELAY: 500, /** * The number of times to try redetecting TinyMCE. * * @property TINYMCE_DETECTION_REPEATS * @type Number * @default 20 * @private */ TINYMCE_DETECTION_REPEATS: 20, /** * The delay (in milliseconds) between checking hidden input fields. * * @property WATCH_HIDDEN_DELAY * @type Number * @default 1000 * @private */ WATCH_HIDDEN_DELAY: 1000, /** * The number of failures to ignore before notifying the user. * * @property FAILURES_BEFORE_NOTIFY * @type Number * @default 1 * @private */ FAILURES_BEFORE_NOTIFY: 1, /** * The value to use when resetting the successful save counter. * * @property FIRST_SUCCESSFUL_SAVE * @static * @type Number * @default -1 * @private */ FIRST_SUCCESSFUL_SAVE: -1, /** * The selectors used throughout this class. * * @property SELECTORS * @private * @type Object * @static */ SELECTORS: { QUIZ_FORM: '#responseform', VALUE_CHANGE_ELEMENTS: 'input, textarea, [contenteditable="true"]', CHANGE_ELEMENTS: 'input, select', HIDDEN_INPUTS: 'input[type=hidden]', CONNECTION_ERROR: '#connection-error', CONNECTION_OK: '#connection-ok' }, /** * The script which handles the autosaves. * * @property AUTOSAVE_HANDLER * @type String * @default M.cfg.wwwroot + '/mod/quiz/autosave.ajax.php' * @private */ AUTOSAVE_HANDLER: M.cfg.wwwroot + '/mod/quiz/autosave.ajax.php', /** * The delay (in milliseconds) between a change being made, and it being auto-saved. * * @property delay * @type Number * @default 120000 * @private */ delay: 120000, /** * A Node reference to the form we are monitoring. * * @property form * @type Node * @default null */ form: null, /** * Whether the form has been modified since the last save started. * * @property dirty * @type boolean * @default false */ dirty: false, /** * Timer object for the delay between form modifaction and the save starting. * * @property delay_timer * @type Object * @default null * @private */ delay_timer: null, /** * Y.io transaction for the save ajax request. * * @property save_transaction * @type object * @default null */ save_transaction: null, /** * Failed saves count. * * @property savefailures * @type Number * @default 0 * @private */ savefailures: 0, /** * Properly bound key change handler. * * @property editor_change_handler * @type EventHandle * @default null * @private */ editor_change_handler: null, /** * Record of the value of all the hidden fields, last time they were checked. * * @property hidden_field_values * @type Object * @default {} */ hidden_field_values: {}, /** * Initialise the autosave code. * * @method init * @param {Number} 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) { Y.log('No response form found. Why did you try to set up autosave?', 'debug', 'moodle-mod_quiz-autosave'); 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); require(['core_form/events'], function(FormEvent) { window.addEventListener(FormEvent.eventTypes.uploadChanged, this.value_changed.bind(this)); }.bind(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); }, /** * Initialise watching of TinyMCE specifically. * * Because TinyMCE might load slowly, and after us, we need to keep * trying, until we detect TinyMCE is there, or enough time has passed. * This is based on the TINYMCE_DETECTION_DELAY and * TINYMCE_DETECTION_REPEATS properties. * * * @method init_tinymce * @param {Number} repeatcount The number of attempts made so far. */ init_tinymce: function(repeatcount) { if (typeof window.tinyMCE === 'undefined') { if (repeatcount > 0) { Y.later(this.TINYMCE_DETECTION_DELAY, this, this.init_tinymce, [repeatcount - 1]); } else { Y.log('Gave up looking for TinyMCE.', 'debug', 'moodle-mod_quiz-autosave'); } return; } Y.log('Found TinyMCE.', 'debug', 'moodle-mod_quiz-autosave'); this.editor_change_handler = Y.bind(this.editor_changed, this); if (window.tinyMCE.onAddEditor) { window.tinyMCE.onAddEditor.add(Y.bind(this.init_tinymce_editor, this)); } else if (window.tinyMCE.on) { var startSaveTimer = this.start_save_timer_if_necessary.bind(this); window.tinyMCE.on('AddEditor', function(event) { event.editor.on('Change Undo Redo keydown', startSaveTimer); }); // One or more editors might already have been added, so we have to attach // the event handlers to these as well. window.tinyMCE.get().forEach(function(editor) { editor.on('Change Undo Redo keydown', startSaveTimer); }); } }, /** * Initialise watching of a specific TinyMCE editor. * * @method init_tinymce_editor * @param {EventFacade} e * @param {Object} editor The TinyMCE editor object */ init_tinymce_editor: function(e, editor) { Y.log('Found TinyMCE editor ' + editor.id + '.', 'debug', 'moodle-mod_quiz-autosave'); 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) { var name = e.target.getAttribute('name'); if (name === 'thispage' || name === 'scrollpos' || (name && name.match(/_:flagged$/))) { return; // Not interesting. } // Fallback to the ID when the name is not present (in the case of content editable). name = name || '#' + e.target.getAttribute('id'); Y.log('Detected a value change in element ' + name + '.', 'debug', 'moodle-mod_quiz-autosave'); this.start_save_timer_if_necessary(); }, editor_changed: function(editor) { Y.log('Detected a value change in editor ' + editor.id + '.', 'debug', 'moodle-mod_quiz-autosave'); 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()) { Y.log('No more saving, time is nearly over.', 'debug', 'moodle-mod_quiz-autosave'); this.stop_autosaving(); return; } Y.log('Doing a save.', 'debug', 'moodle-mod_quiz-autosave'); if (typeof window.tinyMCE !== 'undefined') { window.tinyMCE.triggerSave(); } // YUI io.form incorrectly (in my opinion) sends the value of all submit // buttons in the ajax request. We don't want any submit buttons. // Therefore, temporarily change the type. // (Yes, this is a nasty hack. One day this will be re-written as AMD, hopefully). var allsubmitbuttons = this.form.all('input[type=submit], button[type=submit]'); allsubmitbuttons.setAttribute('type', 'button'); this.save_transaction = Y.io(this.AUTOSAVE_HANDLER, { method: 'POST', form: {id: this.form}, on: { success: this.save_done, failure: this.save_failed }, context: this }); // Change the button types back. allsubmitbuttons.setAttribute('type', 'submit'); }, save_done: function(transactionid, response) { var autosavedata = JSON.parse(response.responseText); if (autosavedata.status !== 'OK') { // Because IIS is useless, Moodle can't send proper HTTP response // codes, so we have to detect failures manually. this.save_failed(transactionid, response); return; } if (typeof autosavedata.timeleft !== 'undefined') { Y.log('Updating timer: ' + autosavedata.timeleft + ' seconds remain.', 'debug', 'moodle-mod_quiz-timer'); M.mod_quiz.timer.updateEndTime(autosavedata.timeleft); } this.update_saved_time_display(); Y.log('Save completed.', 'debug', 'moodle-mod_quiz-autosave'); this.save_transaction = null; if (this.dirty) { Y.log('Dirty after save.', 'debug', 'moodle-mod_quiz-autosave'); this.start_save_timer(); } if (this.savefailures > 0) { Y.one(this.SELECTORS.CONNECTION_ERROR).hide(); Y.one(this.SELECTORS.CONNECTION_OK).show(); this.savefailures = this.FIRST_SUCCESSFUL_SAVE; } else if (this.savefailures === this.FIRST_SUCCESSFUL_SAVE) { Y.one(this.SELECTORS.CONNECTION_OK).hide(); this.savefailures = 0; } }, save_failed: function() { Y.log('Save failed.', 'debug', 'moodle-mod_quiz-autosave'); this.save_transaction = null; // We want to retry soon. this.start_save_timer(); this.savefailures = Math.max(1, this.savefailures + 1); if (this.savefailures === this.FAILURES_BEFORE_NOTIFY) { Y.one(this.SELECTORS.CONNECTION_ERROR).show(); Y.one(this.SELECTORS.CONNECTION_OK).hide(); } }, /** * Inform the user that their answers have been saved. * * @method update_saved_time_display */ update_saved_time_display: function() { // We fetch the current language's preferred time format from the language pack. require(['core/user_date', 'core/notification'], function(UserDate, Notification) { UserDate.get([{ timestamp: Math.floor(Date.now() / 1000), format: M.util.get_string('strftimedatetimeshortaccurate', 'langconfig'), }]).then(function(dateStrs) { var infoDiv = Y.one('#mod_quiz_navblock .othernav .autosave_info'); infoDiv.set('text', M.util.get_string('lastautosave', 'quiz', dateStrs[0])); infoDiv.show(); return; }).catch(Notification.exception); }); }, 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(); } } };