Java Script API

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:

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.