Google Classroom
GeoGebraGeoGebra Classroom

setTimeout() emulation in GeoGebra Classic 5

From version 5.0.545.0 you can try putting the following code in the Global JavaScript to enable setTimeout() and related functions. Then the same code should run in Classic 5 and online. This isn't supported and the behaviour may be different between versions (JavaScript is single-threaded online but Classic 5 is not) but hopefully it's useful to make the workflow a bit easier. /** * Timer for Rhino, original functions from http://stackoverflow.com/questions/2261705/how-to-run-a-javascript-function-asynchronously-without-using-settimeout#answer-5767884 * written by Weston C. * Packaged by Ryan Blunden */ var root = this; // global context if (typeof JavaAdapter != "undefined") { root.timer = new java.util.Timer(); root.counter = 1; root.ids = {}; root.setTimeout = function(fn, delay) { var id = counter++; ids[id] = new JavaAdapter(java.util.TimerTask, { run: fn }); timer.schedule(ids[id], delay); return id; } root.clearTimeout = function(id) { ids[id].cancel(); timer.purge(); delete ids[id]; } root.setInterval = function(fn, delay) { var id = counter++; ids[id] = new JavaAdapter(java.util.TimerTask, { run: fn }); timer.schedule(ids[id], delay, delay); return id; } }