Skip to content

Commit

Permalink
Item14797: make it work on multiple tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Dec 7, 2018
1 parent 24760f2 commit 3321cb9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
6 changes: 4 additions & 2 deletions data/System/JQAutoLogoutContrib.txt
@@ -1,6 +1,7 @@
%META:TOPICINFO{author="micha" comment="reprev" date="1543502605" format="1.1" reprev="2" version="2"}%
---+!! %TOPIC%
%$SHORTDESCRIPTION%
%FORMFIELD{"Description"}%


%TOC%

Expand Down Expand Up @@ -59,13 +60,14 @@ Note that a single sign on login manager might log you in right after having you
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 07 Dec 2018 | make it work on multiple tabs |
| 29 Nov 2018 | initial release |

%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="Michael Daum"}%
%META:FIELD{name="Version" title="Version" value="%25$VERSION%25"}%
%META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}%
%META:FIELD{name="Description" title="Description" value=""}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/%25$ROOTMODULE%25"}%
%META:FIELD{name="Copyright" title="Copyright" value="2018, MichaelDaum, All Rights Reserved"}%
%META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}%
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Contrib/JQAutoLogoutContrib.pm
Expand Up @@ -20,8 +20,8 @@ use warnings;

use Foswiki::Func ();

our $VERSION = '1.00';
our $RELEASE = '29 Nov 2018';
our $VERSION = '1.01';
our $RELEASE = '07 Dec 2018';
our $SHORTDESCRIPTION = 'Log out idle user after a certain period of time';
our $NO_PREFS_IN_TOPIC = 1;

Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Contrib/JQAutoLogoutContrib/Core.pm
Expand Up @@ -29,7 +29,7 @@ sub new {
my $this = bless(
$class->SUPER::new(
name => 'JQAutoLogoutContrib',
version => '1.0',
version => '1.01',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Extensions/JQAutoLogoutContrib',
javascript => ['autologout.js'],
Expand Down
45 changes: 40 additions & 5 deletions pub/System/JQAutoLogoutContrib/autologout.uncompressed.js
@@ -1,5 +1,5 @@
/*
* AutoLogout
* AutoLogout 1.01
*
* Copyright (c) 2018 Michael Daum https://michaeldaumconsulting.com
*
Expand All @@ -18,7 +18,8 @@
disableIf: null,
idleTimeout: 900, // 15 minutes
countdown: 10,
logoutUrl: null
logoutUrl: null,
localStorageId: "jqAutoLogout.startTime"
};

// The actual plugin constructor
Expand Down Expand Up @@ -83,8 +84,9 @@
AutoLogout.prototype.tickCountdown = function (val) {
var self = this;

if (self.idleTimer) {
if (self.idleTimer || self.getIdleTime() < self.opts.idleTimeout) {
//console.log("countdown aborted");
self.elem.dialog("close");
return; // abort
}

Expand All @@ -106,12 +108,45 @@
self.stopTimer();

if (self.isEnabled()) {

// remember when this timer started
self.setStartTime();

self.idleTimer = setTimeout(function() {
self.openDialog();
if (self.getIdleTime() >= self.opts.idleTimeout) {
self.openDialog();
} else {
self.startTimer();
}
}, self.opts.idleTimeout * 1000);
}
};

AutoLogout.prototype.setStartTime = function() {
var self = this;

localStorage.setItem(self.opts.localStorageId, Date.now());
};

AutoLogout.prototype.getStartTime = function() {
var self = this, startTime;

startTime = localStorage.getItem(self.opts.localStorageId);

if (typeof(startTime) !== 'string') {
//console.log("no idle start time");
return 0;
}

return parseInt(startTime, 10)
};

AutoLogout.prototype.getIdleTime = function() {
var self = this;

return Math.floor((Date.now() - self.getStartTime()) / 1000);
};

AutoLogout.prototype.stopTimer = function () {
var self = this;

Expand All @@ -126,14 +161,14 @@

//console.log("redirecting to ",self.opts.logoutUrl);
window.location.href = self.opts.logoutUrl;
localStore.removeItem(self.opts.localStorageId);
};

AutoLogout.prototype.openDialog = function() {
var self = this;

self.stopTimer();


self.elem.dialog("open");
};

Expand Down

0 comments on commit 3321cb9

Please sign in to comment.