MDL-52954 atto: Stop autosave timer, when editor no-longer exists.

This commit is contained in:
Damyon Wiese
2016-03-30 11:48:40 +08:00
parent 1356d85151
commit b803df8170
4 changed files with 48 additions and 6 deletions
@@ -820,6 +820,14 @@ EditorAutosave.prototype = {
*/
autosaveInstance: null,
/**
* Autosave Timer.
*
* @property autosaveTimer
* @type object
*/
autosaveTimer: null,
/**
* Initialize the autosave process
*
@@ -904,7 +912,7 @@ EditorAutosave.prototype = {
// Now setup the timer for periodic saves.
var delay = parseInt(this.get('autosaveFrequency'), 10) * 1000;
Y.later(delay, this, this.saveDraft, false, true);
this.autosaveTimer = Y.later(delay, this, this.saveDraft, false, true);
// Now setup the listener for form submission.
form = this.textarea.ancestor('form');
@@ -968,6 +976,12 @@ EditorAutosave.prototype = {
*/
saveDraft: function() {
var url, params;
if (!this.editor.getDOMNode()) {
// Stop autosaving if the editor was removed from the page.
this.autosaveTimer.cancel();
return;
}
// Only copy the text from the div to the textarea if the textarea is not currently visible.
if (!this.editor.get('hidden')) {
this.updateOriginal();
File diff suppressed because one or more lines are too long
@@ -815,6 +815,14 @@ EditorAutosave.prototype = {
*/
autosaveInstance: null,
/**
* Autosave Timer.
*
* @property autosaveTimer
* @type object
*/
autosaveTimer: null,
/**
* Initialize the autosave process
*
@@ -897,7 +905,7 @@ EditorAutosave.prototype = {
// Now setup the timer for periodic saves.
var delay = parseInt(this.get('autosaveFrequency'), 10) * 1000;
Y.later(delay, this, this.saveDraft, false, true);
this.autosaveTimer = Y.later(delay, this, this.saveDraft, false, true);
// Now setup the listener for form submission.
form = this.textarea.ancestor('form');
@@ -961,6 +969,12 @@ EditorAutosave.prototype = {
*/
saveDraft: function() {
var url, params;
if (!this.editor.getDOMNode()) {
// Stop autosaving if the editor was removed from the page.
this.autosaveTimer.cancel();
return;
}
// Only copy the text from the div to the textarea if the textarea is not currently visible.
if (!this.editor.get('hidden')) {
this.updateOriginal();
+15 -1
View File
@@ -99,6 +99,14 @@ EditorAutosave.prototype = {
*/
autosaveInstance: null,
/**
* Autosave Timer.
*
* @property autosaveTimer
* @type object
*/
autosaveTimer: null,
/**
* Initialize the autosave process
*
@@ -183,7 +191,7 @@ EditorAutosave.prototype = {
// Now setup the timer for periodic saves.
var delay = parseInt(this.get('autosaveFrequency'), 10) * 1000;
Y.later(delay, this, this.saveDraft, false, true);
this.autosaveTimer = Y.later(delay, this, this.saveDraft, false, true);
// Now setup the listener for form submission.
form = this.textarea.ancestor('form');
@@ -247,6 +255,12 @@ EditorAutosave.prototype = {
*/
saveDraft: function() {
var url, params;
if (!this.editor.getDOMNode()) {
// Stop autosaving if the editor was removed from the page.
this.autosaveTimer.cancel();
return;
}
// Only copy the text from the div to the textarea if the textarea is not currently visible.
if (!this.editor.get('hidden')) {
this.updateOriginal();