JavaScript API
The supported tiledash JavaScript API, with signatures and examples.
tiledash.on(event, handler)Runs `handler` with the tile’s `context`, `size`, `theme` or `render`: at once with what is there, then on every change. Returns a function that stops it.
tiledash.call(action, …args)Does an action the widget may do (its Permissions), with the same arguments as in a template’s handler, on the tile’s own device and what its settings picked. Only right after a press inside the tile. Returns a promise that fails with the reason when it is refused.
tiledash.setState(key, value)Sets a value the template reads as `state.<key>`, so the script can switch what the template draws around it.
tiledash.openPopup(id?, look?)Opens one of the widget’s own popups over the page, as a template’s `openPopup` does: the template’s `<hd-popup id="…">` block with that id (`main` without one). The script doesn’t run in the popup; its controls work as the template’s do.
tiledash.closePopup()Closes the popup the widget opened.
tiledash.history(request)Recorded history of a reading the tile is set to, with `history` in its Permissions: the tile’s own device, a device set in a device setting, or a reading picked in a capability, value or readings setting. Resolves to `{ points: [[time, value], …], valueKind, resolution, aggregate, from, to, limitedFrom, unit }`, or `null` when the reading isn’t recorded. Read it once on start, then add the live readings from `context`.
tiledash.storageSmall values kept for this tile on this screen: they survive a reload, not a move to another browser.
tiledash.canActWhether this page may run actions at all; a link that may only look can’t. Hide your buttons when it’s false.
tiledash.rootThe tile as the template draws it, with the widget’s style: find your elements here, not in `document`. An element with `data-script` is yours: the template drawing again leaves it and what you put in it alone. The `hd-*` components that draw from the tile’s values work here, each loaded the first time the tile has one (`customElements.whenDefined` waits for it); `hd-chart` and `hd-history` draw when the widget may read `history`; sparklines, maps, cameras, pictures, floor plans and 3D show an empty box.
tiledash.languageThe viewer’s language, as `nl` or `en`.
tiledash.storage.get(key)A kept value, or `null`.
tiledash.storage.set(key, value)Keeps a value for this tile.
tiledash.storage.remove(key)Forgets a kept value.
tiledash.storage.keys()The keys kept for this tile.