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dF,OAAOE,kBAAoB,CAAC,GAEhC,IAAIC,EAAU,UAAYvB,EAC1BoB,OAAOE,kBAAkBC,GAAW,SAAUjB,GAC1Ca,EAAOd,aAAaC,EACxB,CACJ,CAnBYkB,CAAcL,EAAQA,EAAOnB,SACjC,CAAE,MAAOyB,GACLC,QAAQC,IAAI,mCAAmC5C,KAAKG,0CAC3BuC,KACzBC,QAAQC,IAAIF,EAAIG,MACpB,CACJ,GACJ,G","sources":["webpack://WebComponents/./runestone/khanex/js/khanex.js"],"sourcesContent":["/*\n__author__ = Ralph Morelli\n__date__ = 5/4/2021 \n*/\n\n/* **********\n This script renders the khanex HTML code and sets up functions\n to process the exercise when the user clicks on the khanex 'Check Answer'\n button. \n\n It gets the data it needs from the Khanex node created by khanex.py\n during the runestone build step.\n\n NOTE: An entry for khanex.js script must be added to the webpack.config.js.\n ************** */\n\n\"use strict\";\n\nimport RunestoneBase from \"../../common/js/runestonebase.js\";\n\nvar DEBUG = false;\n\nexport default class Khanex extends RunestoneBase {\n constructor(opts) {\n super(opts);\n var orig = opts.orig; // Looks something like: {\"orig\":{\"jQuery351095558298548049562\":{\"question_label\":\"1.1.2\"}}}\n if (DEBUG)\n console.log(\n \"DEBUG: Khanex constructor, opts=\" + JSON.stringify(opts)\n );\n this.origElem = orig;\n this.divid = orig.id;\n this.resultsViewer = $(orig).data(\"results\");\n this.getIFrameAndQuizname();\n this.renderKhanex(); //generates HTML\n // Checks localStorage to see if this khanex has already been completed by this user.\n // this.checkKhanexStorage();\n this.caption = \"Khanex\";\n this.addCaption(\"runestone\");\n }\n\n // The main content of the khanex node is the iframe.\n getIFrameAndQuizname() {\n var html = $(this.origElem).html();\n var p1 = html.search(\"\");\n this.iframe = html.slice(p1, p2 + 8);\n if (DEBUG) console.log(\"DEBUG: getQuestionText() html = \" + html);\n if (DEBUG)\n console.log(\"DEBUG: getQuestionText() iframe = \" + this.iframe);\n p1 = html.search(\"khanex/qs/\");\n p2 = html.search(\".html\");\n this.quizname = html.slice(p1 + 10, p2); // Grab the quizname from iframe\n if (DEBUG) console.log(\"DEBUG quizname= \", this.quizname);\n }\n\n //generates the HTML that the user interacts with\n renderKhanex() {\n var _this = this;\n if (DEBUG) console.log(\"--------------------DEBUG: renderKhanex()\");\n this.containerDiv = document.createElement(\"div\");\n this.containerDiv.id = this.divid;\n $(this.containerDiv).html(this.iframe);\n $(this.origElem).replaceWith(this.containerDiv);\n if (DEBUG)\n console.log(\n \"DEBUG: renderKhanex(), this = \" + JSON.stringify(this)\n );\n }\n\n // This is what a khanex logging event looks like for a correct answer\n // logging event {\"event\":\"khanex\",\"act\":\"answer:correct\",\"answer\":{\"complete\":1,\"count_hints\":0,\"time_taken\":87,\"attempt_number\":1,\"attempt_content\":\"\\\"100011\\\"\",\"sha1\":\"decimal-to-binary\",\"seed\":194953274,\"problem_type\":\"0\",\"review_mode\":0},\"correct\":\"T\",\"div_id\":\"ex2\",\"course\":\"mobilecsp\",\"clientLoginStatus\":false,\"timezoneoffset\":4}\n\n // Called when user clicks submit button\n // Checks for the result, sets localstorage and submits to the server\n submitKhanex(result) {\n if (DEBUG)\n console.log(\n \"DEBUG: submitKhanex result = \" + JSON.stringify(result)\n );\n var answer = result[\"complete\"];\n if (DEBUG) console.log(\"DEBUG: submitKhanex answer = \" + answer);\n var correct = result[\"complete\"] == 1 ? \"T\" : \"F\";\n var loganswer = \"answer:\" + (correct == \"T\" ? \"correct\" : \"no\"); // backward compatible\n var eventInfo = {\n event: \"khanex\",\n act: loganswer,\n answer: result[\"attempt_content\"],\n correct: correct,\n div_id: this.divid,\n };\n // log the response to the database\n this.logBookEvent(eventInfo); // in bookfuncs.js\n if (DEBUG)\n console.log(\n \"DEBUG: submitkhanex logbookevent = \" +\n JSON.stringify(eventInfo)\n );\n // log the fact that the user has attempted this khanex exercise to local storage\n localStorage.setItem(this.divid, \"true\");\n }\n}\n\n/*=================================\n== Find the custom HTML tags and ==\n== execute our code on them ==\n=================================*/\n$(document).on(\"runestone:login-complete\", function () {\n if (DEBUG) console.log(\"DEBUG: Khanex bind\");\n $(\"[data-component=khanex\").each(function (index) {\n if (DEBUG) console.log(\"DEBUG: Khanex rendering\");\n try {\n var khanex = new Khanex({ orig: this });\n window.componentMap[this.id] = khanex;\n setupCallback(khanex, khanex.quizname);\n } catch (err) {\n console.log(`Error rendering Khanex Exercise ${this.id}\n Details: ${err}`);\n console.log(err.stack);\n }\n });\n});\n\n// Sets up a call back function on the window containing the khanex component\n// We need to pass a reference to this khanex object so that it can be use during callback.\nfunction setupCallback(khanex, quizname) {\n if (typeof window.component_factory === \"undefined\") {\n window.component_factory = {};\n }\n var fn_name = \"khanex_\" + quizname; // Unique function name\n window.component_factory[fn_name] = function (result) {\n khanex.submitKhanex(result);\n };\n}\n"],"names":["Khanex","constructor","opts","super","orig","this","origElem","divid","id","resultsViewer","$","data","getIFrameAndQuizname","renderKhanex","caption","addCaption","html","p1","search","p2","iframe","slice","quizname","containerDiv","document","createElement","replaceWith","submitKhanex","result","correct","eventInfo","event","act","answer","div_id","logBookEvent","localStorage","setItem","on","each","index","khanex","window","componentMap","component_factory","fn_name","setupCallback","err","console","log","stack"],"sourceRoot":""}