diff --git a/README.md b/README.md index 38ba862..1fd7111 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Angular Count-To This project is an animated counter for Angularjs. The directive counts from one number to another over a configured duration. -[Demo](http://sparkalow.github.io/angular-count-to/) +[Demo](http://webkoils.github.io/angular-count-to/) ## How to use angular count-to @@ -22,7 +22,10 @@ Apply the directive to a dom element. ``` ``` - +Optionally you can use a filter on the value +``` + +``` ### Attributes @@ -31,4 +34,5 @@ The following attributes can be set as numbers on the directive element. - ```count-to``` the number to count to. - ```value``` the number to start counting from. - ```duration``` how long the count should take in seconds. +- ```filter``` a filter to apply to the displayed number diff --git a/build/angular-count-to.min.js b/build/angular-count-to.min.js index 91e224e..fb112ec 100644 --- a/build/angular-count-to.min.js +++ b/build/angular-count-to.min.js @@ -1,2 +1,2 @@ -/*! angular-count-to 2013-07-16 */ -var countTo=angular.module("countTo",[]).directive("countTo",["$timeout",function(a){return{replace:!1,scope:!0,link:function(b,c,d){var e,f,g,h,i,j,k,l=c[0],m=function(){f=30,i=0,b.timoutId=null,j=parseInt(d.countTo)||0,b.value=parseInt(d.value,10)||0,g=1e3*parseFloat(d.duration)||0,h=Math.ceil(g/f),k=(j-b.value)/h,e=b.value},n=function(){b.timoutId=a(function(){e+=k,i++,i>=h?(a.cancel(b.timoutId),e=j,l.innerText=j):(l.innerText=Math.round(e),n())},f)},o=function(){b.timoutId&&a.cancel(b.timoutId),m(),n()};return d.$observe("countTo",function(a){a&&o()}),d.$observe("value",function(){o()}),!0}}}]); \ No newline at end of file +/*! angular-count-to 2015-04-07 */ +var countTo=angular.module("countTo",[]).directive("countTo",["$timeout",function(a){return{replace:!1,scope:!0,link:function(b,c,d){var e,f,g,h,i,j,k,l=c[0],m=function(){f=30,i=0,b.timoutId=null,j=parseInt(d.countTo)||0,b.value=parseInt(d.value,10)||0,g=1e3*parseFloat(d.duration)||0,h=Math.ceil(g/f),k=(j-b.value)/h,e=b.value},n=function(){b.timoutId=a(function(){e+=k,i++,i>=h?(a.cancel(b.timoutId),e=j,l.textContent=d.filter?b.$eval("countTo |"+d.filter,{countTo:j}):j):(l.textContent=d.filter?b.$eval("num |"+d.filter,{num:e}):Math.round(e),n())},f)},o=function(){b.timoutId&&a.cancel(b.timoutId),m(),n()};return d.$observe("countTo",function(a){a&&o()}),d.$observe("value",function(){o()}),!0}}}]); \ No newline at end of file diff --git a/scripts/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as b/scripts/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as index cae9748..3d7af6b 100644 --- a/scripts/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as +++ b/scripts/node_modules/karma/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as @@ -69,7 +69,7 @@ package com.hurlant.crypto.rsa } - + public static function parsePublicKey(N:String, E:String):RSAKey { return new RSAKey(new BigInteger(N, 16, true), parseInt(E,16)); } @@ -94,14 +94,14 @@ package com.hurlant.crypto.rsa n = null; Memory.gc(); } - + public function encrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function=null):void { _encrypt(doPublic, src, dst, length, pad, 0x02); } public function decrypt(src:ByteArray, dst:ByteArray, length:uint, pad:Function=null):void { _decrypt(doPrivate2, src, dst, length, pad, 0x02); } - + public function sign(src:ByteArray, dst:ByteArray, length:uint, pad:Function = null):void { _encrypt(doPrivate2, src, dst, length, pad, 0x01); } @@ -109,7 +109,7 @@ package com.hurlant.crypto.rsa _decrypt(doPublic, src, dst, length, pad, 0x01); } - + private function _encrypt(op:Function, src:ByteArray, dst:ByteArray, length:uint, pad:Function, padType:int):void { // adjust pad if needed if (pad==null) pad = pkcs1pad; diff --git a/src/count-to.js b/src/count-to.js index d3aa7ad..649fba3 100644 --- a/src/count-to.js +++ b/src/count-to.js @@ -4,10 +4,8 @@ var countTo = angular.module('countTo', []) replace: false, scope: true, link: function (scope, element, attrs) { - var e = element[0]; var num, refreshInterval, duration, steps, step, countTo, value, increment; - var calculate = function () { refreshInterval = 30; step = 0; @@ -28,9 +26,10 @@ var countTo = angular.module('countTo', []) if (step >= steps) { $timeout.cancel(scope.timoutId); num = countTo; - e.textContent = countTo; + e.textContent = (attrs.filter ? scope.$eval("countTo |"+attrs.filter+"",{countTo:countTo}) : countTo); } else { - e.textContent = Math.round(num); + e.textContent = (attrs.filter ? scope.$eval("num |"+attrs.filter+"",{num:num}) : Math.round(num)); + tick(); } }, refreshInterval); diff --git a/test/unit/directivesSpec.js b/test/unit/directivesSpec.js index bee94c5..a4199a8 100644 --- a/test/unit/directivesSpec.js +++ b/test/unit/directivesSpec.js @@ -44,5 +44,31 @@ describe('count-to directive', function () { }, 0) })); + + it('should display unformatted number when no filter is set', inject(function ($compile, $rootScope, $timeout ) { + element = angular.element(''); + scope = $rootScope.$new(); + $compile(element)(scope); + $rootScope.$digest(); + + $timeout.flush(); + $timeout(function(){ + expect(element.text()).toBe('200'); + }, 0) + + })); + + it('should display formatted number', inject(function ($compile, $rootScope, $timeout ) { + element = angular.element(''); + scope = $rootScope.$new(); + $compile(element)(scope); + $rootScope.$digest(); + + $timeout.flush(); + $timeout(function(){ + expect(element.text()).toBe('200.00'); + }, 0) + + })); });