From 4169b61f98d5a594b4e5fcb423461282df7bf1d9 Mon Sep 17 00:00:00 2001 From: John Anderson Date: Sun, 8 Mar 2015 15:58:42 -0400 Subject: [PATCH 1/3] Added Filter Support added filter attribute of dom element to contain the angular filter --- README.md | 3 +++ build/angular-count-to.min.js | 4 +-- .../com/hurlant/crypto/rsa/RSAKey.as | 8 +++--- src/count-to.js | 7 +++-- test/unit/directivesSpec.js | 26 +++++++++++++++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 38ba862..ba19337 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ Apply the directive to a dom element. ``` ``` +Optionally you can use a filter on the value + ### Attributes @@ -31,4 +33,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..5edefd3 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-03-08 */ +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) + + })); }); From 1559ec6905610435175746d5e5e714ff8f2523ac Mon Sep 17 00:00:00 2001 From: John Anderson Date: Tue, 7 Apr 2015 19:27:47 -0400 Subject: [PATCH 2/3] Updated Readme Updated readme with filter example. --- README.md | 3 ++- build/angular-count-to.min.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ba19337..1765d71 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,9 @@ Apply the directive to a dom element. ``` Optionally you can use a filter on the value +``` - +``` ### Attributes diff --git a/build/angular-count-to.min.js b/build/angular-count-to.min.js index 5edefd3..fb112ec 100644 --- a/build/angular-count-to.min.js +++ b/build/angular-count-to.min.js @@ -1,2 +1,2 @@ -/*! angular-count-to 2015-03-08 */ +/*! 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 From 72b4623f8c9a56223b6bc5f7810edec72e50f19e Mon Sep 17 00:00:00 2001 From: John Anderson Date: Tue, 7 Apr 2015 19:30:11 -0400 Subject: [PATCH 3/3] Updated website Updated url in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1765d71..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