changeset 2706:c7fe669a6c5c

Fixes issue #451 Now the modify page prompts users if they try to leave the page without saving the changes, in all themes. Also it gives the prompt only when the user has made a change.
author Ajitesh Gupta <ajgupta93@gmail.com>
date Thu, 14 Aug 2014 20:58:27 +0530
parents 2b549df8b3b0
children a6c76ccde011
files MoinMoin/static/js/common.js MoinMoin/templates/basic.js MoinMoin/themes/basic/templates/modify.html
diffstat 3 files changed, 11 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/static/js/common.js	Sun Aug 10 00:06:51 2014 +0530
+++ b/MoinMoin/static/js/common.js	Thu Aug 14 20:58:27 2014 +0530
@@ -665,6 +665,17 @@
     moin.enhanceUserSettings();
     moin.enhanceEdit();
     $('.moin-sortable').tablesorter();
+
+    $('#moin-modify').on('change keyup keydown', 'input, textarea, select', function (e) {
+        $(this).addClass('moin-changed-input');
+    });
+
+    $(window).on('beforeunload', function() {
+        if ($('.moin-changed-input').length) {
+            return "Data you may have entered will be discarded!";
+        }
+    });
+
     // placing initToggleComments after enhanceEdit prevents odd autoscroll issue when editing hidden comments
     moin.initToggleComments();
 });
--- a/MoinMoin/templates/basic.js	Sun Aug 10 00:06:51 2014 +0530
+++ b/MoinMoin/templates/basic.js	Thu Aug 14 20:58:27 2014 +0530
@@ -4,18 +4,6 @@
     $('#meta, #help').removeClass('active');
     $('#password, #notification, #ui, #navigation, #options, #acl, #subscriptions').removeClass('active');
     $('textarea').autosize();
-    $('#moin-save-text-button').click(function (){
-        edit = true;
-    });
-    window.onbeforeunload = function(e) {
-        // previously checked if the URL is of the form http://host/+modify/page
-        // it is bad way if we rewrite URL's, hence used a div with id -> "checkmodifyview" in the modify view
-        var test = $('#checkmodifyview').length;
-        if (test == 1 && edit == false) {
-            return "Data you may have entered will be discarded!";
-        }
-        edit = false;
-    }
     $('div.dropup').removeClass('menu');
     $('ul.dropdown-menu').removeClass('submenu');
     $('.topnavcollapse').addClass('collapse');
--- a/MoinMoin/themes/basic/templates/modify.html	Sun Aug 10 00:06:51 2014 +0530
+++ b/MoinMoin/themes/basic/templates/modify.html	Thu Aug 14 20:58:27 2014 +0530
@@ -26,7 +26,6 @@
 {% block content %}
 <h2>{{ title }}</h2>
 <div id="moin-modify" class="moin-form">
-    <div id="checkmodifyview"> </div>
     {{ gen.form.open(form, method='post', enctype='multipart/form-data') }}
     {{ forms.render_errors(form) }}
     {{ forms.render_errors(form['meta_form']['acl']) }}