// Numbas version: exam_results_page_options {"name": "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": [{"name": "Manipulate a GeoGebra applet in JavaScript", "tags": [], "metadata": {"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.

", "licence": "Creative Commons Attribution 4.0 International"}, "statement": "

Here's an applet which shows the current time and a loaded worksheet, created using the custom time_applet function:

\n

{time_applet()}

\n

Here's a calculator, created using the custom set_perspective function:

\n

{set_perspective(geogebra_applet(600,500),'C')}

", "advice": "", "rulesets": {}, "extensions": ["geogebra"], "variables": {}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": [], "variable_groups": [], "functions": {"time_applet": {"parameters": [], "type": "ggbapplet", "language": "javascript", "definition": "// Create the worksheet. \n// This function returns an object with a container `element` and a `promise` resolving to a GeoGebra applet.\nvar result = Numbas.extensions.geogebra.createGeogebraApplet({material_id: 'UqJChZFJ'});\n\n// Once the applet has loaded, run some commands to manipulate the worksheet.\nresult.promise.then(function(d) {\n var app = d.app;\n \n function set_time() {\n app.evalCommand('time_text=Text(\"'+new Date()+'\")');\n }\n setInterval(set_time,500);\n set_time();\n app.setCoords('time_text',1,2);\n app.setFixed('time_text',true,false);\n \n app.setCoords('A',0,2);\n app.setFixed('A',true,true);\n});\n\n// This function returns the result of `createGeogebraApplet` as an object with the JME data type 'ggbapplet', which can be substituted into the question's content.\nreturn new Numbas.jme.types.ggbapplet(result);"}, "set_perspective": {"parameters": [["app", "ggbapplet"], ["perspective", "string"]], "type": "ggbapplet", "language": "javascript", "definition": "// Take an applet, set its perspective to the given string.\n// See https://wiki.geogebra.org/en/SetPerspective_Command for the format of the perspective string.\napp.promise.then(function(d) {\n d.app.setPerspective(perspective);\n});\nreturn new Numbas.jme.types.ggbapplet(app);"}}, "preamble": {"js": "", "css": ""}, "parts": [], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}