From 0db7603a0cc827468288005937bc8838889149c8 Mon Sep 17 00:00:00 2001 From: Bart van Gennep Date: Sun, 23 Jul 2017 09:05:17 +0200 Subject: [PATCH] Replace $timeout with $interval (#47) --- demo/javascripts/main.js | 6 +++--- dist/angular-flash.js | 10 +++++----- dist/angular-flash.js.map | 2 +- dist/angular-flash.min.js | 4 ++-- dist/angular-flash.min.js.map | 2 +- src/angular-flash.js | 8 ++++---- test/angular-flash_test.js | 8 ++++---- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/demo/javascripts/main.js b/demo/javascripts/main.js index 0205a40..8525553 100644 --- a/demo/javascripts/main.js +++ b/demo/javascripts/main.js @@ -32,7 +32,7 @@ $.fn.putCursorAtEnd = function () { // Demo controller var app = angular.module('demoApp', ['ngFlash', 'ngAnimate']); -app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$timeout', function ($rootScope, $scope, Flash, $timeout) { +app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$interval', function ($rootScope, $scope, Flash, $interval) { $scope.success = function () { var message = 'Well done! You successfully read this important alert message.'; Flash.create('success', message); @@ -138,10 +138,10 @@ app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$timeout', fu $('#newList').on('keypress', function (e) { if ($(this).val() !== '') { if (e.which == 13) { - $timeout(function () { + $interval(function () { $scope.add(); return false; - }, 100); + }, 100, 1); } } }); diff --git a/dist/angular-flash.js b/dist/angular-flash.js index e1d1b90..159b20f 100644 --- a/dist/angular-flash.js +++ b/dist/angular-flash.js @@ -1,4 +1,4 @@ -/*! angular-flash - v2.4.0 - 2016-10-25 +/*! angular-flash - v2.4.0 - 2016-11-07 * https://github.com/sachinchoolur/angular-flash * Copyright (c) 2016 Sachin; Licensed MIT */ @@ -115,7 +115,7 @@ app.provider('Flash', function () { this.setShowClose(true); this.setTemplatePreset('bootstrap'); - this.$get = ['$rootScope', '$timeout', function ($rootScope, $timeout) { + this.$get = ['$rootScope', '$interval', function ($rootScope, $interval) { var dataFactory = {}; var counter = 0; @@ -143,15 +143,15 @@ app.provider('Flash', function () { } $rootScope.flashes.push(flash); if (flash.timeout) { - flash.timeoutObj = $timeout(function () { + flash.timeoutObj = $interval(function () { $this.dismiss(flash.id); - }, flash.timeout); + }, flash.timeout, 1); } return flash.id; }; dataFactory.pause = function (index) { if ($rootScope.flashes[index].timeoutObj) { - $timeout.cancel($rootScope.flashes[index].timeoutObj); + $interval.cancel($rootScope.flashes[index].timeoutObj); } }; dataFactory.dismiss = function (id) { diff --git a/dist/angular-flash.js.map b/dist/angular-flash.js.map index 275b63e..b4c1eff 100644 --- a/dist/angular-flash.js.map +++ b/dist/angular-flash.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/angular-flash.js"],"names":[],"mappings":";;AAAA,IAAM,MAAM,QAAQ,MAAR,CAAe,SAAf,EAA0B,EAA1B,CAAN;;AAEN,IAAI,GAAJ,CAAQ,CACJ,YADI,EACU,UAAS,UAAT,EAAqB;AAC/B,WAAO,WAAW,OAAX,GAAqB,EAArB,CADwB;CAArB,CADlB;;AAMA,IAAI,SAAJ,CAAc,SAAd,EAAyB,CACrB,UADqB,EACT,UAAS,QAAT,EAAmB;AAC3B,WAAO;AACH,kBAAU,GAAV;AACA,iBAAS,IAAT;AACA,cAAM,cAAS,KAAT,EAAgB,GAAhB,EAAqB,KAArB,EAA4B;AAC9B,mBAAO,MAAM,MAAN,CAAa,MAAM,OAAN,EAAe,UAAS,IAAT,EAAe;AAC9C,oBAAI,IAAJ,CAAS,IAAT,EAD8C;AAE9C,uBAAO,SAAS,IAAI,QAAJ,EAAT,EAAyB,KAAzB,CAAP,CAF8C;aAAf,CAAnC,CAD8B;SAA5B;KAHV,CAD2B;CAAnB,CADhB;;AAeA,IAAI,SAAJ,CAAc,iBAAd,EAAiC,CAC7B,UAD6B,EACjB,UAAS,QAAT,EAAmB;AAC3B,WAAO;AACH,kBAAU,GAAV;AACA,cAAM,cAAS,KAAT,EAAgB,GAAhB,EAA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,CAAvB,CAA4C,OAA5C,CAAoD,EAApD,CAAP,CADuB;SAA3B;;AAIA,eAAO,WAAP,CA9DkE;KAA/B,CAAvC,CAlD6B;CAAX,CAAtB","file":"angular-flash.js","sourcesContent":["const app = angular.module('ngFlash', []);\n\napp.run([\n '$rootScope', function($rootScope) {\n return $rootScope.flashes = [];\n }\n]);\n\napp.directive('dynamic', [\n '$compile', function($compile) {\n return {\n restrict: 'A',\n replace: true,\n link: function(scope, ele, attrs) {\n return scope.$watch(attrs.dynamic, function(html) {\n ele.html(html);\n return $compile(ele.contents())(scope);\n });\n }\n };\n }\n]);\n\napp.directive('applytransclude', [\n '$compile', function($compile) {\n return {\n restrict: 'A',\n link: function(scope, ele, attrs) {\n scope._transclude(scope, function(clone, scope) {\n ele.empty().append(clone);\n });\n }\n };\n }\n]);\n\napp.directive('closeFlash', [\n '$compile', '$rootScope', 'Flash', function($compile, $rootScope, Flash) {\n return {\n link: function(scope, ele, attrs) {\n return ele.on('click', function() {\n let id = parseInt(attrs.closeFlash, 10);\n Flash.dismiss(id);\n $rootScope.$apply();\n });\n }\n };\n }\n]);\n\napp.directive('flashMessage', [\n 'Flash', function(Flash) {\n return {\n restrict: 'E',\n scope: {\n duration: '=',\n showClose: '=',\n onDismiss: '&',\n name: '@'\n },\n link: function(scope, ele, attrs, ctrl, transclude) {\n Flash.setTimeout(scope.duration);\n Flash.setShowClose(scope.showClose);\n function onDismiss(flash) {\n if (typeof scope.onDismiss !== 'function') return;\n scope.onDismiss({flash: flash});\n }\n\n Flash.setOnDismiss(onDismiss);\n\n if (Flash.config.templateTransclude) {\n scope._transclude = transclude;\n }\n },\n transclude: Flash.config.templateTransclude,\n template: `\n
\n ` + Flash.config.template + `\n
\n `\n };\n }\n]);\n\napp.provider('Flash', function() {\n let defaultConfig = {};\n let templatePresets = {\n bootstrap: {\n html: `\n
\n
\n ×\n Close\n
\n \n
`,\n transclude: false\n },\n transclude: {\n html: `
`,\n transclude: true\n }\n };\n\n this.setTimeout = function(timeout) {\n if (typeof timeout !== 'number') return;\n defaultConfig.timeout = timeout;\n };\n this.setShowClose = function(value) {\n if (typeof value !== 'boolean') return;\n defaultConfig.showClose = value;\n };\n this.setTemplate = function(template) {\n if (typeof template !== 'string') return;\n defaultConfig.template = template;\n };\n this.setTemplatePreset = function(preset) {\n if (typeof preset !== 'string'\n || !(preset in templatePresets)) return;\n\n let template = templatePresets[preset];\n this.setTemplate(template.html);\n defaultConfig.templateTransclude = template.transclude;\n };\n this.setOnDismiss = function(callback) {\n if (typeof callback !== 'function') return;\n defaultConfig.onDismiss = callback;\n };\n\n this.setTimeout(5000);\n this.setShowClose(true);\n this.setTemplatePreset('bootstrap');\n\n this.$get = ['$rootScope', '$timeout', function($rootScope, $timeout) {\n const dataFactory = {};\n let counter = 0;\n\n dataFactory.setTimeout = this.setTimeout;\n dataFactory.setShowClose = this.setShowClose;\n dataFactory.setOnDismiss = this.setOnDismiss;\n dataFactory.config = defaultConfig;\n\n dataFactory.create = function(type, text, timeout, config, showClose) {\n if (!text) return false;\n let $this, flash;\n $this = this;\n flash = {\n type: type,\n text: text,\n config: config,\n id: counter++\n };\n flash.showClose =\n typeof showClose !== 'undefined' ?\n showClose : defaultConfig.showClose;\n if (defaultConfig.timeout && typeof timeout === 'undefined') {\n flash.timeout = defaultConfig.timeout;\n }\n else if (timeout) {\n flash.timeout = timeout;\n }\n $rootScope.flashes.push(flash);\n if (flash.timeout) {\n flash.timeoutObj = $timeout(function() {\n $this.dismiss(flash.id);\n }, flash.timeout);\n }\n return flash.id;\n };\n dataFactory.pause = function(index) {\n if ($rootScope.flashes[index].timeoutObj) {\n $timeout.cancel($rootScope.flashes[index].timeoutObj);\n }\n };\n dataFactory.dismiss = function(id) {\n const index = findIndexById(id);\n if (index !== -1) {\n const flash = $rootScope.flashes[index];\n dataFactory.pause(index);\n $rootScope.flashes.splice(index, 1);\n if (typeof defaultConfig.onDismiss === 'function') {\n defaultConfig.onDismiss(flash);\n }\n }\n };\n dataFactory.clear = function() {\n while ($rootScope.flashes.length > 0) {\n dataFactory.dismiss($rootScope.flashes[0].id);\n }\n };\n dataFactory.reset = dataFactory.clear;\n function findIndexById(id) {\n return $rootScope.flashes.map((flash) => flash.id).indexOf(id);\n }\n\n return dataFactory;\n }];\n});\n"]} \ No newline at end of file +{"version":3,"sources":["../src/angular-flash.js"],"names":["app","angular","module","run","$rootScope","flashes","directive","$compile","restrict","replace","link","scope","ele","attrs","$watch","dynamic","html","contents","_transclude","clone","empty","append","Flash","on","id","parseInt","closeFlash","dismiss","$apply","duration","showClose","onDismiss","name","ctrl","transclude","setTimeout","setShowClose","flash","setOnDismiss","config","templateTransclude","template","provider","defaultConfig","templatePresets","bootstrap","timeout","value","setTemplate","setTemplatePreset","preset","callback","$get","$interval","dataFactory","counter","create","type","text","$this","push","timeoutObj","pause","index","cancel","findIndexById","splice","clear","length","reset","map","indexOf"],"mappings":";;AAAA,IAAMA,MAAMC,QAAQC,MAAR,CAAe,SAAf,EAA0B,EAA1B,CAAZ;;AAEAF,IAAIG,GAAJ,CAAQ,CACJ,YADI,EACU,UAASC,UAAT,EAAqB;AAC/B,WAAOA,WAAWC,OAAX,GAAqB,EAA5B;AACH,CAHG,CAAR;;AAMAL,IAAIM,SAAJ,CAAc,SAAd,EAAyB,CACrB,UADqB,EACT,UAASC,QAAT,EAAmB;AAC3B,WAAO;AACHC,kBAAU,GADP;AAEHC,iBAAS,IAFN;AAGHC,cAAM,cAASC,KAAT,EAAgBC,GAAhB,EAAqBC,KAArB,EAA4B;AAC9B,mBAAOF,MAAMG,MAAN,CAAaD,MAAME,OAAnB,EAA4B,UAASC,IAAT,EAAe;AAC9CJ,oBAAII,IAAJ,CAASA,IAAT;AACA,uBAAOT,SAASK,IAAIK,QAAJ,EAAT,EAAyBN,KAAzB,CAAP;AACH,aAHM,CAAP;AAIH;AARE,KAAP;AAUH,CAZoB,CAAzB;;AAeAX,IAAIM,SAAJ,CAAc,iBAAd,EAAiC,CAC7B,UAD6B,EAC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AACjC,KAAD;AAAA,uBAAWA,MAAMb,EAAjB;AAAA,aAAvB,EAA4C+C,OAA5C,CAAoD/C,EAApD,CAAP;AACH;;AAED,eAAO8B,WAAP;AACH,KA/DW,CAAZ;AAgEH,CAlHD","file":"angular-flash.js","sourcesContent":["const app = angular.module('ngFlash', []);\n\napp.run([\n '$rootScope', function($rootScope) {\n return $rootScope.flashes = [];\n }\n]);\n\napp.directive('dynamic', [\n '$compile', function($compile) {\n return {\n restrict: 'A',\n replace: true,\n link: function(scope, ele, attrs) {\n return scope.$watch(attrs.dynamic, function(html) {\n ele.html(html);\n return $compile(ele.contents())(scope);\n });\n }\n };\n }\n]);\n\napp.directive('applytransclude', [\n '$compile', function($compile) {\n return {\n restrict: 'A',\n link: function(scope, ele, attrs) {\n scope._transclude(scope, function(clone, scope) {\n ele.empty().append(clone);\n });\n }\n };\n }\n]);\n\napp.directive('closeFlash', [\n '$compile', '$rootScope', 'Flash', function($compile, $rootScope, Flash) {\n return {\n link: function(scope, ele, attrs) {\n return ele.on('click', function() {\n let id = parseInt(attrs.closeFlash, 10);\n Flash.dismiss(id);\n $rootScope.$apply();\n });\n }\n };\n }\n]);\n\napp.directive('flashMessage', [\n 'Flash', function(Flash) {\n return {\n restrict: 'E',\n scope: {\n duration: '=',\n showClose: '=',\n onDismiss: '&',\n name: '@'\n },\n link: function(scope, ele, attrs, ctrl, transclude) {\n Flash.setTimeout(scope.duration);\n Flash.setShowClose(scope.showClose);\n function onDismiss(flash) {\n if (typeof scope.onDismiss !== 'function') return;\n scope.onDismiss({flash: flash});\n }\n\n Flash.setOnDismiss(onDismiss);\n\n if (Flash.config.templateTransclude) {\n scope._transclude = transclude;\n }\n },\n transclude: Flash.config.templateTransclude,\n template: `\n
\n ` + Flash.config.template + `\n
\n `\n };\n }\n]);\n\napp.provider('Flash', function() {\n let defaultConfig = {};\n let templatePresets = {\n bootstrap: {\n html: `\n
\n
\n ×\n Close\n
\n \n
`,\n transclude: false\n },\n transclude: {\n html: `
`,\n transclude: true\n }\n };\n\n this.setTimeout = function(timeout) {\n if (typeof timeout !== 'number') return;\n defaultConfig.timeout = timeout;\n };\n this.setShowClose = function(value) {\n if (typeof value !== 'boolean') return;\n defaultConfig.showClose = value;\n };\n this.setTemplate = function(template) {\n if (typeof template !== 'string') return;\n defaultConfig.template = template;\n };\n this.setTemplatePreset = function(preset) {\n if (typeof preset !== 'string'\n || !(preset in templatePresets)) return;\n\n let template = templatePresets[preset];\n this.setTemplate(template.html);\n defaultConfig.templateTransclude = template.transclude;\n };\n this.setOnDismiss = function(callback) {\n if (typeof callback !== 'function') return;\n defaultConfig.onDismiss = callback;\n };\n\n this.setTimeout(5000);\n this.setShowClose(true);\n this.setTemplatePreset('bootstrap');\n\n this.$get = ['$rootScope', '$interval', function($rootScope, $interval) {\n const dataFactory = {};\n let counter = 0;\n\n dataFactory.setTimeout = this.setTimeout;\n dataFactory.setShowClose = this.setShowClose;\n dataFactory.setOnDismiss = this.setOnDismiss;\n dataFactory.config = defaultConfig;\n\n dataFactory.create = function(type, text, timeout, config, showClose) {\n if (!text) return false;\n let $this, flash;\n $this = this;\n flash = {\n type: type,\n text: text,\n config: config,\n id: counter++\n };\n flash.showClose =\n typeof showClose !== 'undefined' ?\n showClose : defaultConfig.showClose;\n if (defaultConfig.timeout && typeof timeout === 'undefined') {\n flash.timeout = defaultConfig.timeout;\n }\n else if (timeout) {\n flash.timeout = timeout;\n }\n $rootScope.flashes.push(flash);\n if (flash.timeout) {\n flash.timeoutObj = $interval(function() {\n $this.dismiss(flash.id);\n }, flash.timeout, 1);\n }\n return flash.id;\n };\n dataFactory.pause = function(index) {\n if ($rootScope.flashes[index].timeoutObj) {\n $interval.cancel($rootScope.flashes[index].timeoutObj);\n }\n };\n dataFactory.dismiss = function(id) {\n const index = findIndexById(id);\n if (index !== -1) {\n const flash = $rootScope.flashes[index];\n dataFactory.pause(index);\n $rootScope.flashes.splice(index, 1);\n if (typeof defaultConfig.onDismiss === 'function') {\n defaultConfig.onDismiss(flash);\n }\n }\n };\n dataFactory.clear = function() {\n while ($rootScope.flashes.length > 0) {\n dataFactory.dismiss($rootScope.flashes[0].id);\n }\n };\n dataFactory.reset = dataFactory.clear;\n function findIndexById(id) {\n return $rootScope.flashes.map((flash) => flash.id).indexOf(id);\n }\n\n return dataFactory;\n }];\n});\n"]} \ No newline at end of file diff --git a/dist/angular-flash.min.js b/dist/angular-flash.min.js index 396b0e2..d1e43bc 100644 --- a/dist/angular-flash.min.js +++ b/dist/angular-flash.min.js @@ -1,6 +1,6 @@ -/*! angular-flash - v2.4.0 - 2016-10-25 +/*! angular-flash - v2.4.0 - 2016-11-07 * https://github.com/sachinchoolur/angular-flash * Copyright (c) 2016 Sachin; Licensed MIT */ -"use strict";var app=angular.module("ngFlash",[]);app.run(["$rootScope",function(a){return a.flashes=[]}]),app.directive("dynamic",["$compile",function(a){return{restrict:"A",replace:!0,link:function(b,c,d){return b.$watch(d.dynamic,function(d){return c.html(d),a(c.contents())(b)})}}}]),app.directive("applytransclude",["$compile",function(a){return{restrict:"A",link:function(a,b,c){a._transclude(a,function(a,c){b.empty().append(a)})}}}]),app.directive("closeFlash",["$compile","$rootScope","Flash",function(a,b,c){return{link:function(a,d,e){return d.on("click",function(){var a=parseInt(e.closeFlash,10);c.dismiss(a),b.$apply()})}}}]),app.directive("flashMessage",["Flash",function(a){return{restrict:"E",scope:{duration:"=",showClose:"=",onDismiss:"&",name:"@"},link:function(b,c,d,e,f){function g(a){"function"==typeof b.onDismiss&&b.onDismiss({flash:a})}a.setTimeout(b.duration),a.setShowClose(b.showClose),a.setOnDismiss(g),a.config.templateTransclude&&(b._transclude=f)},transclude:a.config.templateTransclude,template:'\n
\n '+a.config.template+"\n
\n "}}]),app.provider("Flash",function(){var a={},b={bootstrap:{html:'\n ',transclude:!1},transclude:{html:"
",transclude:!0}};this.setTimeout=function(b){"number"==typeof b&&(a.timeout=b)},this.setShowClose=function(b){"boolean"==typeof b&&(a.showClose=b)},this.setTemplate=function(b){"string"==typeof b&&(a.template=b)},this.setTemplatePreset=function(c){if("string"==typeof c&&c in b){var d=b[c];this.setTemplate(d.html),a.templateTransclude=d.transclude}},this.setOnDismiss=function(b){"function"==typeof b&&(a.onDismiss=b)},this.setTimeout(5e3),this.setShowClose(!0),this.setTemplatePreset("bootstrap"),this.$get=["$rootScope","$timeout",function(b,c){function d(a){return b.flashes.map(function(a){return a.id}).indexOf(a)}var e={},f=0;return e.setTimeout=this.setTimeout,e.setShowClose=this.setShowClose,e.setOnDismiss=this.setOnDismiss,e.config=a,e.create=function(d,e,g,h,i){if(!e)return!1;var j=void 0,k=void 0;return j=this,k={type:d,text:e,config:h,id:f++},k.showClose="undefined"!=typeof i?i:a.showClose,a.timeout&&"undefined"==typeof g?k.timeout=a.timeout:g&&(k.timeout=g),b.flashes.push(k),k.timeout&&(k.timeoutObj=c(function(){j.dismiss(k.id)},k.timeout)),k.id},e.pause=function(a){b.flashes[a].timeoutObj&&c.cancel(b.flashes[a].timeoutObj)},e.dismiss=function(c){var f=d(c);if(-1!==f){var g=b.flashes[f];e.pause(f),b.flashes.splice(f,1),"function"==typeof a.onDismiss&&a.onDismiss(g)}},e.clear=function(){for(;b.flashes.length>0;)e.dismiss(b.flashes[0].id)},e.reset=e.clear,e}]}); +"use strict";var app=angular.module("ngFlash",[]);app.run(["$rootScope",function(a){return a.flashes=[]}]),app.directive("dynamic",["$compile",function(a){return{restrict:"A",replace:!0,link:function(b,c,d){return b.$watch(d.dynamic,function(d){return c.html(d),a(c.contents())(b)})}}}]),app.directive("applytransclude",["$compile",function(a){return{restrict:"A",link:function(a,b,c){a._transclude(a,function(a,c){b.empty().append(a)})}}}]),app.directive("closeFlash",["$compile","$rootScope","Flash",function(a,b,c){return{link:function(a,d,e){return d.on("click",function(){var a=parseInt(e.closeFlash,10);c.dismiss(a),b.$apply()})}}}]),app.directive("flashMessage",["Flash",function(a){return{restrict:"E",scope:{duration:"=",showClose:"=",onDismiss:"&",name:"@"},link:function(b,c,d,e,f){function g(a){"function"==typeof b.onDismiss&&b.onDismiss({flash:a})}a.setTimeout(b.duration),a.setShowClose(b.showClose),a.setOnDismiss(g),a.config.templateTransclude&&(b._transclude=f)},transclude:a.config.templateTransclude,template:'\n
\n '+a.config.template+"\n
\n "}}]),app.provider("Flash",function(){var a={},b={bootstrap:{html:'\n ',transclude:!1},transclude:{html:"
",transclude:!0}};this.setTimeout=function(b){"number"==typeof b&&(a.timeout=b)},this.setShowClose=function(b){"boolean"==typeof b&&(a.showClose=b)},this.setTemplate=function(b){"string"==typeof b&&(a.template=b)},this.setTemplatePreset=function(c){if("string"==typeof c&&c in b){var d=b[c];this.setTemplate(d.html),a.templateTransclude=d.transclude}},this.setOnDismiss=function(b){"function"==typeof b&&(a.onDismiss=b)},this.setTimeout(5e3),this.setShowClose(!0),this.setTemplatePreset("bootstrap"),this.$get=["$rootScope","$interval",function(b,c){function d(a){return b.flashes.map(function(a){return a.id}).indexOf(a)}var e={},f=0;return e.setTimeout=this.setTimeout,e.setShowClose=this.setShowClose,e.setOnDismiss=this.setOnDismiss,e.config=a,e.create=function(d,e,g,h,i){if(!e)return!1;var j=void 0,k=void 0;return j=this,k={type:d,text:e,config:h,id:f++},k.showClose="undefined"!=typeof i?i:a.showClose,a.timeout&&"undefined"==typeof g?k.timeout=a.timeout:g&&(k.timeout=g),b.flashes.push(k),k.timeout&&(k.timeoutObj=c(function(){j.dismiss(k.id)},k.timeout,1)),k.id},e.pause=function(a){b.flashes[a].timeoutObj&&c.cancel(b.flashes[a].timeoutObj)},e.dismiss=function(c){var f=d(c);if(f!==-1){var g=b.flashes[f];e.pause(f),b.flashes.splice(f,1),"function"==typeof a.onDismiss&&a.onDismiss(g)}},e.clear=function(){for(;b.flashes.length>0;)e.dismiss(b.flashes[0].id)},e.reset=e.clear,e}]}); //# sourceMappingURL=angular-flash.min.js.map \ No newline at end of file diff --git a/dist/angular-flash.min.js.map b/dist/angular-flash.min.js.map index 4f3a20d..e417ee3 100644 --- a/dist/angular-flash.min.js.map +++ b/dist/angular-flash.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["angular-flash.js"],"names":["app","angular","module","run","$rootScope","flashes","directive","$compile","restrict","replace","link","scope","ele","attrs","$watch","dynamic","html","contents","_transclude","clone","empty","append","Flash","on","id","parseInt","closeFlash","dismiss","$apply","duration","showClose","onDismiss","name","ctrl","transclude","flash","setTimeout","setShowClose","setOnDismiss","config","templateTransclude","template","provider","defaultConfig","templatePresets","bootstrap","this","timeout","value","setTemplate","setTemplatePreset","preset","callback","$get","$timeout","findIndexById","map","indexOf","dataFactory","counter","create","type","text","$this","push","timeoutObj","pause","index","cancel","splice","clear","length","reset"],"mappings":"AAAA,YAEA,IAAIA,KAAMC,QAAQC,OAAO,aAEzBF,KAAIG,KAAK,aAAc,SAAUC,GAC7B,MAAOA,GAAWC,cAGtBL,IAAIM,UAAU,WAAY,WAAY,SAAUC,GAC5C,OACIC,SAAU,IACVC,SAAS,EACTC,KAAM,SAAcC,EAAOC,EAAKC,GAC5B,MAAOF,GAAMG,OAAOD,EAAME,QAAS,SAAUC,GAEzC,MADAJ,GAAII,KAAKA,GACFT,EAASK,EAAIK,YAAYN,UAMhDX,IAAIM,UAAU,mBAAoB,WAAY,SAAUC,GACpD,OACIC,SAAU,IACVE,KAAM,SAAcC,EAAOC,EAAKC,GAC5BF,EAAMO,YAAYP,EAAO,SAAUQ,EAAOR,GACtCC,EAAIQ,QAAQC,OAAOF,UAMnCnB,IAAIM,UAAU,cAAe,WAAY,aAAc,QAAS,SAAUC,EAAUH,EAAYkB,GAC5F,OACIZ,KAAM,SAAcC,EAAOC,EAAKC,GAC5B,MAAOD,GAAIW,GAAG,QAAS,WACnB,GAAIC,GAAKC,SAASZ,EAAMa,WAAY,GACpCJ,GAAMK,QAAQH,GACdpB,EAAWwB,gBAM3B5B,IAAIM,UAAU,gBAAiB,QAAS,SAAUgB,GAC9C,OACId,SAAU,IACVG,OACIkB,SAAU,IACVC,UAAW,IACXC,UAAW,IACX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pB,aAAeQ,KAAKR,aAChCoB,EAAYnB,OAASI,EAErBe,EAAYE,OAAS,SAAUC,EAAMC,EAAMf,EAASR,EAAQT,GACxD,IAAKgC,EAAM,OAAO,CAClB,IAAIC,GAAQ,OACR5B,EAAQ,MAoBZ,OAnBA4B,GAAQjB,KACRX,GACI0B,KAAMA,EACNC,KAAMA,EACNvB,OAAQA,EACRf,GAAImC,KAERxB,EAAML,UAAiC,mBAAdA,GAA4BA,EAAYa,EAAcb,UAC3Ea,EAAcI,SAA8B,mBAAZA,GAChCZ,EAAMY,QAAUJ,EAAcI,QACvBA,IACPZ,EAAMY,QAAUA,GAEpB3C,EAAWC,QAAQ2D,KAAK7B,GACpBA,EAAMY,UACNZ,EAAM8B,WAAaX,EAAS,WACxBS,EAAMpC,QAAQQ,EAAMX,KACrBW,EAAMY,UAENZ,EAAMX,IAEjBkC,EAAYQ,MAAQ,SAAUC,GACtB/D,EAAWC,QAAQ8D,GAAOF,YAC1BX,EAASc,OAAOhE,EAAWC,QAAQ8D,GAAOF,aAGlDP,EAAY/B,QAAU,SAAUH,GAC5B,GAAI2C,GAAQZ,EAAc/B,EAC1B,IAAc,KAAV2C,EAAc,CACd,GAAIhC,GAAQ/B,EAAWC,QAAQ8D,EAC/BT,GAAYQ,MAAMC,GAClB/D,EAAWC,QAAQgE,OAAOF,EAAO,GACM,kBAA5BxB,GAAcZ,WACrBY,EAAcZ,UAAUI,KAIpCuB,EAAYY,MAAQ,WAChB,KAAOlE,EAAWC,QAAQkE,OAAS,GAC/Bb,EAAY/B,QAAQvB,EAAWC,QAAQ,GAAGmB,KAGlDkC,EAAYc,MAAQd,EAAYY,MAOzBZ","file":"angular-flash.min.js"} \ No newline at end of file +{"version":3,"sources":["angular-flash.js"],"names":["app","angular","module","run","$rootScope","flashes","directive","$compile","restrict","replace","link","scope","ele","attrs","$watch","dynamic","html","contents","_transclude","clone","empty","append","Flash","on","id","parseInt","closeFlash","dismiss","$apply","duration","showClose","onDismiss","name","ctrl","transclude","flash","setTimeout","setShowClose","setOnDismiss","config","templateTransclude","template","provider","defaultConfig","templatePresets","bootstrap","this","timeout","value","setTemplate","setTemplatePreset","preset","callback","$get","$interval","findIndexById","map","indexOf","dataFactory","counter","create","type","text","$this","push","timeoutObj","pause","index","cancel","splice","clear","length","reset"],"mappings":"AAAA,YAEA,IAAIA,KAAMC,QAAQC,OAAO,aAEzBF,KAAIG,KAAK,aAAc,SAAUC,GAC7B,MAAOA,GAAWC,cAGtBL,IAAIM,UAAU,WAAY,WAAY,SAAUC,GAC5C,OACIC,SAAU,IACVC,SAAS,EACTC,KAAM,SAAcC,EAAOC,EAAKC,GAC5B,MAAOF,GAAMG,OAAOD,EAAME,QAAS,SAAUC,GAEzC,MADAJ,GAAII,KAAKA,GACFT,EAASK,EAAIK,YAAYN,UAMhDX,IAAIM,UAAU,mBAAoB,WAAY,SAAUC,GACpD,OACIC,SAAU,IACVE,KAAM,SAAcC,EAAOC,EAAKC,GAC5BF,EAAMO,YAAYP,EAAO,SAAUQ,EAAOR,GACtCC,EAAIQ,QAAQC,OAAOF,UAMnCnB,IAAIM,UAAU,cAAe,WAAY,aAAc,QAAS,SAAUC,EAAUH,EAAYkB,GAC5F,OACIZ,KAAM,SAAcC,EAAOC,EAAKC,GAC5B,MAAOD,GAAIW,GAAG,QAAS,WACnB,GAAIC,GAAKC,SAASZ,EAAMa,WAAY,GACpCJ,GAAMK,QAAQH,GACdpB,EAAWwB,gBAM3B5B,IAAIM,UAAU,gBAAiB,QAAS,SAAUgB,GAC9C,OACId,SAAU,IACVG,OACIkB,SAAU,IACVC,UAAW,IACXC,UAAW,IACXC,KAAM,KAEVtB,KAAM,SAAcC,EAAOC,EAAKC,EAAOoB,EAAMC,GAGzC,QAASH,GAAUI,GACgB,kBAApBxB,GAAMoB,WACjBpB,EAAMoB,WAAYI,MAAOA,IAJ7Bb,EAAMc,WAAWzB,EAAMkB,UACvBP,EAAMe,aAAa1B,EAAMmB,WAMzBR,EAAMgB,aAAaP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,OAAQA,EACRf,GAAImC,KAERxB,EAAML,UAAiC,mBAAdA,GAA4BA,EAAYa,EAAcb,UAC3Ea,EAAcI,SAA8B,mBAAZA,GAChCZ,EAAMY,QAAUJ,EAAcI,QACvBA,IACPZ,EAAMY,QAAUA,GAEpB3C,EAAWC,QAAQ2D,KAAK7B,GACpBA,EAAMY,UACNZ,EAAM8B,WAAaX,EAAU,WACzBS,EAAMpC,QAAQQ,EAAMX,KACrBW,EAAMY,QAAS,IAEfZ,EAAMX,IAEjBkC,EAAYQ,MAAQ,SAAUC,GACtB/D,EAAWC,QAAQ8D,GAAOF,YAC1BX,EAAUc,OAAOhE,EAAWC,QAAQ8D,GAAOF,aAGnDP,EAAY/B,QAAU,SAAUH,GAC5B,GAAI2C,GAAQZ,EAAc/B,EAC1B,IAAI2C,KAAU,EAAI,CACd,GAAIhC,GAAQ/B,EAAWC,QAAQ8D,EAC/BT,GAAYQ,MAAMC,GAClB/D,EAAWC,QAAQgE,OAAOF,EAAO,GACM,kBAA5BxB,GAAcZ,WACrBY,EAAcZ,UAAUI,KAIpCuB,EAAYY,MAAQ,WAChB,KAAOlE,EAAWC,QAAQkE,OAAS,GAC/Bb,EAAY/B,QAAQvB,EAAWC,QAAQ,GAAGmB,KAGlDkC,EAAYc,MAAQd,EAAYY,MAOzBZ","file":"angular-flash.min.js"} \ No newline at end of file diff --git a/src/angular-flash.js b/src/angular-flash.js index c2b43bd..2064c61 100644 --- a/src/angular-flash.js +++ b/src/angular-flash.js @@ -132,7 +132,7 @@ app.provider('Flash', function() { this.setShowClose(true); this.setTemplatePreset('bootstrap'); - this.$get = ['$rootScope', '$timeout', function($rootScope, $timeout) { + this.$get = ['$rootScope', '$interval', function($rootScope, $interval) { const dataFactory = {}; let counter = 0; @@ -162,15 +162,15 @@ app.provider('Flash', function() { } $rootScope.flashes.push(flash); if (flash.timeout) { - flash.timeoutObj = $timeout(function() { + flash.timeoutObj = $interval(function() { $this.dismiss(flash.id); - }, flash.timeout); + }, flash.timeout, 1); } return flash.id; }; dataFactory.pause = function(index) { if ($rootScope.flashes[index].timeoutObj) { - $timeout.cancel($rootScope.flashes[index].timeoutObj); + $interval.cancel($rootScope.flashes[index].timeoutObj); } }; dataFactory.dismiss = function(id) { diff --git a/test/angular-flash_test.js b/test/angular-flash_test.js index 3224909..c09cfa5 100644 --- a/test/angular-flash_test.js +++ b/test/angular-flash_test.js @@ -1,7 +1,7 @@ describe('Unit testing Angular Flash', function() { var $compile, $rootScope, - $timeout, + $interval, node, Flash; @@ -10,11 +10,11 @@ describe('Unit testing Angular Flash', function() { // Store references to $rootScope and $compile // so they are available to all tests in this describe block - beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _Flash_) { + beforeEach(inject(function(_$compile_, _$rootScope_, _$interval_, _Flash_) { // The injector unwraps the underscores (_) from around the parameter names when matching $compile = _$compile_; $rootScope = _$rootScope_; - $timeout = _$timeout_; + $interval = _$interval_; Flash = _Flash_; })); @@ -79,7 +79,7 @@ describe('Unit testing Angular Flash', function() { var contents = node.contents()[0]; expect(contents.querySelectorAll('.alert').length).toEqual(1); - $timeout.flush(); + $interval.flush(); $rootScope.$digest(); expect(contents.querySelectorAll('.alert').length).toEqual(0); });