-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
69 lines (55 loc) · 2.3 KB
/
script.js
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
// For IE8 and earlier version.
// http://afuchs.tumblr.com/post/23550124774/date-now-in-ie8
Date.now = Date.now || function() { return +new Date; };
jQuery(function () {
if (!JSINFO.autologoff) return;
var autologofftimer = window.setTimeout(autologoff_check, (JSINFO.autologoff - 1) * 60 * 1000);
var autologoffrefresh = Date.now();
jQuery('body').keypress(function(){
if((Date.now() - autologoffrefresh) < 60*1000) return;
autologoffrefresh = Date.now();
autologoff_refresh();
});
function autologoff_check() {
jQuery.post(DOKU_BASE + 'lib/exe/ajax.php',
{call: 'autologoff'},
function (timeremains) {
if (timeremains <= 0) {
// remove any onunload handlers
window.onbeforeunload = function(){};
window.onunload = function(){};
// log off
window.location.reload();
} else {
timeremains -= 65;
if (timeremains <= 0) {
var $dialog = jQuery('<div>' + LANG.plugins.autologoff.warn + '</div>');
$dialog.attr('title', LANG.plugins.autologoff.title);
$dialog.appendTo(document.body);
var buttons = {};
buttons[LANG.plugins.autologoff.stillhere] = function () {
autologoff_refresh();
jQuery(this).dialog('close');
};
$dialog.dialog({
modal: true,
buttons: buttons
});
timeremains = 60;
}
window.clearTimeout(autologofftimer);
autologofftimer = window.setTimeout(autologoff_check, timeremains * 1000);
}
}
);
}
function autologoff_refresh() {
jQuery.post(DOKU_BASE + 'lib/exe/ajax.php',
{call: 'autologoff', refresh: 1},
function(timeremains){
window.clearTimeout(autologofftimer);
autologofftimer = window.setTimeout(autologoff_check, (timeremains - 60) * 1000);
}
);
}
});