Repository navigation
Expand file tree
/
Copy pathunloadformcheck.js
More file actions
77 lines (71 loc) · 1.54 KB
/
Copy pathunloadformcheck.js
File metadata and controls
77 lines (71 loc) · 1.54 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* \file
* \brief Check for unsaved changes when unloading window.
*
* @package Lwt
* @license unlicense
* @author andreask7 <andreasks7@users.noreply.github.com>
* @since 1.6.16-fork
* @since 2.3.1-fork You should not only include this script to check before unload
* but also call ask_before_exiting once.
*/
/**
* Set to 1 if a form was altered (set "dirty"),
* ask for confirmation before leaving.
*/
var DIRTY = 0;
/**
* Check the DIRTY status and ask before leaving.
*
* @returns {string} Confiramation string
*/
function askConfirmIfDirty(){
if (DIRTY) {
return '** You have unsaved changes! **';
}
}
/**
* Set the DIRTY variable to 1.
*/
function makeDirty() {
DIRTY = 1;
}
/**
* Set the DIRTY variable to 0
*/
function resetDirty() {
DIRTY = 0;
}
/**
* Set DIRTY to 1 if tag object changed.
*
* @param {*} _ An event, unnused
* @param {object} ui UI object
* @returns {true} Always return true
*/
function tagChanged(_, ui) {
if (!ui.duringInitialization) {
DIRTY = 1;
}
return true;
}
/**
* Call this function if you want to ask the user
* before exiting the form.
*
* @returns {undefined}
*/
function ask_before_exiting() {
$('#termtags').tagit({
afterTagAdded: tagChanged,
afterTagRemoved: tagChanged
});
$('#texttags').tagit({
afterTagAdded: tagChanged,
afterTagRemoved: tagChanged
});
$('input,checkbox,textarea,radio,select')
.not('#quickmenu').on('change', makeDirty);
$(':reset,:submit').on('click', resetDirty);
$(window).on('beforeunload', askConfirmIfDirty);
}