-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added minlength option for leading zeros #11
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( '' ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you meant to keep this outside the digits = digits.split('') Considering the following code only uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow didn't notice that I hadn't even set digits equal to the 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)] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is being treated as a
Number
in the following implementation you should make sureminlength
will always be set to an integer. Your check here will set it to any truthy value.Consider changing this to something like
minlength: parseInt(options.minlength, 10) or 1