Section 4.23 Interactives
TODO: until then examine copious examples in the sample article.
Subsection 4.23.1 GeoGebra Applets and Attached Scripts
A GeoGebra applet is a
<slate> whose @surface is geogebra, inside an <interactive> whose @platform is geogebra. The text of the <slate> may be a list of commands from the GeoGebra Apps API, one per line, such as setCoordSystem(0, 20, 0, 10);. Each command is a method of the applet, written without the applet in front of it, since PreTeXt supplies that. The commands run once the applet has loaded.
An
<interactive> may also attach JavaScript files, listed in its @source attribute, and a script there can connect the applet to the rest of the interactive: a button in another <slate> may change the applet, or a table may change as a reader drags a point. These connections are made by event listeners, which cannot be attached until the applet exists. So once the commands of the <slate> have run, PreTeXt calls a function named listeners, if a script has defined one, and passes it the applet as its only argument. A script that sets the view of the applet when a reader clicks a button would contain the following.
var listeners = function(applet) {
const button = document.getElementById('view-button');
button.addEventListener('click', function() {
applet.setCoordSystem(0, 20, 0, 10);
});
};
The call is made by the same code that runs the commands, so the
<slate> must hold at least one command for listeners to be called. Most interactives have no need of the function and define none. The sample article has a complete example, where a three-dimensional applet communicates with a table and with two buttons.
You have attempted of activities on this page.