diff --git a/amd/build/ggbq.min.js b/amd/build/ggbq.min.js index c28d81b..6e1d053 100644 --- a/amd/build/ggbq.min.js +++ b/amd/build/ggbq.min.js @@ -9,6 +9,6 @@ * @copyright (c) International GeoGebra Institute 2018 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("qtype_geogebra/ggbq",["jquery","https://www.geogebra.org/apps/deployggb.js"],(function($,GGBApplet){const scalingContainers={};let resizeTimeout;const resizeScalingContainer=()=>{clearTimeout(resizeTimeout),resizeTimeout=setTimeout((()=>Object.values(scalingContainers).forEach((containerClass=>{const scalingContainer=document.getElementsByClassName(containerClass)[0],formulationDivStyle=window.getComputedStyle(scalingContainer.querySelector(".qtext").parentElement.parentElement);scalingContainer.style.width=parseInt(formulationDivStyle.width)-parseInt(formulationDivStyle.paddingLeft)-parseInt(formulationDivStyle.paddingRight)+"px"}))),250)};return{b64input:[],ggbBase64:[],currentvals:[],answerinput:[],responsevars:[],qdiv:[],ggbDataset:[],init:function(appletParametersID){window.GGBQ=this;var ggbDataset=document.getElementById(appletParametersID).dataset,slot=ggbDataset.slot;scalingContainers[slot]=ggbDataset.scalingcontainerclass,window.ggbAppletOnLoad=function(ggbAppletId){if(-1!=ggbAppletId){document.querySelector("article").onkeydown=this.checkEnter;var id=ggbAppletId.substring(9),ggbApplet=window[ggbAppletId],curvals=JSON.parse(window.GGBQ.currentvals[id]);for(var label in curvals)ggbApplet.setValue(label,curvals[label]);if(resizeScalingContainer(),window.removeEventListener("resize",resizeScalingContainer),window.addEventListener("resize",resizeScalingContainer),window.GGBQ.b64input[id].val(ggbApplet.getBase64()),window.GGBQ.qdiv[id].style.visibility="visible",""==window.GGBQ.answerinput[id].val()){var responsestring="";window.GGBQ.responsevars[id].forEach((function(responsevar){ggbApplet.isDefined(responsevar)?responsestring+=ggbApplet.getValue(responsevar):responsestring+=0})),window.GGBQ.answerinput[id].val(responsestring)}}},this.b64input[slot]=$(document.getElementById(ggbDataset.b64input)),this.ggbBase64[slot]=this.b64input[slot].val(),this.qdiv[slot]=$("#q"+slot+" .qtext")[0];var parameters=JSON.parse(ggbDataset.parameters);if(""!=this.ggbBase64[slot]&&(parameters.ggbBase64=this.ggbBase64[slot]),ggbDataset.forcedimensions&&"0"!==ggbDataset.forcedimensions){parameters.width=ggbDataset.width,parameters.height=ggbDataset.height;const scalingContainer=document.getElementsByClassName(scalingContainers[slot])[0];scalingContainer&&(scalingContainer.style.overflowX="auto",scalingContainer.style.overflowY="hidden")}else parameters.scaleContainerClass=scalingContainers[slot],parameters.autoHeight=!0;this.ggbDatasetVars=JSON.parse(ggbDataset.vars),parameters.language=ggbDataset.lang,parameters.moodle="takingQuiz",delete parameters.material_id,parameters.id="ggbApplet"+slot;var views=JSON.parse(ggbDataset.views);new GGBApplet(parameters,views,ggbDataset.html5NoWebSimple).inject(ggbDataset.div,"preferHTML5"),$("#responseform").on("submit",this.getBase64andCheck),$(document.getElementById(ggbDataset.div)).on("mouseleave",this.getBase64andCheck),this.currentvals[slot]=ggbDataset.vars,this.answerinput[slot]=$(document.getElementById(ggbDataset.answerinput)),this.responsevars[slot]=JSON.parse(ggbDataset.responsevars)},checkEnter:function(e){return e=e||event,/textarea/i.test((e.target||e.srcElement).tagName)||13!==(e.keyCode||e.which||e.charCode||0)},getBase64andCheck:function(){for(var i=0;i{clearTimeout(resizeTimeout),resizeTimeout=setTimeout((()=>Object.values(scalingContainers).forEach((containerClass=>{const scalingContainer=document.getElementsByClassName(containerClass)[0],formulationDivStyle=window.getComputedStyle(scalingContainer.querySelector(".qtext").parentElement.parentElement);scalingContainer.style.width=parseInt(formulationDivStyle.width)-parseInt(formulationDivStyle.paddingLeft)-parseInt(formulationDivStyle.paddingRight)+"px"}))),250)};return{b64input:[],ggbBase64:[],xmlinput:[],ggbxml:[],currentvals:[],answerinput:[],responsevars:[],qdiv:[],ggbDataset:[],init:function(appletParametersID){window.GGBQ=this;var ggbDataset=document.getElementById(appletParametersID).dataset,slot=ggbDataset.slot;scalingContainers[slot]=ggbDataset.scalingcontainerclass,window.ggbAppletOnLoad=function(ggbAppletId){if(-1!=ggbAppletId){document.querySelector("article").onkeydown=this.checkEnter;var id=ggbAppletId.substring(9),ggbApplet=window[ggbAppletId],curvals=JSON.parse(window.GGBQ.currentvals[id]);for(var label in curvals)ggbApplet.setValue(label,curvals[label]);if(resizeScalingContainer(),window.removeEventListener("resize",resizeScalingContainer),window.addEventListener("resize",resizeScalingContainer),window.GGBQ.b64input[id].val(ggbApplet.getBase64()),window.GGBQ.xmlinput[id].val(ggbApplet.getXML()),window.GGBQ.qdiv[id].style.visibility="visible",""==window.GGBQ.answerinput[id].val()){var responsestring="";window.GGBQ.responsevars[id].forEach((function(responsevar){ggbApplet.isDefined(responsevar)?responsestring+=ggbApplet.getValue(responsevar):responsestring+=0})),window.GGBQ.answerinput[id].val(responsestring)}}},this.b64input[slot]=$(document.getElementById(ggbDataset.b64input)),this.ggbBase64[slot]=this.b64input[slot].val(),this.xmlinput[slot]=$(document.getElementById(ggbDataset.xmlinput)),this.ggbxml[slot]=this.xmlinput[slot].val(),this.qdiv[slot]=$("#q"+slot+" .qtext")[0];var parameters=JSON.parse(ggbDataset.parameters);if(""!=this.ggbBase64[slot]&&(parameters.ggbBase64=this.ggbBase64[slot]),ggbDataset.forcedimensions&&"0"!==ggbDataset.forcedimensions){parameters.width=ggbDataset.width,parameters.height=ggbDataset.height;const scalingContainer=document.getElementsByClassName(scalingContainers[slot])[0];scalingContainer&&(scalingContainer.style.overflowX="auto",scalingContainer.style.overflowY="hidden")}else parameters.scaleContainerClass=scalingContainers[slot],parameters.autoHeight=!0;this.ggbDatasetVars=JSON.parse(ggbDataset.vars),parameters.language=ggbDataset.lang,parameters.moodle="takingQuiz",delete parameters.material_id,parameters.id="ggbApplet"+slot;var views=JSON.parse(ggbDataset.views);new GGBApplet(parameters,views,ggbDataset.html5NoWebSimple).inject(ggbDataset.div,"preferHTML5"),$("#responseform").on("submit",this.getBase64andCheck),$(document.getElementById(ggbDataset.div)).on("mouseleave",this.getBase64andCheck),this.currentvals[slot]=ggbDataset.vars,this.answerinput[slot]=$(document.getElementById(ggbDataset.answerinput)),this.responsevars[slot]=JSON.parse(ggbDataset.responsevars)},checkEnter:function(e){return e=e||event,/textarea/i.test((e.target||e.srcElement).tagName)||13!==(e.keyCode||e.which||e.charCode||0)},getBase64andCheck:function(){for(var i=0;i\n * @copyright (c) International GeoGebra Institute 2018\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GGBApplet) {\n /**\n * Created by Christoph on 25.08.19.\n */\n\n const scalingContainers = {};\n let resizeTimeout;\n /**\n * Resizes the ggb scaling containers to make the ggb applet scale properly to fit into its container.\n */\n const resizeScalingContainer = () => {\n clearTimeout(resizeTimeout);\n resizeTimeout = setTimeout(\n () => Object.values(scalingContainers).forEach((containerClass) => {\n // We need to use getElementsByClassName because colons are not allowed for jquery and Vanilla JS querySelector.\n const scalingContainer = document.getElementsByClassName(containerClass)[0];\n // We retrieve the formulation div container, because this gives us the correct width to adapt\n // the scaling container to.\n const formulationDivStyle = window.getComputedStyle(\n scalingContainer.querySelector('.qtext').parentElement.parentElement);\n scalingContainer.style.width = parseInt(formulationDivStyle.width)\n - parseInt(formulationDivStyle.paddingLeft) - parseInt(formulationDivStyle.paddingRight) + 'px';\n }), 250);\n };\n\n return {\n b64input: [],\n ggbBase64: [],\n currentvals: [],\n answerinput: [],\n responsevars: [],\n qdiv: [],\n //parameters: {},\n ggbDataset: [],\n //applet1,\n\n init: function (appletParametersID) {\n window.GGBQ = this;\n var ggbDataset = document.getElementById(appletParametersID).dataset;\n var slot = ggbDataset.slot;\n // Add current scaling container to the object store for being able to access it later on.\n scalingContainers[slot] = ggbDataset.scalingcontainerclass;\n\n window.ggbAppletOnLoad = function (ggbAppletId) {\n if (ggbAppletId != -1) {\n document.querySelector('article').onkeydown = this.checkEnter;\n var id = ggbAppletId.substring(9);\n var ggbApplet = window[ggbAppletId];\n var curvals = JSON.parse(window.GGBQ.currentvals[id]);\n for (var label in curvals) {\n ggbApplet.setValue(label, curvals[label]);\n }\n\n // Set the initial size of the scaling containers so GeoGebra applet scale a first time correctly after loading.\n resizeScalingContainer();\n // Unregister old event listeners in case we have multiple GeoGebra questions on one page.\n // We only need one for the whole page.\n window.removeEventListener('resize', resizeScalingContainer);\n window.addEventListener('resize', resizeScalingContainer);\n\n window.GGBQ.b64input[id].val(ggbApplet.getBase64());\n\n window.GGBQ.qdiv[id].style.visibility = 'visible';\n if (window.GGBQ.answerinput[id].val() == '') {\n var responsestring = '';\n window.GGBQ.responsevars[id].forEach(function (responsevar) {\n if (ggbApplet.isDefined(responsevar)) {\n responsestring += ggbApplet.getValue(responsevar);\n } else {\n responsestring += 0;\n }\n });\n window.GGBQ.answerinput[id].val(responsestring);\n }\n }\n };\n\n // jquery doesn't handle the colon : but later we expect a jquery optject, so ...\n this.b64input[slot] = $(document.getElementById(ggbDataset.b64input));\n this.ggbBase64[slot] = this.b64input[slot].val();\n\n this.qdiv[slot] = $(\"#q\" + (slot) + \" .qtext\")[0];\n\n var parameters = JSON.parse(ggbDataset.parameters);\n if (this.ggbBase64[slot] != '') {\n parameters.ggbBase64 = this.ggbBase64[slot];\n }\n\n // Check if width and height have been manually set. The default would be \"no\", so we use the scaling container feature.\n if (!ggbDataset.forcedimensions || ggbDataset.forcedimensions === '0') {\n parameters.scaleContainerClass = scalingContainers[slot];\n parameters.autoHeight = true;\n } else {\n // Width and height are specified in this case, so we use the given fixed width and height settings\n // of the plugin instance. Form validation of the settings asserts that both width and height are being set.\n parameters.width = ggbDataset.width;\n parameters.height = ggbDataset.height;\n // We need to use getElementsByClassName because colons are not allowed for jquery and Vanilla JS querySelector.\n const scalingContainer = document.getElementsByClassName(scalingContainers[slot])[0];\n // We should always find this container, just check to be extra safe.\n if (scalingContainer) {\n // Width of the scaling container is being set after the applet has been loaded. So no need to specify it here.\n scalingContainer.style.overflowX = 'auto';\n scalingContainer.style.overflowY = 'hidden';\n }\n }\n\n // parameters.currentvals = JSON.parse(ggbDataset.vars);\n this.ggbDatasetVars = JSON.parse(ggbDataset.vars);\n parameters.language = ggbDataset.lang;\n parameters.moodle = \"takingQuiz\";\n delete parameters.material_id;\n\n parameters.id = 'ggbApplet' + slot;\n\n var views = JSON.parse(ggbDataset.views);\n\n var applet1 = new GGBApplet(parameters, views, ggbDataset.html5NoWebSimple);\n // applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n applet1.inject(ggbDataset.div, \"preferHTML5\");\n\n $('#responseform').on('submit', this.getBase64andCheck);\n\n $(document.getElementById(ggbDataset.div)).on('mouseleave', this.getBase64andCheck);\n\n this.currentvals[slot] = ggbDataset.vars;\n this.answerinput[slot] = $(document.getElementById(ggbDataset.answerinput));\n this.responsevars[slot] = JSON.parse(ggbDataset.responsevars);\n },\n checkEnter: function(e) {\n e = e || event;\n var txtArea = /textarea/i.test((e.target || e.srcElement).tagName);\n return txtArea || (e.keyCode || e.which || e.charCode || 0) !== 13;\n },\n\n\n getBase64andCheck: function() {\n for (var i = 0; i < window.GGBQ.answerinput.length; i++) {\n var ggbApplet = window['ggbApplet' + i];\n if (typeof ggbApplet !== \"undefined\") {\n window.GGBQ.b64input[i].val(ggbApplet.getBase64());\n\n // Workaround, to set all randomized variables.\n for (const [key, value] of Object.entries(window.GGBQ.ggbDatasetVars)) {\n ggbApplet.evalCommand(`${key}=${value}`);\n }\n\n var responsestring = '';\n for (var j = 0; j < window.GGBQ.responsevars[i].length; j++) {\n if (ggbApplet.isDefined(window.GGBQ.responsevars[i][j])) {\n responsestring += ggbApplet.getValue(window.GGBQ.responsevars[i][j]);\n } else {\n responsestring += 0;\n }\n }\n\n window.GGBQ.answerinput[i].val(responsestring);\n }\n }\n },\n };\n});\n"],"names":["define","$","GGBApplet","scalingContainers","resizeTimeout","resizeScalingContainer","clearTimeout","setTimeout","Object","values","forEach","containerClass","scalingContainer","document","getElementsByClassName","formulationDivStyle","window","getComputedStyle","querySelector","parentElement","style","width","parseInt","paddingLeft","paddingRight","b64input","ggbBase64","currentvals","answerinput","responsevars","qdiv","ggbDataset","init","appletParametersID","GGBQ","this","getElementById","dataset","slot","scalingcontainerclass","ggbAppletOnLoad","ggbAppletId","onkeydown","checkEnter","id","substring","ggbApplet","curvals","JSON","parse","label","setValue","removeEventListener","addEventListener","val","getBase64","visibility","responsestring","responsevar","isDefined","getValue","parameters","forcedimensions","height","overflowX","overflowY","scaleContainerClass","autoHeight","ggbDatasetVars","vars","language","lang","moodle","material_id","views","html5NoWebSimple","inject","div","on","getBase64andCheck","e","event","test","target","srcElement","tagName","keyCode","which","charCode","i","length","key","value","entries","evalCommand","j"],"mappings":";;;;;;;;;;;AAWAA,6BAAO,CAAC,SAAU,+CAA+C,SAAUC,EAAGC,iBAKpEC,kBAAoB,OACtBC,oBAIEC,uBAAyB,KAC3BC,aAAaF,eACbA,cAAgBG,YACZ,IAAMC,OAAOC,OAAON,mBAAmBO,SAASC,uBAElCC,iBAAmBC,SAASC,uBAAuBH,gBAAgB,GAGnEI,oBAAsBC,OAAOC,iBAC/BL,iBAAiBM,cAAc,UAAUC,cAAcA,eAC3DP,iBAAiBQ,MAAMC,MAAQC,SAASP,oBAAoBM,OACtDC,SAASP,oBAAoBQ,aAAeD,SAASP,oBAAoBS,cAAgB,SAC/F,YAGT,CACHC,SAAU,GACVC,UAAW,GACXC,YAAa,GACbC,YAAa,GACbC,aAAc,GACdC,KAAM,GAENC,WAAY,GAGZC,KAAM,SAAUC,oBACZjB,OAAOkB,KAAOC,SACVJ,WAAalB,SAASuB,eAAeH,oBAAoBI,QACzDC,KAAOP,WAAWO,KAEtBnC,kBAAkBmC,MAAQP,WAAWQ,sBAErCvB,OAAOwB,gBAAkB,SAAUC,iBACX,GAAhBA,YAAmB,CACnB5B,SAASK,cAAc,WAAWwB,UAAYP,KAAKQ,eAC/CC,GAAKH,YAAYI,UAAU,GAC3BC,UAA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AAK,YAAcN,SAE1BoC,MAAQ1B,KAAKC,MAAMlB,WAAW2C,OAEpB,IAAIxE,UAAU2D,WAAYa,MAAO3C,WAAW4C,kBAElDC,OAAO7C,WAAW8C,IAAK,eAE/B5E,EAAE,iBAAiB6E,GAAG,SAAU3C,KAAK4C,mBAErC9E,EAAEY,SAASuB,eAAeL,WAAW8C,MAAMC,GAAG,aAAc3C,KAAK4C,wBAE5DpD,YAAYW,MAAQP,WAAWsC,UAC/BzC,YAAYU,MAAQrC,EAAEY,SAASuB,eAAeL,WAAWH,mBACzDC,aAAaS,MAAQU,KAAKC,MAAMlB,WAAWF,eAEpDc,WAAY,SAASqC,UACjBA,EAAIA,GAAKC,MACK,YAAYC,MAAMF,EAAEG,QAAUH,EAAEI,YAAYC,UACM,MAA7CL,EAAEM,SAAWN,EAAEO,OAASP,EAAEQ,UAAY,IAI7DT,kBAAmB,eACV,IAAIU,EAAI,EAAGA,EAAIzE,OAAOkB,KAAKN,YAAY8D,OAAQD,IAAK,KACjD3C,UAAY9B,OAAO,YAAcyE,WACZ,IAAd3C,UAA2B,CAClC9B,OAAOkB,KAAKT,SAASgE,GAAGnC,IAAIR,UAAUS,iBAGjC,MAAOoC,IAAKC,SAAUpF,OAAOqF,QAAQ7E,OAAOkB,KAAKkC,gBAClDtB,UAAUgD,sBAAeH,gBAAOC,gBAGhCnC,eAAiB,GACZsC,EAAI,EAAGA,EAAI/E,OAAOkB,KAAKL,aAAa4D,GAAGC,OAAQK,IAChDjD,UAAUa,UAAU3C,OAAOkB,KAAKL,aAAa4D,GAAGM,IAChDtC,gBAAkBX,UAAUc,SAAS5C,OAAOkB,KAAKL,aAAa4D,GAAGM,IAEjEtC,gBAAkB,EAI1BzC,OAAOkB,KAAKN,YAAY6D,GAAGnC,IAAIG"} \ No newline at end of file +{"version":3,"file":"ggbq.min.js","sources":["../src/ggbq.js"],"sourcesContent":["/**\n * Javascript Controller to embed GGBApplet\n *\n * STUDENT VIEW\n *\n * This class provides all the functionality for the new assign module.\n *\n * @author Christoph Stadlbauer \n * @copyright (c) International GeoGebra Institute 2018\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GGBApplet) {\n /**\n * Created by Christoph on 25.08.19.\n */\n\n const scalingContainers = {};\n let resizeTimeout;\n /**\n * Resizes the ggb scaling containers to make the ggb applet scale properly to fit into its container.\n */\n const resizeScalingContainer = () => {\n clearTimeout(resizeTimeout);\n resizeTimeout = setTimeout(\n () => Object.values(scalingContainers).forEach((containerClass) => {\n // We need to use getElementsByClassName because colons are not allowed for jquery and Vanilla JS querySelector.\n const scalingContainer = document.getElementsByClassName(containerClass)[0];\n // We retrieve the formulation div container, because this gives us the correct width to adapt\n // the scaling container to.\n const formulationDivStyle = window.getComputedStyle(\n scalingContainer.querySelector('.qtext').parentElement.parentElement);\n scalingContainer.style.width = parseInt(formulationDivStyle.width)\n - parseInt(formulationDivStyle.paddingLeft) - parseInt(formulationDivStyle.paddingRight) + 'px';\n }), 250);\n };\n\n return {\n b64input: [],\n ggbBase64: [],\n xmlinput: [],\n ggbxml: [],\n currentvals: [],\n answerinput: [],\n responsevars: [],\n qdiv: [],\n //parameters: {},\n ggbDataset: [],\n //applet1,\n\n init: function (appletParametersID) {\n window.GGBQ = this;\n var ggbDataset = document.getElementById(appletParametersID).dataset;\n var slot = ggbDataset.slot;\n // Add current scaling container to the object store for being able to access it later on.\n scalingContainers[slot] = ggbDataset.scalingcontainerclass;\n\n window.ggbAppletOnLoad = function (ggbAppletId) {\n if (ggbAppletId != -1) {\n document.querySelector('article').onkeydown = this.checkEnter;\n var id = ggbAppletId.substring(9);\n var ggbApplet = window[ggbAppletId];\n var curvals = JSON.parse(window.GGBQ.currentvals[id]);\n for (var label in curvals) {\n ggbApplet.setValue(label, curvals[label]);\n }\n\n // Set the initial size of the scaling containers so GeoGebra applet scale a first time correctly after loading.\n resizeScalingContainer();\n // Unregister old event listeners in case we have multiple GeoGebra questions on one page.\n // We only need one for the whole page.\n window.removeEventListener('resize', resizeScalingContainer);\n window.addEventListener('resize', resizeScalingContainer);\n\n window.GGBQ.b64input[id].val(ggbApplet.getBase64());\n window.GGBQ.xmlinput[id].val(ggbApplet.getXML());\n\n window.GGBQ.qdiv[id].style.visibility = 'visible';\n if (window.GGBQ.answerinput[id].val() == '') {\n var responsestring = '';\n window.GGBQ.responsevars[id].forEach(function (responsevar) {\n if (ggbApplet.isDefined(responsevar)) {\n responsestring += ggbApplet.getValue(responsevar);\n } else {\n responsestring += 0;\n }\n });\n window.GGBQ.answerinput[id].val(responsestring);\n }\n }\n };\n\n // jquery doesn't handle the colon : but later we expect a jquery optject, so ...\n this.b64input[slot] = $(document.getElementById(ggbDataset.b64input));\n this.ggbBase64[slot] = this.b64input[slot].val();\n\n this.xmlinput[slot] = $(document.getElementById(ggbDataset.xmlinput));\n this.ggbxml[slot] = this.xmlinput[slot].val();\n this.qdiv[slot] = $(\"#q\" + (slot) + \" .qtext\")[0];\n\n var parameters = JSON.parse(ggbDataset.parameters);\n if (this.ggbBase64[slot] != '') {\n parameters.ggbBase64 = this.ggbBase64[slot];\n }\n\n // Check if width and height have been manually set. The default would be \"no\", so we use the scaling container feature.\n if (!ggbDataset.forcedimensions || ggbDataset.forcedimensions === '0') {\n parameters.scaleContainerClass = scalingContainers[slot];\n parameters.autoHeight = true;\n } else {\n // Width and height are specified in this case, so we use the given fixed width and height settings\n // of the plugin instance. Form validation of the settings asserts that both width and height are being set.\n parameters.width = ggbDataset.width;\n parameters.height = ggbDataset.height;\n // We need to use getElementsByClassName because colons are not allowed for jquery and Vanilla JS querySelector.\n const scalingContainer = document.getElementsByClassName(scalingContainers[slot])[0];\n // We should always find this container, just check to be extra safe.\n if (scalingContainer) {\n // Width of the scaling container is being set after the applet has been loaded. So no need to specify it here.\n scalingContainer.style.overflowX = 'auto';\n scalingContainer.style.overflowY = 'hidden';\n }\n }\n\n // parameters.currentvals = JSON.parse(ggbDataset.vars);\n this.ggbDatasetVars = JSON.parse(ggbDataset.vars);\n parameters.language = ggbDataset.lang;\n parameters.moodle = \"takingQuiz\";\n delete parameters.material_id;\n\n parameters.id = 'ggbApplet' + slot;\n\n var views = JSON.parse(ggbDataset.views);\n\n var applet1 = new GGBApplet(parameters, views, ggbDataset.html5NoWebSimple);\n // applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n applet1.inject(ggbDataset.div, \"preferHTML5\");\n\n $('#responseform').on('submit', this.getBase64andCheck);\n\n $(document.getElementById(ggbDataset.div)).on('mouseleave', this.getBase64andCheck);\n\n this.currentvals[slot] = ggbDataset.vars;\n this.answerinput[slot] = $(document.getElementById(ggbDataset.answerinput));\n this.responsevars[slot] = JSON.parse(ggbDataset.responsevars);\n },\n checkEnter: function(e) {\n e = e || event;\n var txtArea = /textarea/i.test((e.target || e.srcElement).tagName);\n return txtArea || (e.keyCode || e.which || e.charCode || 0) !== 13;\n },\n\n\n getBase64andCheck: function() {\n for (var i = 0; i < window.GGBQ.answerinput.length; i++) {\n var ggbApplet = window['ggbApplet' + i];\n if (typeof ggbApplet !== \"undefined\") {\n window.GGBQ.b64input[i].val(ggbApplet.getBase64());\n window.GGBQ.xmlinput[i].val(ggbApplet.getXML());\n\n // Workaround, to set all randomized variables.\n for (const [key, value] of Object.entries(window.GGBQ.ggbDatasetVars)) {\n ggbApplet.evalCommand(`${key}=${value}`);\n }\n\n var responsestring = '';\n for (var j = 0; j < window.GGBQ.responsevars[i].length; j++) {\n if (ggbApplet.isDefined(window.GGBQ.responsevars[i][j])) {\n responsestring += ggbApplet.getValue(window.GGBQ.responsevars[i][j]);\n } else {\n responsestring += 0;\n }\n }\n\n window.GGBQ.answerinput[i].val(responsestring);\n }\n }\n },\n };\n});\n"],"names":["define","$","GGBApplet","scalingContainers","resizeTimeout","resizeScalingContainer","clearTimeout","setTimeout","Object","values","forEach","containerClass","scalingContainer","document","getElementsByClassName","formulationDivStyle","window","getComputedStyle","querySelector","parentElement","style","width","parseInt","paddingLeft","paddingRight","b64input","ggbBase64","xmlinput","ggbxml","currentvals","answerinput","responsevars","qdiv","ggbDataset","init","appletParametersID","GGBQ","this","getElementById","dataset","slot","scalingcontainerclass","ggbAppletOnLoad","ggbAppletId","onkeydown","checkEnter","id","substring","ggbApplet","curvals","JSON","parse","label","setValue","removeEventListener","addEventListener","val","getBase64","getXML","visibility","responsestring","responsevar","isDefined","getValue","parameters","forcedimensions","height","overflowX","overflowY","scaleContainerClass","autoHeight","ggbDatasetVars","vars","language","lang","moodle","material_id","views","html5NoWebSimple","inject","div","on","getBase64andCheck","e","event","test","target","srcElement","tagName","keyCode","which","charCode","i","length","key","value","entries","evalCommand","j"],"mappings":";;;;;;;;;;;AAWAA,6BAAO,CAAC,SAAU,+CAA+C,SAAUC,EAAGC,iBAKpEC,kBAAoB,OACtBC,oBAIEC,uBAAyB,KAC3BC,aAAaF,eACbA,cAAgBG,YACZ,IAAMC,OAAOC,OAAON,mBAAmBO,SAASC,uBAElCC,iBAAmBC,SAASC,uBAAuBH,gBAAgB,GAGnEI,oBAAsBC,OAAOC,iBAC/BL,iBAAiBM,cAAc,UAAUC,cAAcA,eAC3DP,iBAAiBQ,MAAMC,MAAQC,SAASP,oBAAoBM,OACtDC,SAASP,oBAAoBQ,aAAeD,SAASP,oBAAoBS,cAAgB,SAC/F,YAGT,CACHC,SAAU,GACVC,UAAW,GACXC,SAAU,GACVC,OAAQ,GACRC,YAAa,GACbC,YAAa,GACbC,aAAc,GACdC,KAAM,GAENC,WAAY,GAGZC,KAAM,SAAUC,oBACZnB,OAAOoB,KAAOC,SACVJ,WAAapB,SAASyB,eAAeH,oBAAoBI,QACzDC,KAAOP,WAAWO,KAEtBrC,kBAAkBqC,MAAQP,WAAWQ,sBAErCzB,OAAO0B,gBAAkB,SAAUC,iBACX,GAAhBA,YAAmB,CACnB9B,SAASK,cAAc,WAAW0B,UAAYP,KAAKQ,eAC/CC,GAAKH,YAAYI,UAA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KAAKL,aAAa6D,GAAGM,IAEjEtC,gBAAkB,EAI1B5C,OAAOoB,KAAKN,YAAY8D,GAAGpC,IAAII"} \ No newline at end of file diff --git a/amd/build/ggbt.min.js b/amd/build/ggbt.min.js index 42abb44..8d30b68 100644 --- a/amd/build/ggbt.min.js +++ b/amd/build/ggbt.min.js @@ -7,6 +7,6 @@ * @copyright (c) International GeoGebra Institute 2018 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("qtype_geogebra/ggbt",["jquery","https://www.geogebra.org/apps/deployggb.js"],(function($,GGBApplet){return{init:function(){window.GGBT=this,window.ggbAppletOnLoad=function(){if($('input[name="ggbparameters"]').val(JSON.stringify(window.applet1.getParameters())),$('input[name="ggbviews"]').val(JSON.stringify(window.applet1.getViews())),$('input[name="ggbcodebaseversion"]').val(window.applet1.getHTML5CodebaseVersion()),void 0===this.ggbcheckb){document.getElementById("id_randomizedvar").value||window.GGBT.getrandvars();for(var i=0,answer=$("#id_answer_"+i);void 0!==answer[0];)answer.val()&&(answer.on("change focus",(function(e){e.preventDefault(),window.GGBT.update_feedback($(e.target))})),window.GGBT.update_feedback(answer)),answer=$("#id_answer_"+ ++i);document.querySelector("article").onkeypress=window.GGBT.checkEnter}window.GGBT.usefile.checked&&(document.getElementById("applet_container1").style.display="block",document.getElementById("applet_options").style.display="flex")},void 0!==$("#applet_parameters")[0]&&(this.ggbDataset=$("#applet_parameters")[0].dataset,this.parameters=JSON.parse(this.ggbDataset.parameters),this.views=this.ggbDataset.views,window.applet1=new GGBApplet(this.parameters,this.views,!0),this.lang=this.ggbDataset.lang),$("#id_loadapplet").on("click",(function(e){e.preventDefault();var id=$("#id_ggbturl").val().split("/").pop();0==id.indexOf("m")&&(window.GGBT.isNumber(id.substr(1))||!window.GGBT.isNumber(id.substr(1))&&id.length>8)&&(id=id.substr(1)),window.GGBT.injectapplet(id)})),$("#id_getvars").on("click",(function(e){e.preventDefault(),window.GGBT.getrandvars()})),this.parameters&&window.applet1.inject("applet_container1","preferHTML5"),this.ggbf=document.getElementById("id_ggbtheader"),this.usefile=document.getElementById("id_usefile"),null===this.ggbf&&(this.ggbf=document.getElementById("id_submissiontypes"),this.ggbcheckb=document.getElementById("id_assignsubmission_geogebra_enabled"),null!==this.ggbcheckb&&this.ggbcheckb.addEventListener("change",this.handleggbdisable,!1)),null!==this.ggbf&&(this.ggbf.addEventListener("dragenter",this.handleDragEnter,!1),this.ggbf.addEventListener("dragover",this.handleDragOver,!1),this.ggbf.addEventListener("dragleave",this.handleDragEndLeave,!1),this.ggbf.addEventListener("dragend",this.handleDragEndLeave,!1),this.ggbf.addEventListener("drop",this.handleDrop,!1),this.usefile.addEventListener("change",this.handleusefile,!1)),this.usefile.checked?document.getElementById("applet_options").style.display="block":document.getElementById("applet_options").style.display="none",this.initoptions()},callback:function(params){var elementname=M.core_filepicker.instances[params.client_id].options.elementname;$("#id_"+elementname).val(params.url);var id=params.file.split(".")[0];0==id.indexOf("m")&&(this.isNumber(id.substr(1))||!this.isNumber(id.substr(1))&&id.length>8)&&(id=id.substr(1)),this.injectapplet(id)},injectapplet:function(id){this.parameters={material_id:id},this.parameters.language=this.lang,this.parameters.moodle="editingQuestionOrSubmission",this.parameters.useBrowserForJS=!1,document.getElementById("applet_container1").style.display="block",window.applet1=new GGBApplet(this.parameters,!0),window.applet1.inject("applet_container1","preferHTML5")},getrandvars:function(){var applet=document.ggbApplet;if(void 0!==applet)for(var objNumber=applet.getObjectNumber(),randomizedvar=document.getElementById("id_randomizedvar"),stringforrandomizedvars="",i=0,j=0;j0&&(answer.val()||answer.val(strName),this.update_feedback(answer),i++)}randomizedvar.value=stringforrandomizedvars}},update_feedback:function(answernode){var id=answernode.attr("id").split("_").pop(),varname=answernode.val();if(!varname)return;var feedback=$('input[name="feedback['+id+']"]'),feedbackfromfile=$("#id_feedbackfromfile_"+id);const parser=new DOMParser,xml=window.ggbApplet.getXML(varname);if(!xml)return;const doc=parser.parseFromString(xml,"text/xml");if(doc){var elem=doc.getElementsByTagName("caption"),fbstring="";1==elem.length?(fbstring=elem[0].getAttribute("val"),feedback.val(fbstring)):elem.length>1?(feedback.val(""),fbstring=""):(feedback.val(""),fbstring="Caption not set or variable name wrong."),feedbackfromfile.val(fbstring)}},checkEnter:function(e){return e=e||event,/textarea/i.test((e.target||e.srcElement).tagName)||13!==(e.keyCode||e.which||e.charCode||0)},initoptions:function(){this.enable_right_click=document.getElementById("enableRightClick"),this.enable_label_drags=document.getElementById("enableLabelDrags"),this.show_reset_icon=document.getElementById("showResetIcon"),this.enable_shift_drag_zoom=document.getElementById("enableShiftDragZoom"),this.show_algebra_input=document.getElementById("showAlgebraInput"),this.show_menu_bar=document.getElementById("showMenuBar"),this.show_tool_bar=document.getElementById("showToolBar"),"undefined"!=typeof parameters&&(this.enable_right_click.checked=this.parameters.enableRightClick,this.enable_label_drags.checked=this.parameters.enableLabelDrags,this.show_reset_icon.checked=this.parameters.showResetIcon,this.enable_shift_drag_zoom.checked=this.parameters.enableShiftDragZoom,this.show_algebra_input.checked=this.parameters.showAlgebraInput,this.show_menu_bar.checked=this.parameters.showMenuBar,this.show_tool_bar.checked=this.parameters.showToolBar),this.enable_right_click.addEventListener("change",this.handlesettingschanged,!1),this.enable_label_drags.addEventListener("change",this.handlesettingschanged,!1),this.show_reset_icon.addEventListener("change",this.handlesettingschanged,!1),this.enable_shift_drag_zoom.addEventListener("change",this.handlesettingschanged,!1),this.show_algebra_input.addEventListener("change",this.handlesettingschanged,!1),this.show_menu_bar.addEventListener("change",this.handlesettingschanged,!1),this.show_tool_bar.addEventListener("change",this.handlesettingschanged,!1)},handlesettingschanged:function(evt){window.GGBT.parameters[evt.target.id]=evt.target.checked,$('input[name="ggbparameters"]').val(JSON.stringify(window.GGBT.parameters)),"showToolBar"==evt.target.id||"showMenuBar"==evt.target.id||"showAlgebraInput"==evt.target.id?(window.applet1=new GGBApplet(window.GGBT.parameters,!0),window.applet1.inject("applet_container1","preferHTML5")):window.ggbApplet[evt.target.id](evt.target.checked)},handleusefile:function(){window.GGBT.usefile.checked?document.getElementById("id_ggbturl").value="":(document.getElementById("applet_container1").style.display="none",document.getElementById("applet_options").style.display="none")},handleggbdisable:function(){window.GGBT.ggbcheckb.checked?document.getElementById("applet_container1").style.display="block":(document.getElementById("applet_container1").style.display="none",document.getElementById("applet_options").style.display="none",window.GGBT.usefile.checked&&window.GGBT.usefile.click())},handleDragEnter:function(){("undefined"==typeof ggbcheckb||window.GGBT.ggbcheckb.checked)&&(window.GGBT.ggbf.classList.add("qtype-geogebra-hover"),document.getElementById("applet_container1").style.visibility="hidden")},handleDragOver:function(e){if(void 0===window.GGBT.ggbcheckb||window.GGBT.ggbcheckb.checked)return e.preventDefault&&e.preventDefault(),window.GGBT.ggbf.classList.add("qtype-geogebra-hover"),document.getElementById("applet_container1").style.visibility="hidden",!1},handleDragEndLeave:function(){(void 0===window.GGBT.ggbcheckb||window.GGBT.ggbcheckb.checked)&&(window.GGBT.ggbf.classList.remove("qtype-geogebra-hover"),document.getElementById("applet_container1").style.removeProperty("visibility"))},handleDrop:function(e){if(void 0===window.GGBT.ggbcheckb||window.GGBT.ggbcheckb.checked){e.preventDefault(),e.stopPropagation();var file=e.dataTransfer.files[0];window.GGBT.ggbf.classList.remove("qtype-geogebra-hover"),document.getElementById("applet_container1").style.removeProperty("visibility"),document.getElementById("applet_container1").style.display="block",document.getElementById("applet_options").style.display="flex",document.getElementById("applet_container1").style.height="100%",document.getElementById("id_ggbturl").value="",window.GGBT.usefile.checked||window.GGBT.usefile.click();var reader=new FileReader;reader.onload=function(event){var base64=event.target.result.replace("data:application/vnd.geogebra.file;base64,","");window.GGBT.parameters={ggbBase64:base64},window.GGBT.parameters.enableRightClick=window.GGBT.enable_right_click.checked,window.GGBT.parameters.enableLabelDrags=window.GGBT.enable_label_drags.checked,window.GGBT.parameters.showResetIcon=window.GGBT.show_reset_icon.checked,window.GGBT.parameters.enableShiftDragZoom=window.GGBT.enable_shift_drag_zoom.checked,window.GGBT.parameters.showAlgebraInput=window.GGBT.show_algebra_input.checked,window.GGBT.parameters.showMenuBar=window.GGBT.show_menu_bar.checked,window.GGBT.parameters.showToolBar=window.GGBT.show_tool_bar.checked,window.GGBT.parameters.moodle="editingQuestionOrSubmission",window.applet1=new GGBApplet(window.GGBT.parameters,!0),window.applet1.inject("applet_container1")},reader.readAsDataURL(file)}},isNumber:function(n){return!isNaN(parseFloat(n))&&isFinite(n)}}})); +define("qtype_geogebra/ggbt",["jquery","https://www.geogebra.org/apps/deployggb.js"],(function($,GGBApplet){return{init:function(){window.GGBT=this,window.ggbAppletOnLoad=function(){if($('input[name="ggbparameters"]').val(JSON.stringify(window.applet1.getParameters())),$('input[name="ggbviews"]').val(JSON.stringify(window.applet1.getViews())),$('input[name="ggbcodebaseversion"]').val(window.applet1.getHTML5CodebaseVersion()),void 0===this.ggbcheckb){var applet=document.ggbApplet;console.log($('input[name="ggbxml"]')),$('input[name="ggbxml"]').val(applet.getXML()),document.getElementById("id_randomizedvar").value||window.GGBT.getrandvars();for(var i=0,answer=$("#id_answer_"+i);void 0!==answer[0];)answer.val()&&(answer.on("change focus",(function(e){e.preventDefault(),window.GGBT.update_feedback($(e.target))})),window.GGBT.update_feedback(answer)),answer=$("#id_answer_"+ ++i);document.querySelector("article").onkeypress=window.GGBT.checkEnter}window.GGBT.usefile.checked&&(document.getElementById("applet_container1").style.display="block",document.getElementById("applet_options").style.display="flex")},void 0!==$("#applet_parameters")[0]&&(this.ggbDataset=$("#applet_parameters")[0].dataset,this.parameters=JSON.parse(this.ggbDataset.parameters),this.views=this.ggbDataset.views,window.applet1=new GGBApplet(this.parameters,this.views,!0),this.lang=this.ggbDataset.lang),$("#id_loadapplet").on("click",(function(e){e.preventDefault();var id=$("#id_ggbturl").val().split("/").pop();0==id.indexOf("m")&&(window.GGBT.isNumber(id.substr(1))||!window.GGBT.isNumber(id.substr(1))&&id.length>8)&&(id=id.substr(1)),window.GGBT.injectapplet(id)})),$("#id_getvars").on("click",(function(e){e.preventDefault(),window.GGBT.getrandvars()})),this.parameters&&window.applet1.inject("applet_container1","preferHTML5"),this.ggbf=document.getElementById("id_ggbtheader"),this.usefile=document.getElementById("id_usefile"),null===this.ggbf&&(this.ggbf=document.getElementById("id_submissiontypes"),this.ggbcheckb=document.getElementById("id_assignsubmission_geogebra_enabled"),null!==this.ggbcheckb&&this.ggbcheckb.addEventListener("change",this.handleggbdisable,!1)),null!==this.ggbf&&(this.ggbf.addEventListener("dragenter",this.handleDragEnter,!1),this.ggbf.addEventListener("dragover",this.handleDragOver,!1),this.ggbf.addEventListener("dragleave",this.handleDragEndLeave,!1),this.ggbf.addEventListener("dragend",this.handleDragEndLeave,!1),this.ggbf.addEventListener("drop",this.handleDrop,!1),this.usefile.addEventListener("change",this.handleusefile,!1)),this.usefile.checked?document.getElementById("applet_options").style.display="block":document.getElementById("applet_options").style.display="none",this.initoptions()},callback:function(params){var elementname=M.core_filepicker.instances[params.client_id].options.elementname;$("#id_"+elementname).val(params.url);var id=params.file.split(".")[0];0==id.indexOf("m")&&(this.isNumber(id.substr(1))||!this.isNumber(id.substr(1))&&id.length>8)&&(id=id.substr(1)),this.injectapplet(id)},injectapplet:function(id){this.parameters={material_id:id},this.parameters.language=this.lang,this.parameters.moodle="editingQuestionOrSubmission",this.parameters.useBrowserForJS=!1,document.getElementById("applet_container1").style.display="block",window.applet1=new GGBApplet(this.parameters,!0),window.applet1.inject("applet_container1","preferHTML5")},getrandvars:function(){var applet=document.ggbApplet;if(void 0!==applet)for(var objNumber=applet.getObjectNumber(),randomizedvar=document.getElementById("id_randomizedvar"),stringforrandomizedvars="",i=0,j=0;j0&&(answer.val()||answer.val(strName),this.update_feedback(answer),i++)}randomizedvar.value=stringforrandomizedvars}},update_feedback:function(answernode){var id=answernode.attr("id").split("_").pop(),varname=answernode.val();if(!varname)return;var feedback=$('input[name="feedback['+id+']"]'),feedbackfromfile=$("#id_feedbackfromfile_"+id);const parser=new DOMParser,xml=window.ggbApplet.getXML(varname);if(!xml)return;const doc=parser.parseFromString(xml,"text/xml");if(doc){var elem=doc.getElementsByTagName("caption"),fbstring="";1==elem.length?(fbstring=elem[0].getAttribute("val"),feedback.val(fbstring)):elem.length>1?(feedback.val(""),fbstring=""):(feedback.val(""),fbstring="Caption not set or variable name wrong."),feedbackfromfile.val(fbstring)}},checkEnter:function(e){return e=e||event,/textarea/i.test((e.target||e.srcElement).tagName)||13!==(e.keyCode||e.which||e.charCode||0)},initoptions:function(){this.enable_right_click=document.getElementById("enableRightClick"),this.enable_label_drags=document.getElementById("enableLabelDrags"),this.show_reset_icon=document.getElementById("showResetIcon"),this.enable_shift_drag_zoom=document.getElementById("enableShiftDragZoom"),this.show_algebra_input=document.getElementById("showAlgebraInput"),this.show_menu_bar=document.getElementById("showMenuBar"),this.show_tool_bar=document.getElementById("showToolBar"),"undefined"!=typeof parameters&&(this.enable_right_click.checked=this.parameters.enableRightClick,this.enable_label_drags.checked=this.parameters.enableLabelDrags,this.show_reset_icon.checked=this.parameters.showResetIcon,this.enable_shift_drag_zoom.checked=this.parameters.enableShiftDragZoom,this.show_algebra_input.checked=this.parameters.showAlgebraInput,this.show_menu_bar.checked=this.parameters.showMenuBar,this.show_tool_bar.checked=this.parameters.showToolBar),this.enable_right_click.addEventListener("change",this.handlesettingschanged,!1),this.enable_label_drags.addEventListener("change",this.handlesettingschanged,!1),this.show_reset_icon.addEventListener("change",this.handlesettingschanged,!1),this.enable_shift_drag_zoom.addEventListener("change",this.handlesettingschanged,!1),this.show_algebra_input.addEventListener("change",this.handlesettingschanged,!1),this.show_menu_bar.addEventListener("change",this.handlesettingschanged,!1),this.show_tool_bar.addEventListener("change",this.handlesettingschanged,!1)},handlesettingschanged:function(evt){window.GGBT.parameters[evt.target.id]=evt.target.checked,$('input[name="ggbparameters"]').val(JSON.stringify(window.GGBT.parameters)),"showToolBar"==evt.target.id||"showMenuBar"==evt.target.id||"showAlgebraInput"==evt.target.id?(window.applet1=new GGBApplet(window.GGBT.parameters,!0),window.applet1.inject("applet_container1","preferHTML5")):window.ggbApplet[evt.target.id](evt.target.checked)},handleusefile:function(){window.GGBT.usefile.checked?document.getElementById("id_ggbturl").value="":(document.getElementById("applet_container1").style.display="none",document.getElementById("applet_options").style.display="none")},handleggbdisable:function(){window.GGBT.ggbcheckb.checked?document.getElementById("applet_container1").style.display="block":(document.getElementById("applet_container1").style.display="none",document.getElementById("applet_options").style.display="none",window.GGBT.usefile.checked&&window.GGBT.usefile.click())},handleDragEnter:function(){("undefined"==typeof ggbcheckb||window.GGBT.ggbcheckb.checked)&&(window.GGBT.ggbf.classList.add("qtype-geogebra-hover"),document.getElementById("applet_container1").style.visibility="hidden")},handleDragOver:function(e){if(void 0===window.GGBT.ggbcheckb||window.GGBT.ggbcheckb.checked)return e.preventDefault&&e.preventDefault(),window.GGBT.ggbf.classList.add("qtype-geogebra-hover"),document.getElementById("applet_container1").style.visibility="hidden",!1},handleDragEndLeave:function(){(void 0===window.GGBT.ggbcheckb||window.GGBT.ggbcheckb.checked)&&(window.GGBT.ggbf.classList.remove("qtype-geogebra-hover"),document.getElementById("applet_container1").style.removeProperty("visibility"))},handleDrop:function(e){if(void 0===window.GGBT.ggbcheckb||window.GGBT.ggbcheckb.checked){e.preventDefault(),e.stopPropagation();var file=e.dataTransfer.files[0];window.GGBT.ggbf.classList.remove("qtype-geogebra-hover"),document.getElementById("applet_container1").style.removeProperty("visibility"),document.getElementById("applet_container1").style.display="block",document.getElementById("applet_options").style.display="flex",document.getElementById("applet_container1").style.height="100%",document.getElementById("id_ggbturl").value="",window.GGBT.usefile.checked||window.GGBT.usefile.click();var reader=new FileReader;reader.onload=function(event){var base64=event.target.result.replace("data:application/vnd.geogebra.file;base64,","");window.GGBT.parameters={ggbBase64:base64},window.GGBT.parameters.enableRightClick=window.GGBT.enable_right_click.checked,window.GGBT.parameters.enableLabelDrags=window.GGBT.enable_label_drags.checked,window.GGBT.parameters.showResetIcon=window.GGBT.show_reset_icon.checked,window.GGBT.parameters.enableShiftDragZoom=window.GGBT.enable_shift_drag_zoom.checked,window.GGBT.parameters.showAlgebraInput=window.GGBT.show_algebra_input.checked,window.GGBT.parameters.showMenuBar=window.GGBT.show_menu_bar.checked,window.GGBT.parameters.showToolBar=window.GGBT.show_tool_bar.checked,window.GGBT.parameters.moodle="editingQuestionOrSubmission",window.applet1=new GGBApplet(window.GGBT.parameters,!0),window.applet1.inject("applet_container1")},reader.readAsDataURL(file)}},isNumber:function(n){return!isNaN(parseFloat(n))&&isFinite(n)}}})); //# sourceMappingURL=ggbt.min.js.map \ No newline at end of file diff --git a/amd/build/ggbt.min.js.map b/amd/build/ggbt.min.js.map index fdbceea..0c67018 100644 --- a/amd/build/ggbt.min.js.map +++ b/amd/build/ggbt.min.js.map @@ -1 +1 @@ -{"version":3,"file":"ggbt.min.js","sources":["../src/ggbt.js"],"sourcesContent":["/**\n * Javascript Controller to embed GGBApplet\n *\n * This class provides all the functionality for the new assign module.\n *\n * @author Christoph Stadlbauer \n * @copyright (c) International GeoGebra Institute 2018\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n define(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GGBApplet) {\n /**\n * Created by Christoph on 25.08.19.\n */\n return {\n\n init: function() {\n window.GGBT = this;\n window.ggbAppletOnLoad = function() {\n $('input[name=\"ggbparameters\"]').val(JSON.stringify(window.applet1.getParameters()));\n $('input[name=\"ggbviews\"]').val(JSON.stringify(window.applet1.getViews()));\n $('input[name=\"ggbcodebaseversion\"]').val(window.applet1.getHTML5CodebaseVersion());\n\n if (typeof (this.ggbcheckb) == \"undefined\") {\n\n var randomizedvar = document.getElementById('id_randomizedvar');\n if (!randomizedvar.value) {\n window.GGBT.getrandvars();\n }\n\n var i = 0;\n var answer = $('#id_answer_' + i);\n while (answer[0] !== undefined) {\n if (answer.val()) {\n answer.on('change focus', function(e) {\n e.preventDefault();\n window.GGBT.update_feedback($(e.target));\n });\n window.GGBT.update_feedback(answer);\n }\n answer = $('#id_answer_' + ++i);\n }\n document.querySelector('article').onkeypress = window.GGBT.checkEnter;\n }\n if (window.GGBT.usefile.checked) {\n document.getElementById('applet_container1').style.display = \"block\";\n document.getElementById('applet_options').style.display = \"flex\";\n }\n };\n\n if ($('#applet_parameters')[0] !== undefined) {\n this.ggbDataset = $('#applet_parameters')[0].dataset;\n this.parameters = JSON.parse(this.ggbDataset.parameters);\n this.views = this.ggbDataset.views;\n window.applet1 = new GGBApplet(this.parameters, this.views, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.410.0/web3d\");\n this.lang = this.ggbDataset.lang;\n }\n\n $('#id_loadapplet').on('click', function(e) {\n e.preventDefault();\n var id = $('#id_ggbturl').val().split(\"/\").pop();\n if (id.indexOf(\"m\") == 0) {\n if (window.GGBT.isNumber(id.substr(1)) || (!window.GGBT.isNumber(id.substr(1)) && id.length > 8)) {\n id = id.substr(1);\n }\n }\n window.GGBT.injectapplet(id);\n });\n\n $('#id_getvars').on('click', function(e) {\n e.preventDefault();\n window.GGBT.getrandvars();\n });\n\n if (this.parameters) {\n window.applet1.inject(\"applet_container1\", \"preferHTML5\");\n }\n\n this.ggbf = document.getElementById('id_ggbtheader');\n this.usefile = document.getElementById(\"id_usefile\");\n\n if (this.ggbf === null) { // In this case we are editing a submission.\n this.ggbf = document.getElementById('id_submissiontypes');\n this.ggbcheckb = document.getElementById('id_assignsubmission_geogebra_enabled');\n if (this.ggbcheckb !== null) {\n this.ggbcheckb.addEventListener('change', this.handleggbdisable, false);\n }\n }\n\n if (this.ggbf !== null) {\n this.ggbf.addEventListener('dragenter', this.handleDragEnter, false);\n this.ggbf.addEventListener('dragover', this.handleDragOver, false);\n this.ggbf.addEventListener('dragleave', this.handleDragEndLeave, false);\n this.ggbf.addEventListener('dragend', this.handleDragEndLeave, false);\n this.ggbf.addEventListener('drop', this.handleDrop, false);\n this.usefile.addEventListener('change', this.handleusefile, false);\n }\n\n if (this.usefile.checked) {\n document.getElementById('applet_options').style.display = \"block\";\n } else {\n document.getElementById('applet_options').style.display = \"none\";\n }\n this.initoptions();\n },\n\n callback: function(params) {\n var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;\n $('#id_' + elementname).val(params.url);\n // inject applet to div layer\n var id = (params.file).split(\".\")[0];\n if (id.indexOf(\"m\") == 0) {\n if (this.isNumber(id.substr(1)) || (!this.isNumber(id.substr(1)) && id.length > 8)) {\n id = id.substr(1);\n }\n }\n this.injectapplet(id);\n },\n\n injectapplet: function(id) {\n this.parameters = {\"material_id\": id};\n this.parameters.language = this.lang;\n this.parameters.moodle = \"editingQuestionOrSubmission\";\n // Since we only support HTML5 this should work for js-code in the applet to get executed (ggboninit).\n this.parameters.useBrowserForJS = false;\n\n document.getElementById('applet_container1').style.display = \"block\";\n\n window.applet1 = new GGBApplet(this.parameters, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n\n window.applet1.inject(\"applet_container1\", \"preferHTML5\");\n\n },\n\n getrandvars: function() {\n var applet = document.ggbApplet;\n if (typeof applet !== 'undefined') {\n var objNumber = applet.getObjectNumber();\n var randomizedvar = document.getElementById('id_randomizedvar');\n var stringforrandomizedvars = \"\";\n var i = 0;\n for (var j = 0; j < objNumber; j++) {\n var strName = applet.getObjectName(j);\n if (applet.getObjectType(strName) == \"numeric\" && applet.isIndependent(strName)) {\n stringforrandomizedvars += strName + \",\";\n } else {\n var answer = $('#id_answer_' + i);\n if (applet.getObjectType(strName) == \"boolean\") {\n if (answer !== null && answer.length > 0) {\n if (!answer.val()) {\n answer.val(strName);\n }\n this.update_feedback(answer);\n i++;\n }\n }\n }\n randomizedvar.value = stringforrandomizedvars;\n }\n }\n },\n\n update_feedback: function(answernode) {\n var id = answernode.attr('id').split(\"_\").pop();\n var varname = answernode.val();\n if (!varname) {\n // Should not happen, but make sure this function does not fail.\n return;\n }\n var feedback = $('input[name=\"feedback[' + id + ']\"]');\n var feedbackfromfile = $('#id_feedbackfromfile_' + id);\n const parser = new DOMParser();\n const xml = window.ggbApplet.getXML(varname);\n if (!xml) {\n // Should not happen, but make sure this function does not fail.\n return;\n }\n const doc = parser.parseFromString(xml, \"text/xml\");\n if (doc) {\n var elem = doc.getElementsByTagName('caption');\n var fbstring = '';\n if (elem.length == 1) {\n fbstring = elem[0].getAttribute('val');\n feedback.val(fbstring);\n } else if (elem.length > 1) {\n feedback.val('');\n fbstring = '';\n } else {\n feedback.val('');\n //this is rather an error condition but should be checked by the server\n fbstring = 'Caption not set or variable name wrong.';\n }\n feedbackfromfile.val(fbstring);\n }\n },\n\n checkEnter: function(e) {\n e = e || event;\n var txtArea = /textarea/i.test((e.target || e.srcElement).tagName);\n return txtArea || (e.keyCode || e.which || e.charCode || 0) !== 13;\n },\n\n initoptions: function() {\n this.enable_right_click = document.getElementById('enableRightClick');\n this.enable_label_drags = document.getElementById('enableLabelDrags');\n this.show_reset_icon = document.getElementById('showResetIcon');\n this.enable_shift_drag_zoom = document.getElementById('enableShiftDragZoom');\n this.show_algebra_input = document.getElementById('showAlgebraInput');\n this.show_menu_bar = document.getElementById('showMenuBar');\n this.show_tool_bar = document.getElementById('showToolBar');\n\n if (typeof parameters !== 'undefined') {\n this.enable_right_click.checked = this.parameters.enableRightClick;\n this.enable_label_drags.checked = this.parameters.enableLabelDrags;\n this.show_reset_icon.checked = this.parameters.showResetIcon;\n this.enable_shift_drag_zoom.checked = this.parameters.enableShiftDragZoom;\n this.show_algebra_input.checked = this.parameters.showAlgebraInput;\n this.show_menu_bar.checked = this.parameters.showMenuBar;\n this.show_tool_bar.checked = this.parameters.showToolBar;\n }\n\n this.enable_right_click.addEventListener('change', this.handlesettingschanged, false);\n this.enable_label_drags.addEventListener('change', this.handlesettingschanged, false);\n this.show_reset_icon.addEventListener('change', this.handlesettingschanged, false);\n this.enable_shift_drag_zoom.addEventListener('change', this.handlesettingschanged, false);\n this.show_algebra_input.addEventListener('change', this.handlesettingschanged, false);\n this.show_menu_bar.addEventListener('change', this.handlesettingschanged, false);\n this.show_tool_bar.addEventListener('change', this.handlesettingschanged, false);\n },\n\n handlesettingschanged: function(evt) {\n window.GGBT.parameters[evt.target.id] = (evt.target.checked);\n $('input[name=\"ggbparameters\"]').val(JSON.stringify(window.GGBT.parameters));\n if (evt.target.id == \"showToolBar\" || evt.target.id == \"showMenuBar\" || evt.target.id == \"showAlgebraInput\") {\n window.applet1 = new GGBApplet(window.GGBT.parameters, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n window.applet1.inject(\"applet_container1\", \"preferHTML5\");\n } else {\n window.ggbApplet[evt.target.id](evt.target.checked);\n }\n },\n\n handleusefile: function() {\n if (!window.GGBT.usefile.checked) {\n document.getElementById('applet_container1').style.display = \"none\";\n document.getElementById('applet_options').style.display = \"none\";\n } else {\n document.getElementById('id_ggbturl').value = \"\";\n // document.getElementById('applet_container1').style.display = \"block\";\n }\n },\n\n handleggbdisable: function() {\n if (!window.GGBT.ggbcheckb.checked) {\n document.getElementById('applet_container1').style.display = \"none\";\n document.getElementById('applet_options').style.display = \"none\";\n if (window.GGBT.usefile.checked) {\n window.GGBT.usefile.click();\n }\n } else {\n document.getElementById('applet_container1').style.display = \"block\";\n }\n },\n\n handleDragEnter: function() {\n if (typeof (ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n window.GGBT.ggbf.classList.add('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.visibility = \"hidden\";\n }\n },\n\n handleDragOver: function(e) {\n if (typeof (window.GGBT.ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n if (e.preventDefault) {\n e.preventDefault();\n }\n window.GGBT.ggbf.classList.add('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.visibility = \"hidden\";\n return false;\n }\n },\n\n handleDragEndLeave: function() {\n if (typeof (window.GGBT.ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n window.GGBT.ggbf.classList.remove('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.removeProperty(\"visibility\");\n }\n },\n\n handleDrop: function(e) {\n if (typeof (window.GGBT.ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n e.preventDefault();\n e.stopPropagation();\n var file = e.dataTransfer.files[0];\n window.GGBT.ggbf.classList.remove('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.removeProperty(\"visibility\");\n document.getElementById('applet_container1').style.display = \"block\";\n document.getElementById('applet_options').style.display = \"flex\";\n document.getElementById('applet_container1').style.height = \"100%\";\n //document.getElementById('applet_container1').style.width = \"100%\";\n\n document.getElementById('id_ggbturl').value = \"\";\n //this.usefile = document.getElementById(\"id_usefile\");\n if (!window.GGBT.usefile.checked) {\n window.GGBT.usefile.click();\n }\n var reader = new FileReader();\n reader.onload = function(event) {\n var base64 = event.target.result.replace(\"data:application/vnd.geogebra.file;base64,\", \"\");\n window.GGBT.parameters = {\"ggbBase64\": base64};\n window.GGBT.parameters.enableRightClick = window.GGBT.enable_right_click.checked;\n window.GGBT.parameters.enableLabelDrags = window.GGBT.enable_label_drags.checked;\n window.GGBT.parameters.showResetIcon = window.GGBT.show_reset_icon.checked;\n window.GGBT.parameters.enableShiftDragZoom = window.GGBT.enable_shift_drag_zoom.checked;\n window.GGBT.parameters.showAlgebraInput = window.GGBT.show_algebra_input.checked;\n window.GGBT.parameters.showMenuBar = window.GGBT.show_menu_bar.checked;\n window.GGBT.parameters.showToolBar = window.GGBT.show_tool_bar.checked;\n window.GGBT.parameters.moodle = \"editingQuestionOrSubmission\";\n window.applet1 = new GGBApplet(window.GGBT.parameters, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n window.applet1.inject(\"applet_container1\");\n };\n\n reader.readAsDataURL(file);\n }\n },\n\n isNumber: function(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n }\n };\n});\n"],"names":["define","$","GGBApplet","init","window","GGBT","this","ggbAppletOnLoad","val","JSON","stringify","applet1","getParameters","getViews","getHTML5CodebaseVersion","ggbcheckb","document","getElementById","value","getrandvars","i","answer","undefined","on","e","preventDefault","update_feedback","target","querySelector","onkeypress","checkEnter","usefile","checked","style","display","ggbDataset","dataset","parameters","parse","views","lang","id","split","pop","indexOf","isNumber","substr","length","injectapplet","inject","ggbf","addEventListener","handleggbdisable","handleDragEnter","handleDragOver","handleDragEndLeave","handleDrop","handleusefile","initoptions","callback","params","elementname","M","core_filepicker","instances","options","url","file","language","moodle","useBrowserForJS","applet","ggbApplet","objNumber","getObjectNumber","randomizedvar","stringforrandomizedvars","j","strName","getObjectName","getObjectType","isIndependent","answernode","attr","varname","feedback","feedbackfromfile","parser","DOMParser","xml","getXML","doc","parseFromString","elem","getElementsByTagName","fbstring","getAttribute","event","test","srcElement","tagName","keyCode","which","charCode","enable_right_click","enable_label_drags","show_reset_icon","enable_shift_drag_zoom","show_algebra_input","show_menu_bar","show_tool_bar","enableRightClick","enableLabelDrags","showResetIcon","enableShiftDragZoom","showAlgebraInput","showMenuBar","showToolBar","handlesettingschanged","evt","click","classList","add","visibility","remove","removeProperty","stopPropagation","dataTransfer","files","height","reader","FileReader","onload","base64","result","replace","readAsDataURL","n","isNaN","parseFloat","isFinite"],"mappings":";;;;;;;;;AASCA,6BAAO,CAAC,SAAU,+CAA+C,SAAUC,EAAGC,iBAIpE,CAEHC,KAAM,WACFC,OAAOC,KAAOC,KACdF,OAAOG,gBAAkB,cACrBN,EAAE,+BAA+BO,IAAIC,KAAKC,UAAUN,OAAOO,QAAQC,kBACnEX,EAAE,0BAA0BO,IAAIC,KAAKC,UAAUN,OAAOO,QAAQE,aAC9DZ,EAAE,oCAAoCO,IAAIJ,OAAOO,QAAQG,gCAE1B,IAAnBR,KAAKS,UAA2B,CAEpBC,SAASC,eAAe,oBACzBC,OACfd,OAAOC,KAAKc,sBAGZC,EAAI,EACJC,OAASpB,EAAE,cAAgBmB,QACVE,IAAdD,OAAO,IACNA,OAAOb,QACPa,OAAOE,GAAG,gBAA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5DjH,SAASC,eAAe,cAAcC,MAAQ,GAEzCd,OAAOC,KAAK0B,QAAQC,SACrB5B,OAAOC,KAAK0B,QAAQyF,YAEpBU,OAAS,IAAIC,WACjBD,OAAOE,OAAS,SAASnC,WACjBoC,OAASpC,MAAMtE,OAAO2G,OAAOC,QAAQ,6CAA8C,IACvFnI,OAAOC,KAAKgC,WAAa,WAAcgG,QACvCjI,OAAOC,KAAKgC,WAAW0E,iBAAmB3G,OAAOC,KAAKmG,mBAAmBxE,QACzE5B,OAAOC,KAAKgC,WAAW2E,iBAAmB5G,OAAOC,KAAKoG,mBAAmBzE,QACzE5B,OAAOC,KAAKgC,WAAW4E,cAAgB7G,OAAOC,KAAKqG,gBAAgB1E,QACnE5B,OAAOC,KAAKgC,WAAW6E,oBAAsB9G,OAAOC,KAAKsG,uBAAuB3E,QAChF5B,OAAOC,KAAKgC,WAAW8E,iBAAmB/G,OAAOC,KAAKuG,mBAAmB5E,QACzE5B,OAAOC,KAAKgC,WAAW+E,YAAchH,OAAOC,KAAKwG,cAAc7E,QAC/D5B,OAAOC,KAAKgC,WAAWgF,YAAcjH,OAAOC,KAAKyG,cAAc9E,QAC/D5B,OAAOC,KAAKgC,WAAWgC,OAAS,8BAChCjE,OAAOO,QAAU,IAAIT,UAAUE,OAAOC,KAAKgC,YAAY,GAEvDjC,OAAOO,QAAQsC,OAAO,sBAG1BiF,OAAOM,cAAcrE,QAI7BtB,SAAU,SAAS4F,UACPC,MAAMC,WAAWF,KAAOG,SAASH"} \ No newline at end of file +{"version":3,"file":"ggbt.min.js","sources":["../src/ggbt.js"],"sourcesContent":["/**\n * Javascript Controller to embed GGBApplet\n *\n * This class provides all the functionality for the new assign module.\n *\n * @author Christoph Stadlbauer \n * @copyright (c) International GeoGebra Institute 2018\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n define(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GGBApplet) {\n /**\n * Created by Christoph on 25.08.19.\n */\n return {\n\n init: function() {\n window.GGBT = this;\n window.ggbAppletOnLoad = function() {\n $('input[name=\"ggbparameters\"]').val(JSON.stringify(window.applet1.getParameters()));\n $('input[name=\"ggbviews\"]').val(JSON.stringify(window.applet1.getViews()));\n $('input[name=\"ggbcodebaseversion\"]').val(window.applet1.getHTML5CodebaseVersion());\n\n if (typeof (this.ggbcheckb) == \"undefined\") {\n var applet = document.ggbApplet;\n console.log($('input[name=\"ggbxml\"]'));\n $('input[name=\"ggbxml\"]').val(applet.getXML());\n\n var randomizedvar = document.getElementById('id_randomizedvar');\n if (!randomizedvar.value) {\n window.GGBT.getrandvars();\n }\n\n var i = 0;\n var answer = $('#id_answer_' + i);\n while (answer[0] !== undefined) {\n if (answer.val()) {\n answer.on('change focus', function(e) {\n e.preventDefault();\n window.GGBT.update_feedback($(e.target));\n });\n window.GGBT.update_feedback(answer);\n }\n answer = $('#id_answer_' + ++i);\n }\n document.querySelector('article').onkeypress = window.GGBT.checkEnter;\n }\n if (window.GGBT.usefile.checked) {\n document.getElementById('applet_container1').style.display = \"block\";\n document.getElementById('applet_options').style.display = \"flex\";\n }\n };\n\n if ($('#applet_parameters')[0] !== undefined) {\n this.ggbDataset = $('#applet_parameters')[0].dataset;\n this.parameters = JSON.parse(this.ggbDataset.parameters);\n this.views = this.ggbDataset.views;\n window.applet1 = new GGBApplet(this.parameters, this.views, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.410.0/web3d\");\n this.lang = this.ggbDataset.lang;\n }\n\n $('#id_loadapplet').on('click', function(e) {\n e.preventDefault();\n var id = $('#id_ggbturl').val().split(\"/\").pop();\n if (id.indexOf(\"m\") == 0) {\n if (window.GGBT.isNumber(id.substr(1)) || (!window.GGBT.isNumber(id.substr(1)) && id.length > 8)) {\n id = id.substr(1);\n }\n }\n window.GGBT.injectapplet(id);\n });\n\n $('#id_getvars').on('click', function(e) {\n e.preventDefault();\n window.GGBT.getrandvars();\n });\n\n if (this.parameters) {\n window.applet1.inject(\"applet_container1\", \"preferHTML5\");\n }\n\n this.ggbf = document.getElementById('id_ggbtheader');\n this.usefile = document.getElementById(\"id_usefile\");\n\n if (this.ggbf === null) { // In this case we are editing a submission.\n this.ggbf = document.getElementById('id_submissiontypes');\n this.ggbcheckb = document.getElementById('id_assignsubmission_geogebra_enabled');\n if (this.ggbcheckb !== null) {\n this.ggbcheckb.addEventListener('change', this.handleggbdisable, false);\n }\n }\n\n if (this.ggbf !== null) {\n this.ggbf.addEventListener('dragenter', this.handleDragEnter, false);\n this.ggbf.addEventListener('dragover', this.handleDragOver, false);\n this.ggbf.addEventListener('dragleave', this.handleDragEndLeave, false);\n this.ggbf.addEventListener('dragend', this.handleDragEndLeave, false);\n this.ggbf.addEventListener('drop', this.handleDrop, false);\n this.usefile.addEventListener('change', this.handleusefile, false);\n }\n\n if (this.usefile.checked) {\n document.getElementById('applet_options').style.display = \"block\";\n } else {\n document.getElementById('applet_options').style.display = \"none\";\n }\n this.initoptions();\n },\n\n callback: function(params) {\n var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;\n $('#id_' + elementname).val(params.url);\n // inject applet to div layer\n var id = (params.file).split(\".\")[0];\n if (id.indexOf(\"m\") == 0) {\n if (this.isNumber(id.substr(1)) || (!this.isNumber(id.substr(1)) && id.length > 8)) {\n id = id.substr(1);\n }\n }\n this.injectapplet(id);\n },\n\n injectapplet: function(id) {\n this.parameters = {\"material_id\": id};\n this.parameters.language = this.lang;\n this.parameters.moodle = \"editingQuestionOrSubmission\";\n // Since we only support HTML5 this should work for js-code in the applet to get executed (ggboninit).\n this.parameters.useBrowserForJS = false;\n\n document.getElementById('applet_container1').style.display = \"block\";\n\n window.applet1 = new GGBApplet(this.parameters, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n\n window.applet1.inject(\"applet_container1\", \"preferHTML5\");\n\n },\n\n getrandvars: function() {\n var applet = document.ggbApplet;\n if (typeof applet !== 'undefined') {\n var objNumber = applet.getObjectNumber();\n var randomizedvar = document.getElementById('id_randomizedvar');\n var stringforrandomizedvars = \"\";\n var i = 0;\n for (var j = 0; j < objNumber; j++) {\n var strName = applet.getObjectName(j);\n if (applet.getObjectType(strName) == \"numeric\" && applet.isIndependent(strName)) {\n stringforrandomizedvars += strName + \",\";\n } else {\n var answer = $('#id_answer_' + i);\n if (applet.getObjectType(strName) == \"boolean\") {\n if (answer !== null && answer.length > 0) {\n if (!answer.val()) {\n answer.val(strName);\n }\n this.update_feedback(answer);\n i++;\n }\n }\n }\n randomizedvar.value = stringforrandomizedvars;\n }\n }\n },\n\n update_feedback: function(answernode) {\n var id = answernode.attr('id').split(\"_\").pop();\n var varname = answernode.val();\n if (!varname) {\n // Should not happen, but make sure this function does not fail.\n return;\n }\n var feedback = $('input[name=\"feedback[' + id + ']\"]');\n var feedbackfromfile = $('#id_feedbackfromfile_' + id);\n const parser = new DOMParser();\n const xml = window.ggbApplet.getXML(varname);\n if (!xml) {\n // Should not happen, but make sure this function does not fail.\n return;\n }\n const doc = parser.parseFromString(xml, \"text/xml\");\n if (doc) {\n var elem = doc.getElementsByTagName('caption');\n var fbstring = '';\n if (elem.length == 1) {\n fbstring = elem[0].getAttribute('val');\n feedback.val(fbstring);\n } else if (elem.length > 1) {\n feedback.val('');\n fbstring = '';\n } else {\n feedback.val('');\n //this is rather an error condition but should be checked by the server\n fbstring = 'Caption not set or variable name wrong.';\n }\n feedbackfromfile.val(fbstring);\n }\n },\n\n checkEnter: function(e) {\n e = e || event;\n var txtArea = /textarea/i.test((e.target || e.srcElement).tagName);\n return txtArea || (e.keyCode || e.which || e.charCode || 0) !== 13;\n },\n\n initoptions: function() {\n this.enable_right_click = document.getElementById('enableRightClick');\n this.enable_label_drags = document.getElementById('enableLabelDrags');\n this.show_reset_icon = document.getElementById('showResetIcon');\n this.enable_shift_drag_zoom = document.getElementById('enableShiftDragZoom');\n this.show_algebra_input = document.getElementById('showAlgebraInput');\n this.show_menu_bar = document.getElementById('showMenuBar');\n this.show_tool_bar = document.getElementById('showToolBar');\n\n if (typeof parameters !== 'undefined') {\n this.enable_right_click.checked = this.parameters.enableRightClick;\n this.enable_label_drags.checked = this.parameters.enableLabelDrags;\n this.show_reset_icon.checked = this.parameters.showResetIcon;\n this.enable_shift_drag_zoom.checked = this.parameters.enableShiftDragZoom;\n this.show_algebra_input.checked = this.parameters.showAlgebraInput;\n this.show_menu_bar.checked = this.parameters.showMenuBar;\n this.show_tool_bar.checked = this.parameters.showToolBar;\n }\n\n this.enable_right_click.addEventListener('change', this.handlesettingschanged, false);\n this.enable_label_drags.addEventListener('change', this.handlesettingschanged, false);\n this.show_reset_icon.addEventListener('change', this.handlesettingschanged, false);\n this.enable_shift_drag_zoom.addEventListener('change', this.handlesettingschanged, false);\n this.show_algebra_input.addEventListener('change', this.handlesettingschanged, false);\n this.show_menu_bar.addEventListener('change', this.handlesettingschanged, false);\n this.show_tool_bar.addEventListener('change', this.handlesettingschanged, false);\n },\n\n handlesettingschanged: function(evt) {\n window.GGBT.parameters[evt.target.id] = (evt.target.checked);\n $('input[name=\"ggbparameters\"]').val(JSON.stringify(window.GGBT.parameters));\n if (evt.target.id == \"showToolBar\" || evt.target.id == \"showMenuBar\" || evt.target.id == \"showAlgebraInput\") {\n window.applet1 = new GGBApplet(window.GGBT.parameters, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n window.applet1.inject(\"applet_container1\", \"preferHTML5\");\n } else {\n window.ggbApplet[evt.target.id](evt.target.checked);\n }\n },\n\n handleusefile: function() {\n if (!window.GGBT.usefile.checked) {\n document.getElementById('applet_container1').style.display = \"none\";\n document.getElementById('applet_options').style.display = \"none\";\n } else {\n document.getElementById('id_ggbturl').value = \"\";\n // document.getElementById('applet_container1').style.display = \"block\";\n }\n },\n\n handleggbdisable: function() {\n if (!window.GGBT.ggbcheckb.checked) {\n document.getElementById('applet_container1').style.display = \"none\";\n document.getElementById('applet_options').style.display = \"none\";\n if (window.GGBT.usefile.checked) {\n window.GGBT.usefile.click();\n }\n } else {\n document.getElementById('applet_container1').style.display = \"block\";\n }\n },\n\n handleDragEnter: function() {\n if (typeof (ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n window.GGBT.ggbf.classList.add('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.visibility = \"hidden\";\n }\n },\n\n handleDragOver: function(e) {\n if (typeof (window.GGBT.ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n if (e.preventDefault) {\n e.preventDefault();\n }\n window.GGBT.ggbf.classList.add('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.visibility = \"hidden\";\n return false;\n }\n },\n\n handleDragEndLeave: function() {\n if (typeof (window.GGBT.ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n window.GGBT.ggbf.classList.remove('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.removeProperty(\"visibility\");\n }\n },\n\n handleDrop: function(e) {\n if (typeof (window.GGBT.ggbcheckb) == \"undefined\" || window.GGBT.ggbcheckb.checked) {\n e.preventDefault();\n e.stopPropagation();\n var file = e.dataTransfer.files[0];\n window.GGBT.ggbf.classList.remove('qtype-geogebra-hover');\n document.getElementById('applet_container1').style.removeProperty(\"visibility\");\n document.getElementById('applet_container1').style.display = \"block\";\n document.getElementById('applet_options').style.display = \"flex\";\n document.getElementById('applet_container1').style.height = \"100%\";\n //document.getElementById('applet_container1').style.width = \"100%\";\n\n document.getElementById('id_ggbturl').value = \"\";\n //this.usefile = document.getElementById(\"id_usefile\");\n if (!window.GGBT.usefile.checked) {\n window.GGBT.usefile.click();\n }\n var reader = new FileReader();\n reader.onload = function(event) {\n var base64 = event.target.result.replace(\"data:application/vnd.geogebra.file;base64,\", \"\");\n window.GGBT.parameters = {\"ggbBase64\": base64};\n window.GGBT.parameters.enableRightClick = window.GGBT.enable_right_click.checked;\n window.GGBT.parameters.enableLabelDrags = window.GGBT.enable_label_drags.checked;\n window.GGBT.parameters.showResetIcon = window.GGBT.show_reset_icon.checked;\n window.GGBT.parameters.enableShiftDragZoom = window.GGBT.enable_shift_drag_zoom.checked;\n window.GGBT.parameters.showAlgebraInput = window.GGBT.show_algebra_input.checked;\n window.GGBT.parameters.showMenuBar = window.GGBT.show_menu_bar.checked;\n window.GGBT.parameters.showToolBar = window.GGBT.show_tool_bar.checked;\n window.GGBT.parameters.moodle = \"editingQuestionOrSubmission\";\n window.applet1 = new GGBApplet(window.GGBT.parameters, true);\n // window.applet1.setHTML5Codebase(\"https://cdn.geogebra.org/apps/5.0.541.0/web3d\");\n window.applet1.inject(\"applet_container1\");\n };\n\n reader.readAsDataURL(file);\n }\n },\n\n isNumber: function(n) {\n return !isNaN(parseFloat(n)) && isFinite(n);\n }\n };\n});\n"],"names":["define","$","GGBApplet","init","window","GGBT","this","ggbAppletOnLoad","val","JSON","stringify","applet1","getParameters","getViews","getHTML5CodebaseVersion","ggbcheckb","applet","document","ggbApplet","console","log","getXML","getElementById","value","getrandvars","i","answer","undefined","on","e","preventDefault","update_feedback","target","querySelector","onkeypress","checkEnter","usefile","checked","style","display","ggbDataset","dataset","parameters","parse","views","lang","id","split","pop","indexOf","isNumber","substr","length","injectapplet","inject","ggbf","addEventListener","handleggbdisable","handleDragEnter","handleDragOver","handleDragEndLeave","handleDrop","handleusefile","initoptions","callback","params","elementname","M","core_filepicker","instances","options","url","file","language","moodle","useBrowserForJS","objNumber","getObjectNumber","randomizedvar","stringforrandomizedvars","j","strName","getObjectName","getObjectType","isIndependent","answernode","attr","varname","feedback","feedbackfromfile","parser","DOMParser","xml","doc","parseFromString","elem","getElementsByTagName","fbstring","getAttribute","event","test","srcElement","tagName","keyCode","which","charCode","enable_right_click","enable_label_drags","show_reset_icon","enable_shift_drag_zoom","show_algebra_input","show_menu_bar","show_tool_bar","enableRightClick","enableLabelDrags","showResetIcon","enableShiftDragZoom","showAlgebraInput","showMenuBar","showToolBar","handlesettingschanged","evt","click","classList","add","visibility","remove","removeProperty","stopPropagation","dataTransfer","files","height","reader","FileReader","onload","base64","result","replace","readAsDataURL","n","isNaN","parseFloat","isFinite"],"mappings":";;;;;;;;;AASCA,6BAAO,CAAC,SAAU,+CAA+C,SAAUC,EAAGC,iBAIpE,CAEHC,KAAM,WACFC,OAAOC,KAAOC,KACdF,OAAOG,gBAAkB,cACrBN,EAAE,+BAA+BO,IAAIC,KAAKC,UAAUN,OAAOO,QAAQC,kBACnEX,EAAE,0BAA0BO,IAAIC,KAAKC,UAAUN,OAAOO,QAAQE,aAC9DZ,EAAE,oCAAoCO,IAAIJ,OAAOO,QAAQG,gCAE1B,IAAnBR,KAAKS,UAA2B,KACpCC,OAASC,SAASC,UACtBC,QAAQC,IAAInB,EAAE,yBACdA,EAAE,wBAAwBO,IAAIQ,OAAOK,UAEjBJ,SAASK,eAAe,oBACzBC,OACfnB,OAAOC,KAAKmB,sBAGZC,EAAI,EACJC,OAASzB,EAAE,cAAgBwB,QACVE,IAAdD,OAAO,IACNA,OAAOlB,QACPkB,OAAOE,GAAG,gBAAgB,SAASC,GAC/BA,EAAEC,iBACF1B,OAAOC,KAAK0B,gBAAgB9B,EAAE4B,EAAEG,YAEpC5B,OAAOC,KAAK0B,gBAAgBL,SAEhCA,OAASzB,EAAE,iBAAkBwB,GAEjCR,SAASgB,cAAc,WAAWC,WAAa9B,OAAOC,KAAK8B,WAE3D/B,OAAOC,KAAK+B,QAAQC,UACpBpB,SAASK,eAAe,qBAAqBgB,MAAMC,QAAU,QAC7DtB,SAASK,eAAe,kBAAkBgB,MAAMC,QAAU,cAI/BZ,IAA/B1B,EAAE,sBAAsB,UACnBuC,WAAavC,EAAE,sBAAsB,GAAGwC,aACxCC,WAAajC,KAAKkC,MAAMrC,KAAKkC,WAAWE,iBACxCE,MAAQtC,KAAKkC,WAAWI,MAC7BxC,OAAOO,QAAU,IAAIT,UAAUI,KAAKoC,WAAYpC,KAAKsC,OAAO,QAEvDC,KAAOvC,KAAKkC,WAAWK,MAGhC5C,E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AKyG,mBAAmBzE,QACzEjC,OAAOC,KAAKqC,WAAW4E,YAAclH,OAAOC,KAAK0G,cAAc1E,QAC/DjC,OAAOC,KAAKqC,WAAW6E,YAAcnH,OAAOC,KAAK2G,cAAc3E,QAC/DjC,OAAOC,KAAKqC,WAAWgC,OAAS,8BAChCtE,OAAOO,QAAU,IAAIT,UAAUE,OAAOC,KAAKqC,YAAY,GAEvDtC,OAAOO,QAAQ2C,OAAO,sBAG1B8E,OAAOM,cAAclE,QAI7BtB,SAAU,SAASyF,UACPC,MAAMC,WAAWF,KAAOG,SAASH"} \ No newline at end of file diff --git a/amd/src/ggbq.js b/amd/src/ggbq.js index 31c4336..2fd2f76 100644 --- a/amd/src/ggbq.js +++ b/amd/src/ggbq.js @@ -37,6 +37,8 @@ define(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GG return { b64input: [], ggbBase64: [], + xmlinput: [], + ggbxml: [], currentvals: [], answerinput: [], responsevars: [], @@ -70,6 +72,7 @@ define(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GG window.addEventListener('resize', resizeScalingContainer); window.GGBQ.b64input[id].val(ggbApplet.getBase64()); + window.GGBQ.xmlinput[id].val(ggbApplet.getXML()); window.GGBQ.qdiv[id].style.visibility = 'visible'; if (window.GGBQ.answerinput[id].val() == '') { @@ -90,6 +93,8 @@ define(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GG this.b64input[slot] = $(document.getElementById(ggbDataset.b64input)); this.ggbBase64[slot] = this.b64input[slot].val(); + this.xmlinput[slot] = $(document.getElementById(ggbDataset.xmlinput)); + this.ggbxml[slot] = this.xmlinput[slot].val(); this.qdiv[slot] = $("#q" + (slot) + " .qtext")[0]; var parameters = JSON.parse(ggbDataset.parameters); @@ -150,6 +155,7 @@ define(['jquery', 'https://www.geogebra.org/apps/deployggb.js'], function ($, GG var ggbApplet = window['ggbApplet' + i]; if (typeof ggbApplet !== "undefined") { window.GGBQ.b64input[i].val(ggbApplet.getBase64()); + window.GGBQ.xmlinput[i].val(ggbApplet.getXML()); // Workaround, to set all randomized variables. for (const [key, value] of Object.entries(window.GGBQ.ggbDatasetVars)) { diff --git a/amd/src/ggbt.js b/amd/src/ggbt.js index d6d8fb9..040ca00 100644 --- a/amd/src/ggbt.js +++ b/amd/src/ggbt.js @@ -21,6 +21,9 @@ $('input[name="ggbcodebaseversion"]').val(window.applet1.getHTML5CodebaseVersion()); if (typeof (this.ggbcheckb) == "undefined") { + var applet = document.ggbApplet; + console.log($('input[name="ggbxml"]')); + $('input[name="ggbxml"]').val(applet.getXML()); var randomizedvar = document.getElementById('id_randomizedvar'); if (!randomizedvar.value) { diff --git a/edit_geogebra_form.php b/edit_geogebra_form.php index 1ec6dea..d11e4da 100644 --- a/edit_geogebra_form.php +++ b/edit_geogebra_form.php @@ -329,10 +329,8 @@ private function check_constraints($data, &$errors) { // Check if all vars in constraints are part of randomized vars. if (count($errors) === 0) { foreach ($inequalitystrings as $inequalitystring) { - // TODO We need to decode from base64 here to get to the xml we do not save anymore. - // TODO Maybe we can also refactor the whole way of checking the validness for randomizedvars. if (!qtype_geogebra_question_helper::is_valid_inequality_for_randomizedvars($inequalitystring, - $data['randomizedvar'], $data['ggbxml']) + $data['randomizedvar']) ) { if (!isset($errors['constraints'])) { $errors['constraints'] = ''; @@ -347,8 +345,6 @@ private function check_constraints($data, &$errors) { // Check if constraints are within the sliders min and max. if (count($errors) === 0) { foreach ($inequalitystrings as $inequalitystring) { - // TODO We need to decode from base64 here to get to the xml we do not save anymore. - // TODO Maybe we can also refactor the whole way of checking the inequality of slider min max. if (!qtype_geogebra_question_helper::is_valid_inequality_for_slider_minmax($inequalitystring, $data['randomizedvar'], $data['ggbxml']) ) { @@ -364,7 +360,6 @@ private function check_constraints($data, &$errors) { } // Check if constraints can be met i.e. are not contradictory or to hard to meet with random numbers. if (count($errors) === 0) { - // TODO Refactor xml to base64 $vars = qtype_geogebra_question_helper::get_variables_with_minmaxstep($data['randomizedvar'], $data['ggbxml']); $inequalities = array(); foreach ($inequalitystrings as $inequalitystring) { @@ -387,7 +382,6 @@ private function check_answer($data, &$errors) { if (isset($data['answer'])) { $i = 0; - // TODO rework to base64 instead of xml $xml = simplexml_load_string($data['ggbxml']); foreach ($data['answer'] as $label) { if (!empty($label)) { @@ -466,6 +460,11 @@ private function add_hidden_inputs($mform) { $mform->addElement('hidden', 'ggbcodebaseversion'); $mform->setType('ggbcodebaseversion', PARAM_RAW); + + // We need the XML injected by the GGB API function to be able to access GGB objects and values from PHP side. However, + // we do not use the XML representation to store the GGB applet itself, but rely on base64. + $mform->addElement('hidden', 'ggbxml'); + $mform->setType('ggbxml', PARAM_RAW); } /** diff --git a/question.php b/question.php index bf6c6b7..85c4444 100644 --- a/question.php +++ b/question.php @@ -132,6 +132,7 @@ public function get_expected_data() { $expected = array(); $expected['answer'] = PARAM_RAW; $expected['ggbbase64'] = PARAM_RAW; + $expected['ggbxml'] = PARAM_RAW; return $expected; } @@ -156,6 +157,7 @@ public function get_correct_response() { */ public function is_complete_response(array $response) { $ret = array_key_exists('ggbbase64', $response) && ($response['ggbbase64']); + $ret = $ret && array_key_exists('ggbxml', $response) && ($response['ggbxml']); if (!empty($this->answers)) { $ret = $ret && array_key_exists('answer', $response) && ($response['answer'] || $response['answer'] === '0'); $ret = $ret && (preg_replace("/[^0,1]/", "", $response['answer']) == $response['answer']); @@ -175,9 +177,27 @@ public function is_complete_response(array $response) { * whether the new set of responses can safely be discarded. */ public function is_same_response(array $prevresponse, array $newresponse) { - // TODO We have to find a way to determine if a response of a user has changed based on base64. - // For now we just say: Whenever it's loaded und saved, it has changed (no matter if there actually have been changes). - return false; + $ret = question_utils::arrays_same_at_key_missing_is_blank($prevresponse, $newresponse, 'answer'); + // The base64 string does not seem to be equal every time you load the applet so using xml + // Some values in euclidianview -> coordsystem are also not equal on each submit + // I think we should only use construction from the xml. + $prevxml = ''; + if (isset($prevresponse['ggbxml'])) { + $prevxml = simplexml_load_string($prevresponse['ggbxml']); + } + $newxml = ''; + if (isset($newresponse['ggbxml'])) { + $newxml = simplexml_load_string($newresponse['ggbxml']); + } + if (!empty($newxml) && empty($prevxml)) { + $ret = false; + } else { + if (!empty($newxml)) { + $ret = $ret && ($prevxml->construction->asXML() == $newxml->construction->asXML()); + } + } + + return $ret; } /** @@ -245,6 +265,9 @@ public function get_validation_error(array $response) { if (!(array_key_exists('ggbbase64', $response) && ($response['ggbbase64']))) { return get_string('ggbfilemissing', 'qtype_geogebra'); } + if (!(array_key_exists('ggbxml', $response) && ($response['ggbxml']))) { + return get_string('ggbxmlmissing', 'qtype_geogebra'); + } if (!empty($this->answers) && !(array_key_exists('answer', $response) && ($response['answer'] || $response['answer'] === '0')) ) { diff --git a/renderer.php b/renderer.php index 8fb6de9..6425f20 100644 --- a/renderer.php +++ b/renderer.php @@ -61,6 +61,18 @@ public function formulation_and_controls(question_attempt $qa, question_display_ $result .= html_writer::empty_tag('input', $b64inputattributes); + $xmlinputname = $qa->get_qt_field_name('ggbxml'); + + $xmlinputattributes = array( + 'type' => 'hidden', + 'name' => $xmlinputname, + 'value' => '', // Value is being extracted from base64 by JS module. + 'id' => $xmlinputname, + 'size' => 80, + ); + + $result .= html_writer::empty_tag('input', $xmlinputattributes); + $answercurrent = $qa->get_last_qt_var('answer'); $answerinputname = $qa->get_qt_field_name('answer'); @@ -118,6 +130,7 @@ public function formulation_and_controls(question_attempt $qa, question_display_ data-div=$ggbdivname data-vars=$currentvals data-b64input=$b64inputname + data-xmlinput=$xmlinputname data-answerinput=$answerinputname data-responsevars=$responsevarsjson data-slot=$slot