roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adityasha...@apache.org
Subject [roller] 01/02: Improved: Editor should confirm user before leaving the page (ROL-2136) On the pages where editors are used, if the user has done some unsaved changes. Before closing window/tab it should confirm user. Done following changes: 1. Included UnsavedChanges plugin for Xinha editor that implicitly handles it 2. Added custom code to add confimation box for text area which adds an event handler to beforeunload event if the text area is changed.
Date Wed, 12 Jun 2019 10:02:44 GMT
This is an automated email from the ASF dual-hosted git repository.

adityasharma pushed a commit to branch ROL-2136-5.2.x
in repository https://gitbox.apache.org/repos/asf/roller.git

commit 7e9460396355007675f27e2794bc868ffb731cf5
Author: Aditya Sharma <iamadityasharma7@gmail.com>
AuthorDate: Mon Jun 3 22:18:19 2019 +0530

    Improved: Editor should confirm user before leaving the page
    (ROL-2136)
    On the pages where editors are used, if the user has done some unsaved changes. Before
closing window/tab it should confirm user.
    Done following changes:
    1. Included UnsavedChanges plugin for Xinha editor that implicitly handles it
    2. Added custom code to add confimation box for text area which adds an event handler
to beforeunload event if the text area is changed.
---
 app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp
index 5050b29..1d463f8 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/EntryEditor.jsp
@@ -125,6 +125,17 @@
                 textAreaElement.focus();
             }
         }
+        // Added event listener to confirm once the editor content is changed
+        jQuery("#edit_content").one("change", function() {
+            console.log("this");
+            jQuery(window).on("beforeunload", function(event) {
+                // Chrome requires returnValue to be set and original event is found as originalEvent
+                // see https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#Example
+                if (event.originalEvent)
+                    event.originalEvent.returnValue = "Are you sure you want to leave?";
+                return "Are you sure you want to leave?";
+            });
+        });
     </script>
 </s:if>
 <s:else>
@@ -169,7 +180,7 @@
                 'edit_content', 'edit_summary'
             ];
 
-            xinha_plugins = xinha_plugins ? xinha_plugins :[];
+            xinha_plugins = xinha_plugins ? xinha_plugins :[ 'UnsavedChanges'];
             if(!Xinha.loadPlugins(xinha_plugins, xinha_init)) return;
 
             xinha_config = xinha_config ? xinha_config() : new Xinha.Config();


Mime
View raw message