"use strict";
var _elements = elByTag('time');
+ var _isActive = true;
+ var _isPending = false;
var _offset = null;
/**
new Repeating(this._refresh.bind(this), 60000);
DomChangeListener.add('WoltLabSuite/Core/Date/Time/Relative', this._refresh.bind(this));
+
+ document.addEventListener('visibilitychange', this._onVisibilityChange.bind(this));
+ },
+
+ _onVisibilityChange: function () {
+ if (document.hidden) {
+ _isActive = false;
+ _isPending = false;
+ }
+ else {
+ _isActive = true;
+
+ // force immediate refresh
+ if (_isPending) {
+ this._refresh();
+ _isPending = false;
+ }
+ }
},
_refresh: function() {
+ // activity is suspended while the tab is hidden, but force an
+ // immediate refresh once the page is active again
+ if (!_isActive) {
+ if (!_isPending) _isPending = true;
+ return;
+ }
+
var date = new Date();
var timestamp = (date.getTime() - date.getMilliseconds()) / 1000;
- if (_offset === null) _offset = timestamp - TIME_NOW;
+ if (_offset === null) _offset = timestamp - window.TIME_NOW;
for (var i = 0, length = _elements.length; i < length; i++) {
var element = _elements[i];
this._metaData = {};
this._editor = null;
this._element = element;
+ this._isActive = true;
+ this._isPending = false;
this._key = Core.getStoragePrefix() + elData(this._element, 'autosave');
this._lastMessage = '';
this._originalMessage = '';
// clear editor content on reset
EventHandler.add('com.woltlab.wcf.redactor2', 'reset_' + this._element.id, this.hideOverlay.bind(this));
+
+ document.addEventListener('visibilitychange', this._onVisibilityChange.bind(this));
+ },
+
+ _onVisibilityChange: function () {
+ if (document.hidden) {
+ this._isActive = false;
+ this._isPending = true;
+ }
+ else {
+ this._isActive = true;
+ this._isPending = false;
+ }
},
/**
this._timer = window.setInterval(this._saveToStorage.bind(this), _frequency * 1000);
this._saveToStorage();
+
+ this._isPending = false;
},
/**
window.clearInterval(this._timer);
this._timer = null;
+ this._isPending = false;
},
/**
* @protected
*/
_saveToStorage: function() {
+ if (!this._isActive) {
+ if (!this._isPending) return;
+
+ // save one last time before suspending
+ this._isPending = false;
+ }
+
//noinspection JSUnresolvedVariable
if (window.ENABLE_DEVELOPER_TOOLS && Devtools._internal_.editorAutosave() === false) {
//noinspection JSUnresolvedVariable