Implementing a countdown bbcode

Hi all!
I would like some help for starting the development of a “countdown” bbcode that, as the name says, will display a countdown in a post.
The idea is to translate something like this [countdown=<iso date and time>] into a simple textual countdown of the format ddd:hh:mm:ss where d is days, h is hours, m is minutes and s is seconds.

The experiments I did so far was inserting some js code to calculate the amount of days, hours and so on. I inserted it in the header part of the theme through the theme editing interface, and I can display the countdown in the js console no probs.

The tricky part, even after having read the Beginner's guide to developing Discourse Themes , is to find a way to:

  • find whether the post raw text contains a [countdown ...] tag
  • get the iso date in it and validate it
  • if validation succeeds, start the countdown js function and perform text substitution in the post cooked text

I was thinking to get some inspiration from the code that performs the [date ...] function provided by Discourse. Would that be a valid choice? Could you suggest any better alterntive?

Thanks in advance!

I would look at the calendar plugin that does something similar.

1 Like