Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/idle/idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
autoResume: 'idle', // lets events automatically resume (unsets idle state/resets warning)
interrupt: 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll',
windowInterrupt: null,
keepalive: true
keepalive: true,
localStorageKey: 'expiry'
};

/**
Expand Down Expand Up @@ -43,6 +44,14 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
options.keepalive = enabled === true;
};

this.setLocalStorageKey = function(key) {
options.localStorageKey = key;
};

this.getLocalStorageKey = function() {
return options.localStorageKey;
};

this.$get = ['$interval', '$log', '$rootScope', '$document', 'Keepalive', 'IdleLocalStorage', '$window',
function($interval, $log, $rootScope, $document, Keepalive, LocalStorage, $window) {
var state = {
Expand Down Expand Up @@ -133,14 +142,14 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
}

function getExpiry() {
var obj = LocalStorage.get('expiry');
var obj = LocalStorage.get(options.localStorageKey);

return obj && obj.time ? new Date(obj.time) : null;
}

function setExpiry(date) {
if (!date) LocalStorage.remove('expiry');
else LocalStorage.set('expiry', {id: id, time: date});
if (!date) LocalStorage.remove(options.localStorageKey);
else LocalStorage.set(options.localStorageKey, {id: id, time: date});
}

var svc = {
Expand All @@ -150,6 +159,8 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
_getNow: function() {
return new Date();
},
setLocalStorageKey: this.setLocalStorageKey,
getLocalStorageKey: this.getLocalStorageKey,
getIdle: function(){
return options.idle;
},
Expand Down Expand Up @@ -262,7 +273,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
}

var wrap = function(event) {
if (event.key === 'ngIdle.expiry' && event.newValue && event.newValue !== event.oldValue) {
if (event.key === 'ngIdle.' + svc.getLocalStorageKey() && event.newValue && event.newValue !== event.oldValue) {
var val = angular.fromJson(event.newValue);
if (val.id === id) return;
svc.interrupt(true);
Expand Down