/[drupal]/contributions/modules/saveguard/saveguard.js
ViewVC logotype

Contents of /contributions/modules/saveguard/saveguard.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sat Aug 22 06:00:14 2009 UTC (3 months ago) by deekayen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +15 -14 lines
File MIME type: text/javascript
Works on 7.x
1 // $Id: saveguard.js,v 1.1 2007/11/27 20:48:36 starbow Exp $
2
3 /*
4 * Called when there is unsaved data on the page
5 * to warn users leaving (or reloading) page that they would lose their changes.
6 * The onbeforeunload event works in FF, IE and Safari, but not in Opera (yet).
7 * The form of the dialog is unmodifiable:
8 *
9 * Are you sure you want to navigate away from this page?
10 * Your message here
11 * Press OK to continue, or Cancel to stay on the current page.
12 */
13 (function ($) {
14 Drupal.markPageUnsaved = function(msg) {
15 if (!$('body').is('.has-unsaved-changes')) { // Only do it once.
16 $('body').addClass('has-unsaved-changes');
17 if (!msg) { // default message
18 msg = "If you continue your unsaved changes will be lost.";
19 }
20 window.onbeforeunload = function() {return msg;};
21 $(':submit, input:image').click(function() {
22 window.onbeforeunload = null; // Turn off the warning before submit triggers it.
23 });
24 }
25 };
26
27 $(document).ready(function(){
28 msg = Drupal.settings.saveguard.msg;
29 $('input, select').change(function() {Drupal.markPageUnsaved(msg)}); // checkboxes, radio buttons and selects
30 $('input, textarea').keypress(function() {Drupal.markPageUnsaved(msg)}); // textfields and textareas
31 });
32
33 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2