From aaec884bdd21f64260838a4fe58856d09a51d4a1 Mon Sep 17 00:00:00 2001 From: Aaron Holland Date: Sat, 10 May 2014 21:25:10 -0400 Subject: [PATCH 1/5] Added minlength option for leading zeros --- assets/coffee/tick.coffee | 10 +++++++++- assets/js/tick.js | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/assets/coffee/tick.coffee b/assets/coffee/tick.coffee index d49ee60..6c732ac 100755 --- a/assets/coffee/tick.coffee +++ b/assets/coffee/tick.coffee @@ -46,6 +46,7 @@ $.fn.ticker = (options) -> separators boolean if true, all arbitrary characters inbetween digits are wrapped in seperated elements if false, these characters are stripped out autostart boolean whether or not to start the ticker when instantiated + minlength int minimum length of the element, leading zeros will be put in place if not long enough Events @@ -64,6 +65,7 @@ class Tick delay : options.delay or 1000 separators: if options.separators? then options.separators else false autostart : if options.autostart? then options.autostart else true + minlength : options.minlength or 1 @increment = @build_increment_callback( options.incremental ) @@ -96,9 +98,15 @@ class Tick render: () -> - digits = String( @value ).split( '' ) + digits = String( @value ) containers = @element.children( ':not(.tick-separator)' ) + # add leading zeros if length is not long enough + if digits.length < @options.minlength + while (digits.length < @options.minlength) + digits = "0" + digits + digits.split( '' ) + # add new containers for each digit that doesnt exist (if they do, just update them) if digits.length > containers.length for i in [0...(digits.length - containers.length)] diff --git a/assets/js/tick.js b/assets/js/tick.js index 78a9564..08ade98 100755 --- a/assets/js/tick.js +++ b/assets/js/tick.js @@ -49,6 +49,7 @@ separators boolean if true, all arbitrary characters inbetween digits are wrapped in seperated elements if false, these characters are stripped out autostart boolean whether or not to start the ticker when instantiated + minlength int minimum length of the element, leading zeros will be put in place if not long enough Events @@ -68,7 +69,8 @@ this.options = { delay: options.delay || 1000, separators: options.separators != null ? options.separators : false, - autostart: options.autostart != null ? options.autostart : true + autostart: options.autostart != null ? options.autostart : true, + minlength: options.minlength || 1 }; this.increment = this.build_increment_callback(options.incremental); this.value = Number(this.element.html().replace(/[^\d.]/g, '')); @@ -95,8 +97,14 @@ Tick.prototype.render = function() { var container, containers, digits, i, _i, _j, _k, _len, _ref, _ref1, _ref2, _results; - digits = String(this.value).split(''); + digits = String(this.value); containers = this.element.children(':not(.tick-separator)'); + if (digits.length < this.options.minlength) { + while (digits.length < this.options.minlength) { + digits = "0" + digits; + } + digits.split(''); + } if (digits.length > containers.length) { for (i = _i = 0, _ref = digits.length - containers.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { if (this.options.separators && this.separators[i]) { From f20483b695dfde878a1bc74dbae99e9fab3dfaf8 Mon Sep 17 00:00:00 2001 From: Aaron Holland Date: Fri, 30 May 2014 14:57:09 -0400 Subject: [PATCH 2/5] Removed Split --- assets/coffee/tick.coffee | 1 - assets/js/tick.js | 1 - 2 files changed, 2 deletions(-) diff --git a/assets/coffee/tick.coffee b/assets/coffee/tick.coffee index 6c732ac..d68f267 100755 --- a/assets/coffee/tick.coffee +++ b/assets/coffee/tick.coffee @@ -105,7 +105,6 @@ class Tick if digits.length < @options.minlength while (digits.length < @options.minlength) digits = "0" + digits - digits.split( '' ) # add new containers for each digit that doesnt exist (if they do, just update them) if digits.length > containers.length diff --git a/assets/js/tick.js b/assets/js/tick.js index 08ade98..72888dc 100755 --- a/assets/js/tick.js +++ b/assets/js/tick.js @@ -103,7 +103,6 @@ while (digits.length < this.options.minlength) { digits = "0" + digits; } - digits.split(''); } if (digits.length > containers.length) { for (i = _i = 0, _ref = digits.length - containers.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { From 0525c099740d5e5d6d95505ab91a3a1bfaff9ed4 Mon Sep 17 00:00:00 2001 From: Aaron Holland Date: Tue, 3 Jun 2014 22:19:30 -0400 Subject: [PATCH 3/5] Added ParseInt for minlength --- assets/coffee/tick.coffee | 2 +- assets/js/tick.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/coffee/tick.coffee b/assets/coffee/tick.coffee index d68f267..2f167f6 100755 --- a/assets/coffee/tick.coffee +++ b/assets/coffee/tick.coffee @@ -65,7 +65,7 @@ class Tick delay : options.delay or 1000 separators: if options.separators? then options.separators else false autostart : if options.autostart? then options.autostart else true - minlength : options.minlength or 1 + minlength : parseInt(options.minlength, 10) or 1 @increment = @build_increment_callback( options.incremental ) diff --git a/assets/js/tick.js b/assets/js/tick.js index 72888dc..64d64d5 100755 --- a/assets/js/tick.js +++ b/assets/js/tick.js @@ -70,7 +70,7 @@ delay: options.delay || 1000, separators: options.separators != null ? options.separators : false, autostart: options.autostart != null ? options.autostart : true, - minlength: options.minlength || 1 + minlength: parseInt(options.minlength, 10) || 1 }; this.increment = this.build_increment_callback(options.incremental); this.value = Number(this.element.html().replace(/[^\d.]/g, '')); From 54c7fcac4b001ad71b79c40a65820a1a8141ba35 Mon Sep 17 00:00:00 2001 From: Aaron Holland Date: Tue, 3 Jun 2014 22:52:41 -0400 Subject: [PATCH 4/5] Fixed Separators Bug --- assets/coffee/tick.coffee | 1 + assets/js/tick.js | 1 + 2 files changed, 2 insertions(+) diff --git a/assets/coffee/tick.coffee b/assets/coffee/tick.coffee index 2f167f6..6c796ca 100755 --- a/assets/coffee/tick.coffee +++ b/assets/coffee/tick.coffee @@ -105,6 +105,7 @@ class Tick if digits.length < @options.minlength while (digits.length < @options.minlength) digits = "0" + digits + @separators.unshift('') # add new containers for each digit that doesnt exist (if they do, just update them) if digits.length > containers.length diff --git a/assets/js/tick.js b/assets/js/tick.js index 64d64d5..3b00a7f 100755 --- a/assets/js/tick.js +++ b/assets/js/tick.js @@ -102,6 +102,7 @@ if (digits.length < this.options.minlength) { while (digits.length < this.options.minlength) { digits = "0" + digits; + this.separators.unshift(''); } } if (digits.length > containers.length) { From 9fc7e30fc1aea2a250e3c146142b0daa10a7d018 Mon Sep 17 00:00:00 2001 From: Aaron Holland Date: Thu, 5 Jun 2014 13:15:17 -0400 Subject: [PATCH 5/5] Revert "Fixed Separators Bug" This reverts commit 54c7fcac4b001ad71b79c40a65820a1a8141ba35. --- assets/coffee/tick.coffee | 1 - assets/js/tick.js | 1 - 2 files changed, 2 deletions(-) diff --git a/assets/coffee/tick.coffee b/assets/coffee/tick.coffee index 6c796ca..2f167f6 100755 --- a/assets/coffee/tick.coffee +++ b/assets/coffee/tick.coffee @@ -105,7 +105,6 @@ class Tick if digits.length < @options.minlength while (digits.length < @options.minlength) digits = "0" + digits - @separators.unshift('') # add new containers for each digit that doesnt exist (if they do, just update them) if digits.length > containers.length diff --git a/assets/js/tick.js b/assets/js/tick.js index 3b00a7f..64d64d5 100755 --- a/assets/js/tick.js +++ b/assets/js/tick.js @@ -102,7 +102,6 @@ if (digits.length < this.options.minlength) { while (digits.length < this.options.minlength) { digits = "0" + digits; - this.separators.unshift(''); } } if (digits.length > containers.length) {