Mirador exposes a fairly powerful set of events as its primary API, and it is possible to introspect the state of Mirador with a number of convenience methods to react to changes and export and import data and viewer state. In the following examples, we'll go through some common tasks that can be accomplished programmatically, and answer any questions for improving our documentation. To follow along, simply visit projectMirador.org/demo and open the javascript console. We will work through these examples by manipulating Mirador programmatically in the console.
The projectMirador.org/demo page exposes an instance of Mirador called myMiradorInstance
. All methods, events, and state can be accessed here. Let's start by retrieving different pieces of information about the current viewer state.
The saveController
is the central state manager of Mirador. Though it is not fully implemented, most state of interest can be accessed through it. Type myMiradorInstance.saveController
to access it and explore its API through the developer tools' autocomplete feature.
You can get a complete description of the serialisable configuration of mirador by typing:
myMiradorInstance.saveController.currentConfig
and pressing enter.
Mirador's current windows can be retrieved by id, or from the workspace.
Try:
myMiradorInstance.saveController.currentConfig.windowObjects
This will return an array of currently displayed windows, with their IDs and addresses. You can then obtain the live window instance (In the non-serialised form) using the saveController convenience function.
Mirador's windows are kept in "slots" in the windowing system. By knowing the address of the slot, it is possible to retrieve the window occupying a certain position in the layout.
The manifests currently in the viewer are available by typing myMiradorInstance.saveController.currentConfig.data
. Notice that this is the same as the configuration that was initially passed in to begin with.
Because of the highly asynchronous nature of what Mirador does (requesting, managing, and rendering hundreds of remote resources through multiple layers of linked data), Mirador uses a node.js style eventEmitter. Mirador exposes its event system to the programmer through myMiradorInstance.viewer.eventEmitter
. The eventEmitter
has a .subscribe()
and a .publish()
method, which can be used to receive and fire events. This can be a powerful tool for building software that reacts to Mirador's event stream.