From 8966ba59ada3ac2eddb25393a228c0be1012999b Mon Sep 17 00:00:00 2001 From: Matt Banz Date: Thu, 9 Apr 2015 15:36:02 -0600 Subject: [PATCH 1/9] Initializing the idleCountdown directive's value to the timeout --- angular-idle.js | 7 +++++-- angular-idle.map | 2 +- angular-idle.min.js | 2 +- src/countdown/countdown.js | 9 ++++++--- src/countdown/countdown.spec.js | 12 ++++++++++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/angular-idle.js b/angular-idle.js index 33090e1..17bd50d 100644 --- a/angular-idle.js +++ b/angular-idle.js @@ -291,13 +291,16 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) }); angular.module('ngIdle.countdown', []) - .directive('idleCountdown', function() { + .directive('idleCountdown', ['Idle', function(Idle) { return { restrict: 'A', scope: { value: '=idleCountdown' }, link: function($scope) { + // Initialize the scope's value to the configured timeout. + $scope.value = Idle._options().timeout; + $scope.$on('IdleWarn', function(e, countdown) { $scope.$apply(function() { $scope.value = countdown; @@ -311,7 +314,7 @@ angular.module('ngIdle.countdown', []) }); } }; - }); + }]); angular.module('ngIdle.title', []) .factory('Title', ['$document', '$interpolate', function($document, $interpolate) { diff --git a/angular-idle.map b/angular-idle.map index eecf9d3..463f08a 100644 --- a/angular-idle.map +++ b/angular-idle.map @@ -1 +1 @@ -{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAAKH,EACLI,OAAQ,QAIZJ,EAAMK,OAAQ,EAEdT,EAAQC,KAAOG,EAGjB,IAAIM,GAAcP,KAAKD,SAAW,SAASS,GAGzC,GAFAA,EAAUC,SAASD,GAEfE,MAAMF,IAAuB,GAAXA,EAAc,KAAM,IAAIN,OAAM,+DACpDL,GAAQE,SAAWS,EAGrBR,MAAKW,MAAQ,aAAc,OAAQ,YAAa,QAC9C,SAASC,EAAYC,EAAMC,EAAWC,GAOpC,QAASC,GAAeC,EAAMC,GAC5BN,EAAWO,WAAW,oBAAqBF,EAAMC,GAGnD,QAASE,KACPR,EAAWO,WAAW,aAElB1B,EAAQ4B,SAASxB,EAAQC,OAC3BiB,EAAMlB,EAAQC,MACXwB,QAAQN,GACRO,MAAMP,GAfb,GAAIQ,IACFJ,KAAM,KAkBR,QACEK,SAAU,WACR,MAAO5B,IAETU,YAAaA,EACbmB,MAAO,WAIL,MAHAZ,GAAUa,OAAOH,EAAMJ,MAEvBI,EAAMJ,KAAON,EAAUM,EAAyB,IAAnBvB,EAAQE,UAC9ByB,EAAMJ,MAEfQ,KAAM,WACJd,EAAUa,O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AChD,GAAIgF,GAAUhF,EAAQiF,YAEtB,QACE5D,IAAK,SAASa,EAAK3E,GACjByH,EAAQE,QAAQ,UAAUhD,EAAKnF,EAAQoI,OAAO5H,KAEhDyD,IAAK,SAASkB,GACZ,MAAOnF,GAAQuF,SAAS0C,EAAQI,QAAQ,UAAUlD,KAEpDX,OAAQ,SAASW,GACf8C,EAAQK,WAAW,UAAUnD,SAKlCpF,OAAQA,OAAOC"} \ No newline at end of file +{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","Idle","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAA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+G,YAAYzB,GAAavD,EAAM+E,cAE3C/E,EAAM+E,SAAWxB,IAEnB+B,UAAW,SAAS7D,GAClBjD,KAAKyG,OAEL,IAAIM,IAAcC,aAAc/D,EAChC8D,GAAUE,QAAUC,KAAKC,MAAMlE,EAAU,IACzC8D,EAAUvG,QAAUsF,EAAQ7C,EAAgC,GAApB8D,EAAUE,QAAc,GAEhEjH,KAAKC,MAAM4F,EAAa7F,KAAK4G,eAAeG,KAE9CK,cAAe,WACbpH,KAAKyG,QAELzG,KAAKC,MAAMD,KAAK6G,oBAElBQ,QAAS,WACHrH,KAAKsG,YAAYtG,KAAKC,MAAMD,KAAKsG,iBAI1CnB,UAAU,SAAU,QAAS,SAASmC,GACnC,OACEjC,SAAU,IACVE,KAAM,SAASC,EAAQ+B,EAAUC,GAC3BA,EAAMC,eAEVH,EAAMb,OAAM,GAEZjB,EAAOC,IAAI,WAAY,SAASC,EAAGzC,GACjCqE,EAAMR,UAAU7D,KAGlBuC,EAAOC,IAAI,UAAW,WACpB6B,EAAMD,YAGR7B,EAAOC,IAAI,cAAe,WACxB6B,EAAMF,wBAMlB3H,EAAQE,OAAO,0BACZ+H,QAAQ,oBAAqB,UAAW,SAAShF,GAChD,GAAIiF,GAAUjF,EAAQkF,YAEtB,QACE7D,IAAK,SAASa,EAAK3E,GACjB0H,EAAQE,QAAQ,UAAUjD,EAAKnF,EAAQqI,OAAO7H,KAEhDyD,IAAK,SAASkB,GACZ,MAAOnF,GAAQuF,SAAS2C,EAAQI,QAAQ,UAAUnD,KAEpDX,OAAQ,SAASW,GACf+C,EAAQK,WAAW,UAAUpD,SAKlCpF,OAAQA,OAAOC"} \ No newline at end of file diff --git a/angular-idle.min.js b/angular-idle.min.js index bd96bcf..fc39ca6 100644 --- a/angular-idle.min.js +++ b/angular-idle.min.js @@ -5,5 +5,5 @@ * @license MIT */ -!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){a.autoResume=b===!0?"idle":b===!1?"off":b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",[]).directive("idleCountdown",function(){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(a){a.$on("IdleWarn",function(b,c){a.$apply(function(){a.value=c})}),a.$on("IdleTimeout",function(){a.$apply(function(){a.value=0})})}}}),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); +!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){a.autoResume=b===!0?"idle":b===!1?"off":b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",[]).directive("idleCountdown",["Idle",function(a){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(b){b.value=a._options().timeout,b.$on("IdleWarn",function(a,c){b.$apply(function(){b.value=c})}),b.$on("IdleTimeout",function(){b.$apply(function(){b.value=0})})}}}]),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); //# sourceMappingURL=angular-idle.map \ No newline at end of file diff --git a/src/countdown/countdown.js b/src/countdown/countdown.js index dfa9e13..bf116c3 100644 --- a/src/countdown/countdown.js +++ b/src/countdown/countdown.js @@ -1,11 +1,14 @@ -angular.module('ngIdle.countdown', []) - .directive('idleCountdown', function() { +angular.module('ngIdle.countdown', ['ngIdle.idle']) + .directive('idleCountdown', ['Idle', function(Idle) { return { restrict: 'A', scope: { value: '=idleCountdown' }, link: function($scope) { + // Initialize the scope's value to the configured timeout. + $scope.value = Idle._options().timeout; + $scope.$on('IdleWarn', function(e, countdown) { $scope.$apply(function() { $scope.value = countdown; @@ -19,4 +22,4 @@ angular.module('ngIdle.countdown', []) }); } }; - }); + }]); diff --git a/src/countdown/countdown.spec.js b/src/countdown/countdown.spec.js index 36c7526..2475568 100644 --- a/src/countdown/countdown.spec.js +++ b/src/countdown/countdown.spec.js @@ -13,11 +13,12 @@ describe('ngIdle', function() { describe('idle-countdown', function() { beforeEach(module('ngIdle.countdown')); - var $compile, $scope, create; + var $compile, $scope, create, Idle; - beforeEach(inject(function(_$rootScope_, _$compile_) { + beforeEach(inject(function(_$rootScope_, _$compile_, _Idle_) { $scope = _$rootScope_; $compile = _$compile_; + Idle = _Idle_; create = function() { var el = $compile(angular.element('
{{countdown}} seconds remaining.
'))($scope); @@ -26,6 +27,13 @@ describe('ngIdle', function() { }; })); + it('should initialize the countdown scope value to the Idle timeout', function() { + var randomTimeout = Math.floor(Math.random() * 100); + Idle.setTimeout(randomTimeout); + create(); + expect($scope.countdown).toBe(randomTimeout); + }); + it('should update countdown scope value when receiving new IdleWarning event', function() { create(); From 018303877bdd91628a9edba82909c716794c3261 Mon Sep 17 00:00:00 2001 From: Jonathan Cherryhomes Date: Wed, 15 Apr 2015 20:05:12 -0500 Subject: [PATCH 2/9] Added getIdle() and getTimeout() Added convenience methods to the IdleProvider for getting the current Idle and Timeout values. --- angular-idle.js | 7 ++- angular-idle.map | 2 +- angular-idle.min.js | 2 +- src/idle/idle.js | 6 ++ src/idle/idle.spec.js | 22 +++++-- src/keepalive/keepalive.js | 1 - test/index.html | 122 ++++++++++++++++++------------------- 7 files changed, 91 insertions(+), 71 deletions(-) diff --git a/angular-idle.js b/angular-idle.js index 33090e1..dae67e1 100644 --- a/angular-idle.js +++ b/angular-idle.js @@ -42,7 +42,6 @@ angular.module('ngIdle.keepalive', []) ping: null }; - function handleResponse(data, status) { $rootScope.$broadcast('KeepaliveResponse', data, status); } @@ -215,6 +214,12 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) _getNow: function() { return new Date(); }, + getIdle: function(){ + return options.idle; + }, + getTimeout: function(){ + return options.timeout; + }, setIdle: function(seconds) { changeOption(this, setIdle, seconds); }, diff --git a/angular-idle.map b/angular-idle.map index eecf9d3..b922957 100644 --- a/angular-idle.map +++ b/angular-idle.map @@ -1 +1 @@ -{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAAKH,EACLI,OAAQ,QAIZJ,EAAMK,OAAQ,EAEdT,EAAQC,KAAOG,EAGjB,IAAIM,GAAcP,KAAKD,SAAW,SAASS,GAGzC,GAFAA,EAAUC,SAASD,GAEfE,MAAMF,IAAuB,GAAXA,EAAc,KAAM,IAAIN,OAAM,+DACpDL,GAAQE,SAAWS,EAGrBR,MAAKW,MAAQ,aAAc,OAAQ,YAAa,QAC9C,SAASC,EAAYC,EAAMC,EAAWC,GAOpC,QAASC,GAAeC,EAAMC,GAC5BN,EAAWO,WAAW,oBAAqBF,EAAMC,GAGnD,QAASE,KACPR,EAAWO,WAAW,aAElB1B,EAAQ4B,SAASxB,EAAQC,OAC3BiB,EAAMlB,EAAQC,MACXwB,QAAQN,GACRO,MAAMP,GAfb,GAAIQ,IACFJ,KAAM,KAkBR,QACEK,SAAU,WACR,MAAO5B,IAETU,YAAaA,EACbmB,MAAO,WAIL,MAHAZ,GAAUa,OAAOH,EAAMJ,MAEvBI,EAAMJ,KAAON,EAAUM,EAAyB,IAAnBvB,EAAQE,UAC9ByB,EAAMJ,MAEfQ,KAAM,WACJd,EAAUa,OAAOH,EAAMJ,OAEzBA,KAAM,WACJA,UAOZ3B,EAAQE,OAAO,eAAgB,mBAAoB,wBAChD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QAAQ,UAAUhD,EAAKnF,EAAQoI,OAAO5H,KAEhDyD,IAAK,SAASkB,GACZ,MAAOnF,GAAQuF,SAAS0C,EAAQI,QAAQ,UAAUlD,KAEpDX,OAAQ,SAASW,GACf8C,EAAQK,WAAW,UAAUnD,SAKlCpF,OAAQA,OAAOC"} \ No newline at end of file +{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","getIdle","getTimeout","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAAKH,EACLI,OAAQ,QAIZJ,EAAMK,OAAQ,EAEdT,EAAQC,KAAOG,EAGjB,IA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D,EAAMgF,cAE3ChF,EAAMgF,SAAWvB,IAEnB8B,UAAW,SAAS9D,GAClBjD,KAAK0G,OAEL,IAAIM,IAAcC,aAAchE,EAChC+D,GAAUE,QAAUC,KAAKC,MAAMnE,EAAU,IACzC+D,EAAUxG,QAAUuF,EAAQ9C,EAAgC,GAApB+D,EAAUE,QAAc,GAEhElH,KAAKC,MAAM6F,EAAa9F,KAAK6G,eAAeG,KAE9CK,cAAe,WACbrH,KAAK0G,QAEL1G,KAAKC,MAAMD,KAAK8G,oBAElBQ,QAAS,WACHtH,KAAKuG,YAAYvG,KAAKC,MAAMD,KAAKuG,iBAI1ClB,UAAU,SAAU,QAAS,SAASkC,GACnC,OACEjC,SAAU,IACVE,KAAM,SAASC,EAAQ+B,EAAUC,GAC3BA,EAAMC,eAEVH,EAAMb,OAAM,GAEZjB,EAAOC,IAAI,WAAY,SAASC,EAAG1C,GACjCsE,EAAMR,UAAU9D,KAGlBwC,EAAOC,IAAI,UAAW,WACpB6B,EAAMD,YAGR7B,EAAOC,IAAI,cAAe,WACxB6B,EAAMF,wBAMlB5H,EAAQE,OAAO,0BACZgI,QAAQ,oBAAqB,UAAW,SAASjF,GAChD,GAAIkF,GAAUlF,EAAQmF,YAEtB,QACE9D,IAAK,SAASe,EAAK7E,GACjB2H,EAAQE,QAAQ,UAAUhD,EAAKrF,EAAQsI,OAAO9H,KAEhDyD,IAAK,SAASoB,GACZ,MAAOrF,GAAQyF,SAAS0C,EAAQI,QAAQ,UAAUlD,KAEpDb,OAAQ,SAASa,GACf8C,EAAQK,WAAW,UAAUnD,SAKlCtF,OAAQA,OAAOC"} \ No newline at end of file diff --git a/angular-idle.min.js b/angular-idle.min.js index bd96bcf..3aba0da 100644 --- a/angular-idle.min.js +++ b/angular-idle.min.js @@ -5,5 +5,5 @@ * @license MIT */ -!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){a.autoResume=b===!0?"idle":b===!1?"off":b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",[]).directive("idleCountdown",function(){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(a){a.$on("IdleWarn",function(b,c){a.$apply(function(){a.value=c})}),a.$on("IdleTimeout",function(){a.$apply(function(){a.value=0})})}}}),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); +!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){b===!0?a.autoResume="idle":b===!1?a.autoResume="off":a.autoResume=b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},getIdle:function(){return a.idle},getTimeout:function(){return a.timeout},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",[]).directive("idleCountdown",function(){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(a){a.$on("IdleWarn",function(b,c){a.$apply(function(){a.value=c})}),a.$on("IdleTimeout",function(){a.$apply(function(){a.value=0})})}}}),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); //# sourceMappingURL=angular-idle.map \ No newline at end of file diff --git a/src/idle/idle.js b/src/idle/idle.js index 826607b..a1316e7 100644 --- a/src/idle/idle.js +++ b/src/idle/idle.js @@ -134,6 +134,12 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) _getNow: function() { return new Date(); }, + getIdle: function(){ + return options.idle; + }, + getTimeout: function(){ + return options.timeout; + }, setIdle: function(seconds) { changeOption(this, setIdle, seconds); }, diff --git a/src/idle/idle.spec.js b/src/idle/idle.spec.js index b7120cb..7fe0157 100644 --- a/src/idle/idle.spec.js +++ b/src/idle/idle.spec.js @@ -158,6 +158,16 @@ describe('ngIdle', function() { expect(Idle.watch).toHaveBeenCalled(); }); + it ('getIdle() should return the current idle value', function(){ + Idle.setIdle(100); + expect(Idle.getIdle()).toBe(100); + }); + + it ('getTimeout() should return the current timeout value', function(){ + Idle.setTimeout(100); + expect(Idle.getTimeout()).toBe(100); + }); + it ('setTimeout() should update option.timeout and restart', function() { spyOn(Idle, 'watch'); spyOn(Idle, 'unwatch'); @@ -376,15 +386,15 @@ describe('ngIdle', function() { // in practice, the functionality works fine, but here the test always fails. dunno how to fix it right now. // it ('document event should interrupt idle timeout', function() { - // Idle.watch(); - // $timeout.flush(); + // Idle.watch(); + // $timeout.flush(); - // expect(Idle.idling()).toBe(true); + // expect(Idle.idling()).toBe(true); - // var e = $.Event('click'); - // $('body').trigger(e); + // var e = $.Event('click'); + // $('body').trigger(e); - // expect(Idle.idling()).toBe(false); + // expect(Idle.idling()).toBe(false); // }); }); diff --git a/src/keepalive/keepalive.js b/src/keepalive/keepalive.js index 9a4db08..5701c23 100644 --- a/src/keepalive/keepalive.js +++ b/src/keepalive/keepalive.js @@ -33,7 +33,6 @@ angular.module('ngIdle.keepalive', []) ping: null }; - function handleResponse(data, status) { $rootScope.$broadcast('KeepaliveResponse', data, status); } diff --git a/test/index.html b/test/index.html index 42412c4..7c621f7 100644 --- a/test/index.html +++ b/test/index.html @@ -1,74 +1,74 @@ - - NgIdle Sample - - - + + - - -
-

