1// For IE8 and earlier version. 2// http://afuchs.tumblr.com/post/23550124774/date-now-in-ie8 3Date.now = Date.now || function() { return +new Date; }; 4 5jQuery(function () { 6 if (!JSINFO.autologoff) return; 7 8 9 var autologofftimer = window.setTimeout(autologoff_check, (JSINFO.autologoff - 1) * 60 * 1000); 10 var autologoffrefresh = Date.now(); 11 12 jQuery('body').keypress(function(){ 13 if((Date.now() - autologoffrefresh) < 60*1000) return; 14 autologoffrefresh = Date.now(); 15 autologoff_refresh(); 16 }); 17 18 function autologoff_check() { 19 20 jQuery.post(DOKU_BASE + 'lib/exe/ajax.php', 21 {call: 'autologoff'}, 22 function (timeremains) { 23 if (timeremains <= 0) { 24 // remove any onunload handlers 25 window.onbeforeunload = function(){}; 26 window.onunload = function(){}; 27 // log off 28 window.location.reload(); 29 } else { 30 timeremains -= 65; 31 if (timeremains <= 0) { 32 var $dialog = jQuery('<div>' + LANG.plugins.autologoff.warn + '</div>'); 33 $dialog.attr('title', LANG.plugins.autologoff.title); 34 $dialog.appendTo(document.body); 35 36 37 var buttons = {}; 38 buttons[LANG.plugins.autologoff.stillhere] = function () { 39 autologoff_refresh(); 40 jQuery(this).dialog('close'); 41 }; 42 43 44 $dialog.dialog({ 45 modal: true, 46 buttons: buttons 47 }); 48 49 timeremains = 60; 50 } 51 52 window.clearTimeout(autologofftimer); 53 autologofftimer = window.setTimeout(autologoff_check, timeremains * 1000); 54 } 55 } 56 ); 57 } 58 59 function autologoff_refresh() { 60 jQuery.post(DOKU_BASE + 'lib/exe/ajax.php', 61 {call: 'autologoff', refresh: 1}, 62 function(timeremains){ 63 window.clearTimeout(autologofftimer); 64 autologofftimer = window.setTimeout(autologoff_check, (timeremains - 60) * 1000); 65 } 66 ); 67 } 68 69}); 70