Auto clear on form submit
authorAlexander Ebert <ebert@woltlab.com>
Fri, 29 Jul 2016 14:19:48 +0000 (16:19 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 29 Jul 2016 14:35:45 +0000 (16:35 +0200)
wcfsetup/install/files/js/WoltLab/WCF/Ui/Redactor/Autosave.js

index 94fffd21a9f34515d3eb3a5b04ca6fb649ef1365..2871bbc58f82896e0eddc988879a69d2746280da 100644 (file)
@@ -7,7 +7,7 @@
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @module     WoltLab/WCF/Ui/Redactor/Autosave
  */
-define([], function() {
+define(['Dom/Traverse'], function(DomTraverse) {
        "use strict";
        
        // time between save requests in seconds
@@ -38,6 +38,11 @@ define([], function() {
                        
                        // remove attribute to prevent Redactor's built-in autosave to kick in
                        this._element.removeAttribute('data-autosave');
+                       
+                       var form = DomTraverse.parentByTag(this._element, 'FORM');
+                       if (form !== null) {
+                               form.addEventListener('submit', this.destroy.bind(this));
+                       }
                },
                
                /**
@@ -46,7 +51,7 @@ define([], function() {
                 * 
                 * @return      {string}        message content
                 */
-               getInitialValue: function () {
+               getInitialValue: function() {
                        var value = '';
                        try {
                                value = window.localStorage.getItem(this._key);