Idle and Keepalive events

- -
    -
  • {{event}}
  • -
+ $log.debug('app started.'); + }); + + + +
+

Idle and Keepalive events

+ +
    +
  • {{event}}
  • +
- Timeout in {{countdown}} seconds. + Timeout in {{countdown}} seconds. -
- Change idle value -
-
- Change timeout value -
-
- +
+ Change idle value +
+
+ Change timeout value +
+
+ From 39952236920c1d0e0f71ee487021cfc567c5bae4 Mon Sep 17 00:00:00 2001 From: philmerrell Date: Fri, 17 Apr 2015 14:34:07 -0600 Subject: [PATCH 3/9] Set original title on IdleStart event to accommodate dynamic page titles --- angular-idle.js | 4 ++++ angular-idle.map | 2 +- angular-idle.min.js | 2 +- src/title/title.js | 4 ++++ src/title/title.spec.js | 9 +++++++++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/angular-idle.js b/angular-idle.js index dae67e1..3f99afe 100644 --- a/angular-idle.js +++ b/angular-idle.js @@ -382,6 +382,10 @@ angular.module('ngIdle.title', []) Title.store(true); + $scope.$on('IdleStart', function(e) { + Title.original($element[0].innerText); + }); + $scope.$on('IdleWarn', function(e, countdown) { Title.setAsIdle(countdown); }); diff --git a/angular-idle.map b/angular-idle.map index b922957..b4f5838 100644 --- a/angular-idle.map +++ b/angular-idle.map @@ -1 +1 @@ -{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","getIdle","getTimeout","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAAKH,EACLI,OAAQ,QAIZJ,EAAMK,OAAQ,EAEdT,EAAQC,KAAOG,EAGjB,IAAIM,GAAcP,KAAKD,SAAW,SAASS,GAGzC,GAFAA,EAAUC,SAASD,GAEfE,MAAMF,IAAuB,GAAXA,EAAc,KAAM,IAAIN,OAAM,+DACpDL,GAAQE,SAAWS,EAGrBR,MAAKW,MAAQ,aAAc,OAAQ,YAAa,QAC9C,SAASC,EAAYC,EAAMC,EAAWC,GAMpC,QAASC,GAAeC,EAAMC,GAC5BN,EAAWO,WAAW,oBAAqBF,EAAMC,GAGnD,QAASE,KACPR,EAAWO,WAAW,aAElB1B,EAAQ4B,SAASxB,EAAQC,OAC3BiB,EAAMlB,EAAQC,MACXwB,QAAQN,GACRO,MAAMP,GAdb,GAAIQ,IACFJ,KAAM,KAi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OACEjC,SAAU,IACVE,KAAM,SAASC,EAAQ+B,EAAUC,GAC3BA,EAAMC,eAEVH,EAAMb,OAAM,GAEZjB,EAAOC,IAAI,WAAY,SAASC,EAAG1C,GACjCsE,EAAMR,UAAU9D,KAGlBwC,EAAOC,IAAI,UAAW,WACpB6B,EAAMD,YAGR7B,EAAOC,IAAI,cAAe,WACxB6B,EAAMF,wBAMlB5H,EAAQE,OAAO,0BACZgI,QAAQ,oBAAqB,UAAW,SAASjF,GAChD,GAAIkF,GAAUlF,EAAQmF,YAEtB,QACE9D,IAAK,SAASe,EAAK7E,GACjB2H,EAAQE,QAAQ,UAAUhD,EAAKrF,EAAQsI,OAAO9H,KAEhDyD,IAAK,SAASoB,GACZ,MAAOrF,GAAQyF,SAAS0C,EAAQI,QAAQ,UAAUlD,KAEpDb,OAAQ,SAASa,GACf8C,EAAQK,WAAW,UAAUnD,SAKlCtF,OAAQA,OAAOC"} \ No newline at end of file +{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","getIdle","getTimeout","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","innerText","service","stor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IAAK,SAASe,EAAK7E,GACjB4H,EAAQE,QAAQ,UAAUjD,EAAKrF,EAAQuI,OAAO/H,KAEhDyD,IAAK,SAASoB,GACZ,MAAOrF,GAAQyF,SAAS2C,EAAQI,QAAQ,UAAUnD,KAEpDb,OAAQ,SAASa,GACf+C,EAAQK,WAAW,UAAUpD,SAKlCtF,OAAQA,OAAOC"} \ No newline at end of file diff --git a/angular-idle.min.js b/angular-idle.min.js index 3aba0da..f85b177 100644 --- a/angular-idle.min.js +++ b/angular-idle.min.js @@ -5,5 +5,5 @@ * @license MIT */ -!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){b===!0?a.autoResume="idle":b===!1?a.autoResume="off":a.autoResume=b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},getIdle:function(){return a.idle},getTimeout:function(){return a.timeout},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",[]).directive("idleCountdown",function(){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(a){a.$on("IdleWarn",function(b,c){a.$apply(function(){a.value=c})}),a.$on("IdleTimeout",function(){a.$apply(function(){a.value=0})})}}}),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); +!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){b===!0?a.autoResume="idle":b===!1?a.autoResume="off":a.autoResume=b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},getIdle:function(){return a.idle},getTimeout:function(){return a.timeout},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",[]).directive("idleCountdown",function(){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(a){a.$on("IdleWarn",function(b,c){a.$apply(function(){a.value=c})}),a.$on("IdleTimeout",function(){a.$apply(function(){a.value=0})})}}}),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleStart",function(b){a.original(c[0].innerText)}),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); //# sourceMappingURL=angular-idle.map \ No newline at end of file diff --git a/src/title/title.js b/src/title/title.js index 70cde2b..8ff3e21 100644 --- a/src/title/title.js +++ b/src/title/title.js @@ -62,6 +62,10 @@ angular.module('ngIdle.title', []) Title.store(true); + $scope.$on('IdleStart', function(e) { + Title.original($element[0].innerText); + }); + $scope.$on('IdleWarn', function(e, countdown) { Title.setAsIdle(countdown); }); diff --git a/src/title/title.spec.js b/src/title/title.spec.js index b3b887d..f61a298 100644 --- a/src/title/title.spec.js +++ b/src/title/title.spec.js @@ -115,6 +115,7 @@ describe('ngIdle', function() { spyOn(Title, 'setAsTimedOut'); spyOn(Title, 'restore'); spyOn(Title, 'store'); + spyOn(Title, 'original'); create = function(template) { var el = $compile(angular.element(template||'Hello World'))($scope); @@ -133,6 +134,14 @@ describe('ngIdle', function() { expect(Title.store).toHaveBeenCalledWith(true); }); + it('should set original title on IdleStart event', function() { + create('Dynamic Title'); + $scope.$broadcast('IdleStart'); + $scope.$apply(); + + expect(Title.original).toHaveBeenCalledWith('Dynamic Title'); + }); + it('should set title to idle message on IdleWarn event', function() { $scope.$broadcast('IdleWarn', 5); $scope.$apply(); From 86b19d7030564176a56d2c1ab20ebe16df33066f Mon Sep 17 00:00:00 2001 From: Mike Grabski Date: Mon, 20 Apr 2015 12:21:19 -0400 Subject: [PATCH 4/9] Use Idle.getTimeout() instead of internal _options() --- src/countdown/countdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/countdown/countdown.js b/src/countdown/countdown.js index bf116c3..29e8c70 100644 --- a/src/countdown/countdown.js +++ b/src/countdown/countdown.js @@ -7,7 +7,7 @@ angular.module('ngIdle.countdown', ['ngIdle.idle']) }, link: function($scope) { // Initialize the scope's value to the configured timeout. - $scope.value = Idle._options().timeout; + $scope.value = Idle.getTimeout(); $scope.$on('IdleWarn', function(e, countdown) { $scope.$apply(function() { From b0a5f66d4d86a5e6c9c7eae873cf4fa06a478753 Mon Sep 17 00:00:00 2001 From: Mike Grabski Date: Wed, 29 Apr 2015 15:02:55 -0400 Subject: [PATCH 5/9] Fix jshint errors --- angular-idle.js | 10 +++++----- angular-idle.map | 2 +- angular-idle.min.js | 2 +- src/title/title.js | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/angular-idle.js b/angular-idle.js index 4983533..54ad72f 100644 --- a/angular-idle.js +++ b/angular-idle.js @@ -304,7 +304,7 @@ angular.module('ngIdle.countdown', ['ngIdle.idle']) }, link: function($scope) { // Initialize the scope's value to the configured timeout. - $scope.value = Idle._options().timeout; + $scope.value = Idle.getTimeout(); $scope.$on('IdleWarn', function(e, countdown) { $scope.$apply(function() { @@ -325,7 +325,7 @@ angular.module('ngIdle.title', []) .factory('Title', ['$document', '$interpolate', function($document, $interpolate) { function padLeft(nr, n, str){ - return Array(n-String(nr).length+1).join(str||'0')+nr; + return new Array(n-String(nr).length+1).join(str||'0')+nr; } var state = { @@ -385,7 +385,7 @@ angular.module('ngIdle.title', []) Title.store(true); - $scope.$on('IdleStart', function(e) { + $scope.$on('IdleStart', function() { Title.original($element[0].innerText); }); @@ -407,7 +407,7 @@ angular.module('ngIdle.title', []) angular.module('ngIdle.localStorage', []) .service('IdleLocalStorage', ['$window', function($window) { var storage = $window.localStorage; - + return { set: function(key, value) { storage.setItem('ngIdle.'+key, angular.toJson(value)); @@ -421,4 +421,4 @@ angular.module('ngIdle.localStorage', []) }; }]); -})(window, window.angular); \ No newline at end of file +})(window, window.angular); diff --git a/angular-idle.map b/angular-idle.map index a902310..5e9ba23 100644 --- a/angular-idle.map +++ b/angular-idle.map @@ -1 +1 @@ -{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","getIdle","getTimeout","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","Idle","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","innerText","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,E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QE,QAAQ,UAAUlD,EAAKrF,EAAQwI,OAAOhI,KAEhDyD,IAAK,SAASoB,GACZ,MAAOrF,GAAQyF,SAAS4C,EAAQI,QAAQ,UAAUpD,KAEpDb,OAAQ,SAASa,GACfgD,EAAQK,WAAW,UAAUrD,SAKlCtF,OAAQA,OAAOC"} \ No newline at end of file +{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","getIdle","getTimeout","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","Idle","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","innerText","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAAKH,EACLI,OAAQ,QAIZJ,EAAMK,OAAQ,EAEdT,EAAQC,KAA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AAS9B,GACxB,MAAIxF,GAAQiH,YAAYzB,GAAazD,EAAMiF,cAE3CjF,EAAMiF,SAAWxB,IAEnB+B,UAAW,SAAS/D,GAClBjD,KAAK2G,OAEL,IAAIM,IAAcC,aAAcjE,EAChCgE,GAAUE,QAAUC,KAAKC,MAAMpE,EAAU,IACzCgE,EAAUzG,QAAUwF,EAAQ/C,EAAgC,GAApBgE,EAAUE,QAAc,GAEhEnH,KAAKC,MAAM8F,EAAa/F,KAAK8G,eAAeG,KAE9CK,cAAe,WACbtH,KAAK2G,QAEL3G,KAAKC,MAAMD,KAAK+G,oBAElBQ,QAAS,WACHvH,KAAKwG,YAAYxG,KAAKC,MAAMD,KAAKwG,iBAI1CnB,UAAU,SAAU,QAAS,SAASmC,GACnC,OACEjC,SAAU,IACVE,KAAM,SAASC,EAAQ+B,EAAUC,GAC3BA,EAAMC,eAEVH,EAAMb,OAAM,GAEZjB,EAAOC,IAAI,YAAa,WACtB6B,EAAMhB,SAASiB,EAAS,GAAGG,aAG7BlC,EAAOC,IAAI,WAAY,SAASC,EAAG3C,GACjCuE,EAAMR,UAAU/D,KAGlByC,EAAOC,IAAI,UAAW,WACpB6B,EAAMD,YAGR7B,EAAOC,IAAI,cAAe,WACxB6B,EAAMF,wBAMlB7H,EAAQE,OAAO,0BACZkI,QAAQ,oBAAqB,UAAW,SAASnF,GAChD,GAAIoF,GAAUpF,EAAQqF,YAEtB,QACEhE,IAAK,SAASe,EAAK7E,GACjB6H,EAAQE,QAAQ,UAAUlD,EAAKrF,EAAQwI,OAAOhI,KAEhDyD,IAAK,SAASoB,GACZ,MAAOrF,GAAQyF,SAAS4C,EAAQI,QAAQ,UAAUpD,KAEpDb,OAAQ,SAASa,GACfgD,EAAQK,WAAW,UAAUrD,SAKlCtF,OAAQA,OAAOC"} \ No newline at end of file diff --git a/angular-idle.min.js b/angular-idle.min.js index 4739e7f..bf0b2c9 100644 --- a/angular-idle.min.js +++ b/angular-idle.min.js @@ -5,5 +5,5 @@ * @license MIT */ -!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){a.autoResume=b===!0?"idle":b===!1?"off":b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},getIdle:function(){return a.idle},getTimeout:function(){return a.timeout},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",["ngIdle.idle"]).directive("idleCountdown",["Idle",function(a){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(b){b.value=a._options().timeout,b.$on("IdleWarn",function(a,c){b.$apply(function(){b.value=c})}),b.$on("IdleTimeout",function(){b.$apply(function(){b.value=0})})}}}]),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleStart",function(b){a.original(c[0].innerText)}),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); +!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){a.autoResume=b===!0?"idle":b===!1?"off":b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},getIdle:function(){return a.idle},getTimeout:function(){return a.timeout},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",["ngIdle.idle"]).directive("idleCountdown",["Idle",function(a){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(b){b.value=a.getTimeout(),b.$on("IdleWarn",function(a,c){b.$apply(function(){b.value=c})}),b.$on("IdleTimeout",function(){b.$apply(function(){b.value=0})})}}}]),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return new Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleStart",function(){a.original(c[0].innerText)}),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); //# sourceMappingURL=angular-idle.map \ No newline at end of file diff --git a/src/title/title.js b/src/title/title.js index 8ff3e21..b624258 100644 --- a/src/title/title.js +++ b/src/title/title.js @@ -2,7 +2,7 @@ angular.module('ngIdle.title', []) .factory('Title', ['$document', '$interpolate', function($document, $interpolate) { function padLeft(nr, n, str){ - return Array(n-String(nr).length+1).join(str||'0')+nr; + return new Array(n-String(nr).length+1).join(str||'0')+nr; } var state = { @@ -62,7 +62,7 @@ angular.module('ngIdle.title', []) Title.store(true); - $scope.$on('IdleStart', function(e) { + $scope.$on('IdleStart', function() { Title.original($element[0].innerText); }); From e7272c091e9da5349d2301d1517cb24f888969eb Mon Sep 17 00:00:00 2001 From: Mike Grabski Date: Wed, 29 Apr 2015 15:36:56 -0400 Subject: [PATCH 6/9] Fixes #76 by safely handing missing expiries in localstorage --- src/idle/idle.js | 4 ++-- src/idle/idle.spec.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/idle/idle.js b/src/idle/idle.js index a1316e7..79b5ebd 100644 --- a/src/idle/idle.js +++ b/src/idle/idle.js @@ -119,7 +119,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) function getExpiry() { var obj = LocalStorage.get('expiry'); - return new Date(obj.time); + return obj && obj.time ? new Date(obj.time) : null; } function setExpiry(date) { @@ -148,7 +148,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) }, isExpired: function() { var expiry = getExpiry(); - return expiry && expiry <= this._getNow(); + return expiry !== null && expiry <= this._getNow(); }, running: function() { return state.running; diff --git a/src/idle/idle.spec.js b/src/idle/idle.spec.js index 7fe0157..4790456 100644 --- a/src/idle/idle.spec.js +++ b/src/idle/idle.spec.js @@ -342,6 +342,10 @@ describe('ngIdle', function() { expect(Idle.isExpired()).toBe(true); }); + it ('isExpired() should return false if there is no expiry yet', function() { + expect(Idle.isExpired()).toBe(false); + }); + it ('interrupt() should broadcast $timeout if running and past expiry', function() { spyOn($rootScope, '$broadcast'); From 899e89bd2b1352a01f0c96ca9014dd8893e08530 Mon Sep 17 00:00:00 2001 From: Mike Grabski Date: Wed, 29 Apr 2015 15:58:49 -0400 Subject: [PATCH 7/9] Fixes #77 by adding dependencies node --- package.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b2ef84..5c624ec 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,16 @@ "name": "ng-idle", "version": "1.0.4", "description": "Directives and services for responding to idle users in AngularJS", + "keywords": [ + "angularjs", + "idle", + "ng-idle", + "keepalive", + "ping", + "angular", + "user", + "session" + ], "main": [ "angular-idle.js", "angular-idle.min.js", @@ -19,6 +29,9 @@ "bugs": { "url": "https://github.com/HackedByChinese/ng-idle/issues" }, + "dependencies": { + "angular": "^1.2.0" + }, "devDependencies": { "grunt": "~0.4.2", "grunt-bump": "0.0.13", @@ -39,7 +52,6 @@ "karma-script-launcher": "~0.1.0", "matchdep": "~0.3.0", "requirejs": "~2.1.10", - "angular": "^1.2.0", "angular-mocks": "^1.2.0", "jquery": "^2.0.3" } From afc379d6bc1cd54e7b10c42b57f1ac88167d1dd3 Mon Sep 17 00:00:00 2001 From: Mike Grabski Date: Wed, 29 Apr 2015 16:26:22 -0400 Subject: [PATCH 8/9] Fixes #75 by updating countdown within evalAsync --- angular-idle.js | 12 ++++++------ angular-idle.map | 2 +- angular-idle.min.js | 2 +- {test => sample}/index.html | 22 +++++++++++++++------- src/countdown/countdown.js | 4 ++-- 5 files changed, 25 insertions(+), 17 deletions(-) rename {test => sample}/index.html (73%) diff --git a/angular-idle.js b/angular-idle.js index 54ad72f..b40a1d4 100644 --- a/angular-idle.js +++ b/angular-idle.js @@ -199,7 +199,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) function getExpiry() { var obj = LocalStorage.get('expiry'); - return new Date(obj.time); + return obj && obj.time ? new Date(obj.time) : null; } function setExpiry(date) { @@ -228,7 +228,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) }, isExpired: function() { var expiry = getExpiry(); - return expiry && expiry <= this._getNow(); + return expiry !== null && expiry <= this._getNow(); }, running: function() { return state.running; @@ -307,13 +307,13 @@ angular.module('ngIdle.countdown', ['ngIdle.idle']) $scope.value = Idle.getTimeout(); $scope.$on('IdleWarn', function(e, countdown) { - $scope.$apply(function() { + $scope.$evalAsync(function() { $scope.value = countdown; }); }); $scope.$on('IdleTimeout', function() { - $scope.$apply(function() { + $scope.$evalAsync(function() { $scope.value = 0; }); }); @@ -407,7 +407,7 @@ angular.module('ngIdle.title', []) angular.module('ngIdle.localStorage', []) .service('IdleLocalStorage', ['$window', function($window) { var storage = $window.localStorage; - + return { set: function(key, value) { storage.setItem('ngIdle.'+key, angular.toJson(value)); @@ -421,4 +421,4 @@ angular.module('ngIdle.localStorage', []) }; }]); -})(window, window.angular); +})(window, window.angular); \ No newline at end of file diff --git a/angular-idle.map b/angular-idle.map index 5e9ba23..43d962d 100644 --- a/angular-idle.map +++ b/angular-idle.map @@ -1 +1 @@ -{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","Date","time","setExpiry","date","set","id","remove","getTime","svc","_getNow","getIdle","getTimeout","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","Idle","restrict","scope","link","$scope","$on","e","$apply","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","innerText","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAAKH,EACLI,OAAQ,QAIZJ,EAAMK,OAAQ,EAEdT,EAAQC,KAAOG,EAGjB,IAAIM,GAAcP,KAAKD,SAAW,SAASS,GAGzC,GAFAA,EAAUC,SAASD,GAEfE,MAAMF,IAAuB,GAAXA,EAAc,KAAM,IAAIN,OAAM,+DACpDL,GAAQE,SAAWS,EAGrBR,MAAKW,MAAQ,aAAc,OAAQ,YAAa,QAC9C,SAASC,EAAYC,EAAMC,EAAWC,GAMpC,QAASC,GAAeC,EAAMC,GAC5BN,EAAWO,WA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KC,MAAM8F,EAAa/F,KAAK8G,eAAeG,KAE9CK,cAAe,WACbtH,KAAK2G,QAEL3G,KAAKC,MAAMD,KAAK+G,oBAElBQ,QAAS,WACHvH,KAAKwG,YAAYxG,KAAKC,MAAMD,KAAKwG,iBAI1CnB,UAAU,SAAU,QAAS,SAASmC,GACnC,OACEjC,SAAU,IACVE,KAAM,SAASC,EAAQ+B,EAAUC,GAC3BA,EAAMC,eAEVH,EAAMb,OAAM,GAEZjB,EAAOC,IAAI,YAAa,WACtB6B,EAAMhB,SAASiB,EAAS,GAAGG,aAG7BlC,EAAOC,IAAI,WAAY,SAASC,EAAG3C,GACjCuE,EAAMR,UAAU/D,KAGlByC,EAAOC,IAAI,UAAW,WACpB6B,EAAMD,YAGR7B,EAAOC,IAAI,cAAe,WACxB6B,EAAMF,wBAMlB7H,EAAQE,OAAO,0BACZkI,QAAQ,oBAAqB,UAAW,SAASnF,GAChD,GAAIoF,GAAUpF,EAAQqF,YAEtB,QACEhE,IAAK,SAASe,EAAK7E,GACjB6H,EAAQE,QAAQ,UAAUlD,EAAKrF,EAAQwI,OAAOhI,KAEhDyD,IAAK,SAASoB,GACZ,MAAOrF,GAAQyF,SAAS4C,EAAQI,QAAQ,UAAUpD,KAEpDb,OAAQ,SAASa,GACfgD,EAAQK,WAAW,UAAUrD,SAKlCtF,OAAQA,OAAOC"} \ No newline at end of file +{"version":3,"file":"angular-idle.min.js","sources":["angular-idle.js"],"names":["window","angular","undefined","module","provider","options","http","interval","this","value","Error","isString","url","method","cache","setInterval","seconds","parseInt","isNaN","$get","$rootScope","$log","$interval","$http","handleResponse","data","status","$broadcast","ping","isObject","success","error","state","_options","start","cancel","stop","idle","timeout","autoResume","interrupt","keepalive","setTimeout","isNumber","events","setIdle","enabled","$document","Keepalive","LocalStorage","$window","startKeepalive","running","stopKeepalive","toggleState","idling","name","countdown","changeOption","self","fn","reset","unwatch","watch","getExpiry","obj","get","time","Date","setExpiry","date","set","id","remove","getTime","svc","_getNow","getIdle","getTimeout","isExpired","expiry","noExpiryUpdate","find","on","wrap","event","key","newValue","oldValue","val","fromJson","addEventListener","attachEvent","directive","Idle","restrict","scope","link","$scope","$on","e","$evalAsync","factory","$interpolate","padLeft","nr","n","str","Array","String","length","join","original","timedout","isUndefined","store","overwrite","title","idleMessage","timedOutMessage","setAsIdle","remaining","totalSeconds","minutes","Math","floor","setAsTimedOut","restore","Title","$element","$attr","idleDisabled","innerText","service","storage","localStorage","setItem","toJson","getItem","removeItem"],"mappings":";;;;;;;CAMA,SAAUA,EAAQC,EAASC,GAC3B,YACAD,GAAQE,OAAO,UAAW,mBAAoB,cAAe,mBAAoB,eAAgB,wBACjGF,EAAQE,OAAO,uBACZC,SAAS,YAAa,WACrB,GAAIC,IACFC,KAAM,KACNC,SAAU,IAGZC,MAAKF,KAAO,SAASG,GACnB,IAAKA,EAAO,KAAM,IAAIC,OAAM,sGACxBT,GAAQU,SAASF,KACnBA,GACEG,IAAKH,EACLI,OAAQ,QAIZJ,EAAMK,OAAQ,EAEdT,EAAQC,KAAOG,EAGjB,IAAIM,GAAcP,KAAKD,SAAW,SAASS,GAGzC,GAFAA,EAAUC,SAASD,GAEfE,MAAMF,IAAuB,GAAXA,EAAc,KAAM,IAAIN,OAAM,+DACpDL,GAAQE,SAAWS,EAGrBR,MAAKW,MAAQ,aAAc,OAAQ,YAAa,QAC9C,SAASC,EAAYC,EAAMC,EAAWC,GAMpC,QAASC,GAAeC,EAAMC,GAC5BN,EAAWO,WAAW,oBAAqBF,EAAMC,GAGnD,QAASE,KACPR,EAAWO,WAAW,aAElB1B,EAAQ4B,SAASxB,EAAQC,OAC3BiB,EAAMlB,EAAQC,MACXwB,QAAQN,GACRO,MAAMP,GAdb,GAAIQ,IACFJ,KAAM,KAiBR,QACEK,SAAU,WACR,MAAO5B,IAETU,YAAaA,EACbmB,MAAO,WAIL,MAHAZ,GAAUa,OAAOH,EAAMJ,MAEvBI,EAAMJ,KAAON,EAAUM,EAAyB,IAAnBvB,EA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Q+B,EAAUC,GAC3BA,EAAMC,eAEVH,EAAMb,OAAM,GAEZjB,EAAOC,IAAI,YAAa,WACtB6B,EAAMhB,SAASiB,EAAS,GAAGG,aAG7BlC,EAAOC,IAAI,WAAY,SAASC,EAAG3C,GACjCuE,EAAMR,UAAU/D,KAGlByC,EAAOC,IAAI,UAAW,WACpB6B,EAAMD,YAGR7B,EAAOC,IAAI,cAAe,WACxB6B,EAAMF,wBAMlB7H,EAAQE,OAAO,0BACZkI,QAAQ,oBAAqB,UAAW,SAASnF,GAChD,GAAIoF,GAAUpF,EAAQqF,YAEtB,QACEhE,IAAK,SAASe,EAAK7E,GACjB6H,EAAQE,QAAQ,UAAUlD,EAAKrF,EAAQwI,OAAOhI,KAEhDyD,IAAK,SAASoB,GACZ,MAAOrF,GAAQyF,SAAS4C,EAAQI,QAAQ,UAAUpD,KAEpDb,OAAQ,SAASa,GACfgD,EAAQK,WAAW,UAAUrD,SAKlCtF,OAAQA,OAAOC"} \ No newline at end of file diff --git a/angular-idle.min.js b/angular-idle.min.js index bf0b2c9..8feb108 100644 --- a/angular-idle.min.js +++ b/angular-idle.min.js @@ -5,5 +5,5 @@ * @license MIT */ -!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){a.autoResume=b===!0?"idle":b===!1?"off":b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return new Date(a.time)}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},getIdle:function(){return a.idle},getTimeout:function(){return a.timeout},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",["ngIdle.idle"]).directive("idleCountdown",["Idle",function(a){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(b){b.value=a.getTimeout(),b.$on("IdleWarn",function(a,c){b.$apply(function(){b.value=c})}),b.$on("IdleTimeout",function(){b.$apply(function(){b.value=0})})}}}]),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return new Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleStart",function(){a.original(c[0].innerText)}),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); +!function(a,b,c){"use strict";b.module("ngIdle",["ngIdle.keepalive","ngIdle.idle","ngIdle.countdown","ngIdle.title","ngIdle.localStorage"]),b.module("ngIdle.keepalive",[]).provider("Keepalive",function(){var a={http:null,interval:600};this.http=function(c){if(!c)throw new Error("Argument must be a string containing a URL, or an object containing the HTTP request configuration.");b.isString(c)&&(c={url:c,method:"GET"}),c.cache=!1,a.http=c};var c=this.interval=function(b){if(b=parseInt(b),isNaN(b)||0>=b)throw new Error("Interval must be expressed in seconds and be greater than 0.");a.interval=b};this.$get=["$rootScope","$log","$interval","$http",function(d,e,f,g){function h(a,b){d.$broadcast("KeepaliveResponse",a,b)}function i(){d.$broadcast("Keepalive"),b.isObject(a.http)&&g(a.http).success(h).error(h)}var j={ping:null};return{_options:function(){return a},setInterval:c,start:function(){return f.cancel(j.ping),j.ping=f(i,1e3*a.interval),j.ping},stop:function(){f.cancel(j.ping)},ping:function(){i()}}}]}),b.module("ngIdle.idle",["ngIdle.keepalive","ngIdle.localStorage"]).provider("Idle",function(){var a={idle:1200,timeout:30,autoResume:"idle",interrupt:"mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll",keepalive:!0},c=this.timeout=function(c){if(c===!1)a.timeout=0;else{if(!(b.isNumber(c)&&c>=0))throw new Error("Timeout must be zero or false to disable the feature, or a positive integer (in seconds) to enable it.");a.timeout=c}};this.interrupt=function(b){a.interrupt=b};var d=this.idle=function(b){if(0>=b)throw new Error("Idle must be a value in seconds, greater than 0.");a.idle=b};this.autoResume=function(b){b===!0?a.autoResume="idle":b===!1?a.autoResume="off":a.autoResume=b},this.keepalive=function(b){a.keepalive=b===!0},this.$get=["$interval","$log","$rootScope","$document","Keepalive","IdleLocalStorage","$window",function(e,f,g,h,i,j,k){function l(){a.keepalive&&(t.running&&i.ping(),i.start())}function m(){a.keepalive&&i.stop()}function n(){t.idling=!t.idling;var b=t.idling?"Start":"End";g.$broadcast("Idle"+b),t.idling?(m(),a.timeout&&(t.countdown=a.timeout,o(),t.timeout=e(o,1e3,a.timeout,!1))):l(),e.cancel(t.idle)}function o(){return t.countdown<=0?void p():(g.$broadcast("IdleWarn",t.countdown),void t.countdown--)}function p(){m(),e.cancel(t.idle),e.cancel(t.timeout),t.idling=!0,t.running=!1,t.countdown=0,g.$broadcast("IdleTimeout")}function q(a,b,c){var d=a.running();a.unwatch(),b(c),d&&a.watch()}function r(){var a=j.get("expiry");return a&&a.time?new Date(a.time):null}function s(a){a?j.set("expiry",{id:u,time:a}):j.remove("expiry")}var t={idle:null,timeout:null,idling:!1,running:!1,countdown:null},u=(new Date).getTime(),v={_options:function(){return a},_getNow:function(){return new Date},getIdle:function(){return a.idle},getTimeout:function(){return a.timeout},setIdle:function(a){q(this,d,a)},setTimeout:function(a){q(this,c,a)},isExpired:function(){var a=r();return null!==a&&a<=this._getNow()},running:function(){return t.running},idling:function(){return t.idling},watch:function(b){e.cancel(t.idle),e.cancel(t.timeout);var c=a.timeout?a.timeout:0;b||s(new Date((new Date).getTime()+1e3*(a.idle+c))),t.idling?n():t.running||l(),t.running=!0,t.idle=e(n,1e3*a.idle,0,!1)},unwatch:function(){e.cancel(t.idle),e.cancel(t.timeout),t.idling=!1,t.running=!1,s(null),m()},interrupt:function(b){return t.running?a.timeout&&this.isExpired()?void p():void(("idle"===a.autoResume||"notIdle"===a.autoResume&&!t.idling)&&this.watch(b)):void 0}};h.find("body").on(a.interrupt,function(){v.interrupt()});var w=function(a){if("ngIdle.expiry"===a.key&&a.newValue!==a.oldValue){var c=b.fromJson(a.newValue);if(c.id===u)return;v.interrupt(!0)}};return k.addEventListener?k.addEventListener("storage",w,!1):k.attachEvent("onstorage",w),v}]}),b.module("ngIdle.countdown",["ngIdle.idle"]).directive("idleCountdown",["Idle",function(a){return{restrict:"A",scope:{value:"=idleCountdown"},link:function(b){b.value=a.getTimeout(),b.$on("IdleWarn",function(a,c){b.$evalAsync(function(){b.value=c})}),b.$on("IdleTimeout",function(){b.$evalAsync(function(){b.value=0})})}}}]),b.module("ngIdle.title",[]).factory("Title",["$document","$interpolate",function(a,c){function d(a,b,c){return new Array(b-String(a).length+1).join(c||"0")+a}var e={original:null,idle:"{{minutes}}:{{seconds}} until your session times out!",timedout:"Your session has expired."};return{original:function(a){return b.isUndefined(a)?e.original:void(e.original=a)},store:function(a){(a||!e.original)&&(e.original=this.value())},value:function(c){return b.isUndefined(c)?a[0].title:void(a[0].title=c)},idleMessage:function(a){return b.isUndefined(a)?e.idle:void(e.idle=a)},timedOutMessage:function(a){return b.isUndefined(a)?e.timedout:void(e.timedout=a)},setAsIdle:function(a){this.store();var b={totalSeconds:a};b.minutes=Math.floor(a/60),b.seconds=d(a-60*b.minutes,2),this.value(c(this.idleMessage())(b))},setAsTimedOut:function(){this.store(),this.value(this.timedOutMessage())},restore:function(){this.original()&&this.value(this.original())}}}]).directive("title",["Title",function(a){return{restrict:"E",link:function(b,c,d){d.idleDisabled||(a.store(!0),b.$on("IdleStart",function(){a.original(c[0].innerText)}),b.$on("IdleWarn",function(b,c){a.setAsIdle(c)}),b.$on("IdleEnd",function(){a.restore()}),b.$on("IdleTimeout",function(){a.setAsTimedOut()}))}}}]),b.module("ngIdle.localStorage",[]).service("IdleLocalStorage",["$window",function(a){var c=a.localStorage;return{set:function(a,d){c.setItem("ngIdle."+a,b.toJson(d))},get:function(a){return b.fromJson(c.getItem("ngIdle."+a))},remove:function(a){c.removeItem("ngIdle."+a)}}}])}(window,window.angular); //# sourceMappingURL=angular-idle.map \ No newline at end of file diff --git a/test/index.html b/sample/index.html similarity index 73% rename from test/index.html rename to sample/index.html index 7c621f7..670c299 100644 --- a/test/index.html +++ b/sample/index.html @@ -1,7 +1,7 @@ NgIdle Sample - +