Fixed autosave recognizing empty values
authorAlexander Ebert <ebert@woltlab.com>
Thu, 22 Sep 2016 10:41:15 +0000 (12:41 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 22 Sep 2016 10:41:23 +0000 (12:41 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Autosave.js

index 92194d42a502a044d87513027e9f560f12aa528e..a2ded726b549bba6daded4c715ef8ccd6d3c6c22 100644 (file)
@@ -72,18 +72,15 @@ define(['Language', 'Dom/Traverse'], function(Language, DomTraverse) {
                        }
                        
                        // check if storage is outdated
-                       if (value !== null && typeof value === 'object') {
+                       if (value !== null && typeof value === 'object' && value.content) {
                                var lastEditTime = ~~elData(this._element, 'autosave-last-edit-time');
-                               if (lastEditTime * 1000 > value.timestamp) {
+                               if (lastEditTime * 1000 <= value.timestamp) {
                                        //noinspection JSUnresolvedVariable
-                                       return this._element.value;
+                                       this._originalMessage = this._element.value;
+                                       this._restored = true;
+                                       
+                                       return value.content;
                                }
-                               
-                               //noinspection JSUnresolvedVariable
-                               this._originalMessage = this._element.value;
-                               this._restored = true;
-                               
-                               return value.content;
                        }
                        
                        //noinspection JSUnresolvedVariable
@@ -225,6 +222,10 @@ define(['Language', 'Dom/Traverse'], function(Language, DomTraverse) {
                                return;
                        }
                        
+                       if (content === '') {
+                               return this.clear();
+                       }
+                       
                        try {
                                window.localStorage.setItem(this._key, JSON.stringify({
                                        content: content,