Countdown Timer - fapnip/openeos GitHub Wiki

Create and display a Countdown Timer

Example:

// Create and display new Timer instance
new Timer({
  duration: "3s",
  style: "normal",
  onTimeout: function() {
    new Say('<p>Boo!</p>')
  }
})

Timer

Constructor Options

duration

Required String or Number. If number, number of ms to wait. If string, '1s' = 1 second, '1m' one minute, etc.

style

Optional string. Default 'normal'

Options:

  • normal - Animated countdown timer is displayed while timer is counting down
  • secret - Animated spinner is displayed while timer is counting down
  • hidden - Nothing is displayed while timer is counting down

onTimeout

Optional Function. Called when timer loop is complete.

onContinue

Optional Function. Called when all timer loops are complete.

loops

Optional number. Default 1. Number of loops timer will run.

paused

Optional boolean. Default false. Start timer paused.

Constructor Methods

Timer.getAll()

Return array of all active timer ids

Timer.get(string)

Return timer instance for given id

Instance Methods

stop()

Cancel timer. Do not run onTimeout or onContinue.

pause()

Pause timer.

play()

Resume timer.

getPaused()

Returns true if timer is paused

getId()

Return id for given timer instance

getDuration()

Return duration for current timer loop in ms

getRemaining()

Return time remaining for current timer loop in ms

getLoops()

Return total number of loops for this timer. 0 = forever (until page change or stop)

getLoop()

Return current loop for this timer, starting with 0

Timer Action Overrides in EOS editor

Milovana's EOS editor does not natively support loops for its asynchronous timers.

To make an EOS Timer Action loop for a given number of times in OEOS:

  1. Turn on the timer's asynchronous mode.
  2. Add an EVAL action as the first Asynchronous action.
  3. In that eval action, add as the first line: // oeos-timer-loops-[number of loop]

For example, to loop forever:

// oeos-timer-loops-0

Or to loop 3 times:

// oeos-timer-loops-3

Or to loop by expression:

// oeos-timer-loops-<eval>myGlobalLoopCountFunction()</eval>

⚠️ **GitHub.com Fallback** ⚠️