// Numbas version: exam_results_page_options {"name": "Keith's copy of Manipulate a GeoGebra applet in JavaScript", "extensions": ["geogebra"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"rulesets": {}, "parts": [], "ungrouped_variables": [], "statement": "

$a = \\var{a}$

\n

$b = \\var{b}$

\n

{applet}

", "extensions": ["geogebra"], "variablesTest": {"maxRuns": 100, "condition": ""}, "preamble": {"js": "// we need a container element to make available to the question right now; the applet will be attached to it once it's loaded\nvar container = document.createElement('div');\ncontainer.className = 'numbas-geogebra-applet numbas-geogebra-loading';\ncontainer.innerHTML = 'GeoGebra applet loading...';\nquestion.scope.setVariable('applet',new Numbas.jme.types.THTML(container));\n\n// request the applet; the 'then' function runs once the applet has been loaded\nNumbas.extensions.geogebra.createGeogebraApplet({material_id: 'UqJChZFJ'}).then(function(d) {\n \n // run some commands to manipulate the worksheet\n var app = d.app;\n app.evalCommand('time_text=Text(\"'+new Date()+'\")');\n app.setCoords('time_text',1,2);\n app.setFixed('time_text',true,false);\n app.setCoords('A',0,2);\n app.setFixed('A',true,true);\n \n var interval = setInterval(function() {\n if(container.parentNode) {\n container.innerHTML = '';\n container.className = 'numbas-geogebra-applet numbas-geogebra-loaded';\n container.appendChild(d.element);\n clearInterval(interval);\n }\n },10);\n});", "css": ""}, "variable_groups": [], "name": "Keith's copy of Manipulate a GeoGebra applet in JavaScript", "tags": [], "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

This question shows how to load a GeoGebra applet in JavaScript, avoiding the JME functions. This allows you to do some more complicated manipulation of the worksheet than simply redefining objects.

"}, "functions": {}, "advice": "", "variables": {}, "type": "question", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Keith Tarnowski", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3425/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}, {"name": "Keith Tarnowski", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/3425/"}]}