Custom scripts
Use a slipscript code block to add a script, and exec to execute it.
{exec}
```slip-script
// JS script here
```
If a script has a “permanent” side-effect, it has to provide a way for slipshow to revert it. There are two ways for that. One is to use a specific API for side effects, which is the easiest and will accomodate most of the scripts. The other one is more general but slightly more work.
The slip API
The slip API allows to do side effect, while :
slip.up(element, duration, margin)
provides programatic access to the
upaction.
slip.center(element, duration, margin)
provides programatic access to the
centeraction.
slip.down(element, duration, margin)
provides programatic access to the
downaction.
slip.focus(elementList, duration, margin)
provides programatic access to the
focusaction.
slip.unfocus()
provides programatic access to the
unfocusaction.
slip.static(elementList)
provides programatic access to the
staticaction.
slip.unstatic(elementList)
provides programatic access to the
unstaticaction.
slip.reveal(elementList)
provides programatic access to the
revealaction.
slip.unreveal(elementList)
provides programatic access to the
unrevealaction.
slip.emph(elementList)
provides programatic access to the
emphaction.
slip.unemph(elementList)
provides programatic access to the
unemphaction.
slip.playMedia(elementList)
provides programatic access to the
play-mediaaction.
slip.draw(elementList)
provides programatic access to the
drawaction.
slip.changePage(element, page)
provides programatic access to the
change-pageaction, wherepagecan be an absolute or relative number.
slip.setStyle(element, style, value)
allows to set the
styleofelementtovalue.
slip.setClass(element, className, boolean)
allows to add or remove (depending on
boolean) the classclassNameofelement.
slip.setProp(object, propertyName, value)
allows to set the property
propertyNameofobjecttovalue.
slip.onUndo(callback)
does no side-effect, but register
callback()to be run when going backward.
Providing your own undo functions
When the API above is not enough, Slipshow provides a way to define your own
undo functions. They need to be generated when the script runs, and they
will be called when inverting the step.
If you use the slip API, and want to fill a small gap in it, you can use
slip.onUndo defined just above. You can also override any side-effect
registered by the slip API by returning an undo function:
{exec}
```slip-script
let elem = document.querySelector("#id")
let old_value = elem.style.opacity;
elem.style.opacity = "1";
return {undo : () => { elem.style.opacity = old_value }}
```