Overview
A <time class="nds-clock"> shows the current time as h:mm AM. The script writes it, and writes it again at each new minute. A page can show any number of clocks. The Top Bar can show one as an item.
The script writes the time only. The icon and the look are yours: the canon uses a Meta line.
Pick another component when:
Markup
Variants
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Clock (default) | — | — | The time alone |
| Structure | With today’s date | canon #clock-with-today |
— | Today’s date, then the time, as the top bar shows them. The date is Date’s data-date-today |
| Calendar | Hijri (default) | — | time[data-date-today] |
The date in Umm al-Qura Hijri. See Date |
| Calendar | Gregorian | [data-calendar="gregory"] |
time[data-date-today] |
Replaces hijri: the Gregorian date, with the month’s name. data-date-era adds nothing to a Gregorian date. See Date |
Built-in Features
-
One Timer
One timer serves every clock on the page, at the turn of each minute. It stops while the tab is hidden, and the clocks catch up when it shows again.
-
Site Timezone
The clock shows the time in the timezone that
data-timezoneon<html>names, or the visitor's time without it. -
No Work When Hidden
A clock that
data-hiddenhides at the current width is not written. When no clock shows, the timer stops.
Best Practices
- Show a clock for a time-bound service: appointments, deadlines, submissions. Leave it out where the time does not matter.
- Set
data-timezoneon<html>when every visitor must see the service’s time, such as Riyadh time for a deadline. - Write the
<time>empty. The script writes the time after the page shows, so the clock is empty until then. - In the top bar, the clock is one of the two items DGA allows.
API
Classes
| Class | Element | Effect |
|---|---|---|
.nds-clock |
<time> |
The clock. The script writes its text, such as 2:05 PM, and its datetime, such as 14:05 |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-timezone |
<html> |
The site’s timezone, as an IANA name such as Asia/Riyadh. See Date |
data-hidden |
The clock, or an element around it | Hides it in the named width bands. See Hidden |
JavaScript
NDS.Clock loads after the page shows. Until it loads, a call to it loads it and returns a promise.
| Method | Effect |
|---|---|
NDS.Clock.init() |
Writes every clock on the page and starts the minute timer. The loader runs it when a clock is on the page, and NDS.init.mount() on markup added later |
The full API is in the banner of _js/nds-clock.js.