Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion assets/coffee/tick.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 : parseInt(options.minlength, 10) or 1

@increment = @build_increment_callback( options.incremental )

Expand Down Expand Up @@ -96,9 +98,14 @@ 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

# 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)]
Expand Down
11 changes: 9 additions & 2 deletions assets/js/tick.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.