forked from anandgorantala/Form-Savior
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.formSavior.js
More file actions
41 lines (33 loc) · 798 Bytes
/
jquery.formSavior.js
File metadata and controls
41 lines (33 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(function( $ ){
$.fn.formSavior = function(options) {
return this.each(function() {
var cfg = {
'msg' : 'There are unsaved changes on this form',
'noprompt' : 'noprompt'
};
if ( options ) {
$.extend( cfg, options );
}
var originals = '';
var showalert = true;
var $form = $(this);
$win = $(window);
$doc = $(document);
function saveOriginals() {
originals = $form.serialize();
}
function allowSave() {
showalert = false;
}
function savePrompt() {
current = $form.serialize();
if(current != originals && showalert === true && !$form.hasClass(cfg.noprompt)) {
return cfg.msg;
}
}
$doc.ready(saveOriginals);
$form.submit(allowSave);
$win.bind('beforeunload', savePrompt);
});
};
})( jQuery );