(function($){
$.fn.userActionTimeout = function (time, name) {
function setCookie (key, value, expires, path, domain, secure) {
var sCookie = key+'='+escape(value)+'; ';
if(expires !== undefined) {
var date = new Date();
date.setTime(date.getTime()+(expires*24*60*60*1000));
sCookie+= 'expires='+date.toGMTString()+'; ';
}
sCookie+= (path === undefined) ? 'path=/;' : 'path='+path+'; ';
sCookie+= (domain === undefined) ? '' : 'domain='+domain+'; '
sCookie+= (secure === true) ? 'secure; ' : '';
document.cookie = sCookie;
}
function getCookie (sKey) {
var sValue = '';
var sKeyEq = sKey+ '=';
var aCookies = document.cookie.split(';');
for(var iCounter = 0, iCookieLength = aCookies.length; iCounter < iCookieLength; iCounter++) {
while(aCookies[iCounter].charAt(0) === ' ') {
aCookies[iCounter] = aCookies[iCounter].substring(1);
}
if(aCookies[iCounter].indexOf(sKeyEq) === 0) {
sValue = aCookies[iCounter].substring(sKeyEq.length);
}
}
return unescape(sValue);
}
function removeCookie (key) {
setCookie(key, '', -1);
}
var time = time || 1000
, name = name || 'auth'
, setTimer = function (time, name) {
setTimeout(function(){
if (getCookie(name)) {
removeCookie(name);
}
$(document).off('click', clearTimer);
$(document).off('keydown', clearTimer);
}, time);
}
, clearTimer = function() {
clearTimeout(timeout);
timeout = setTimer(time, name);
}
, timeout = setTimer(time, name);
$(document).on('click', clearTimer);
$(document).on('keydown', clearTimer);
return this;
};
})(jQuery);
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.user_action_timeout.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$().userActionTimeout(1000, 'auth');
});
</script>
<title>Плагин jQuery</title>
</head>
<body>
</body>
</html>
Комментариев нет:
Отправить комментарий