For transparent work with data on the client side, and more efficient
development of custom scripts, Mukha provides a simple API for
Java Script.
The API works independently of the site's location; for example, data is loaded
both when opening pages over the network and locally (via the file:// protocol). To enable it, you need to:
In the template, as close to the beginning of the HTML as possible, place the tag {{ jsapi }} (if it is not already there)
With the API connected, the window.Mukha object becomes available to scripts. Below is a list of its fields.
Available fields
permalink
Root-relative link to the current page. This link
cannot always be unambiguously derived from the URL, so
it's better to use the API.
relative(
from , to )
Returns a relative link from the page specified by the first parameter
to the page specified by the second.
Parameter
Type
Description
from
string
Root-relative link to the page from which the link should originate
to
string
Link to the page to be referenced.
relTo(
to )
Converts a root-relative site link into a relative one from the current page
Parameter
Type
Description
to
string
Canonical link to the page
getData(
dataset )
Requests a global dataset saved for the JS API by name. Returns
a Promise that resolves with the requested data object.
Parameter
Type
Description
dataset
string
Name of the dataset
getLocalData(
dataset , path )
Requests a local dataset. Returns
a Promise that resolves with the requested data object.
Parameter
Type
Description
dataset
string
Name of the local dataset
path
string
Optional: path to the page. Allows loading a local dataset from a page other than the current one
attachScript(
url )
Attaches a script from the specified URL, returns a Promise that
resolves if the script was successfully loaded.
Parameter
Type
Description
url
string
URL of the script to load.
---
title: Java Script API
excerpt: API for custom scripts
doc: jsapi_en
---
For transparent work with data on the client side, and more efficient
development of custom scripts, Mukha provides a simple API for
Java Script.
---
The API works independently of the site's location; for example, data is loaded
both when opening pages over the network and locally (via the file:// protocol). To enable it, you need to:
- In the template, _as close to the beginning of the HTML as possible_, place the tag {% raw %}`{{ jsapi }}`{% endraw %} (if it is not already there)
- In the [configuration file](/+doc:config_file_en), add the option `js_api: true`
With the API connected, the `window.Mukha` object becomes available to scripts. Below is a list of its fields.
### Available fields
{% for unit in data.datasets.api.jsapi %}
<div class="mb-6">
<strong>
{{ unit.field }}{% if unit.isFunction %}(
{% if unit.params %}
{% for P in unit.params %}
{{ P[0] }}{% if not loop.last %} , {% endif %}
{% endfor %}
{% endif %} )
{% endif %}
</strong>
<div>{{ unit.description_en}} </div>
{% if unit.params %}
<table>
<thead>
<tr>
<td>Parameter</td>
<td>Type</td>
<td>Description</td>
</tr>
</thead>
<tbody>
{% for row in unit.params %}
<tr>
<td><code>{{row[0]}}</code></td>
<td>{{row[1]}}</td>
<td>{{row[3]}}</td>
</tr>
{% endfor %}
</tbody></table>
{% endif %}