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AAgBtI,KAAKsB,cAC1BtB,KAAKuI,aACT,CACA,WAAAA,GACI7H,EAAEV,KAAKiD,cAAcuF,MACzB,CACA,eAAAF,CAAgBG,GAGZ,IAAIC,EAAcnH,SAASC,cAAc,OACrCmH,EAAWpH,SAASC,cAAc,OACtCd,EAAEiI,GAAUnG,KAAK,CACboG,IAAK,uBACLC,MAAO,2BAEXH,EAAYI,UAAY,UACxBJ,EAAYK,MAAQ,GACpBL,EAAY5G,YAAY6G,GACxBjI,EAAE+H,GAAWO,QAAQN,EACzB,CACA,iBAAAO,GACI,MAAO,GACX,CACA,YAAAC,GACIxI,EAAEV,KAAK4C,aAAa4F,MACxB,OAGoC,IAA7BX,OAAOsB,oBACdtB,OAAOsB,kBAAoB,CAAC,GAGhCtB,OAAOsB,kBAAkBC,YAAc,SAAUvJ,GAC7C,OAAIA,EAAKwJ,MACE,IAAIhB,EAAiBxI,GAEzB,IAAIF,EAAYE,EAC3B,C","sources":["webpack://WebComponents/./runestone/shortanswer/js/shortanswer.js","webpack://WebComponents/./runestone/shortanswer/js/timed_shortanswer.js"],"sourcesContent":["/*==========================================\n======= Master shortanswer.js ========\n============================================\n=== This file contains the JS for ===\n=== the Runestone shortanswer component. ===\n============================================\n=== Created by ===\n=== Isaiah Mayerchak ===\n=== 7/2/15 ===\n=== Brad Miller ===\n=== 2019 ===\n==========================================*/\n\nimport RunestoneBase from \"../../common/js/runestonebase.js\";\nimport \"./../css/shortanswer.css\";\n\nexport default class ShortAnswer extends RunestoneBase {\n constructor(opts) {\n super(opts);\n if (opts) {\n var orig = opts.orig; // entire

element that will be replaced by new HTML\n this.useRunestoneServices =\n opts.useRunestoneServices || eBookConfig.useRunestoneServices;\n this.origElem = orig;\n this.divid = orig.id;\n this.question = this.origElem.innerHTML;\n this.optional = false;\n this.attachURL = opts.attachURL;\n if ($(this.origElem).is(\"[data-optional]\")) {\n this.optional = true;\n }\n if ($(this.origElem).is(\"[data-mathjax]\")) {\n this.mathjax = true;\n }\n if ($(this.origElem).is(\"[data-attachment]\")) {\n this.attachment = true;\n }\n this.placeholder =\n $(this.origElem).data(\"placeholder\") ||\n \"Write your answer here\";\n this.renderHTML();\n this.caption = \"shortanswer\";\n this.addCaption(\"runestone\");\n this.checkServer(\"shortanswer\", true);\n if (typeof Prism !== \"undefined\") {\n Prism.highlightAllUnder(this.containerDiv);\n }\n }\n }\n\n renderHTML() {\n this.containerDiv = document.createElement(\"div\");\n this.containerDiv.id = this.divid;\n $(this.containerDiv).addClass(this.origElem.getAttribute(\"class\"));\n this.newForm = document.createElement(\"form\");\n this.newForm.id = this.divid + \"_journal\";\n this.newForm.name = this.newForm.id;\n this.newForm.action = \"\";\n this.containerDiv.appendChild(this.newForm);\n this.fieldSet = document.createElement(\"fieldset\");\n this.newForm.appendChild(this.fieldSet);\n this.firstLegendDiv = document.createElement(\"div\");\n this.firstLegendDiv.innerHTML = this.question;\n $(this.firstLegendDiv).addClass(\"journal-question\");\n this.fieldSet.appendChild(this.firstLegendDiv);\n this.jInputDiv = document.createElement(\"div\");\n this.jInputDiv.id = this.divid + \"_journal_input\";\n this.fieldSet.appendChild(this.jInputDiv);\n this.jOptionsDiv = document.createElement(\"div\");\n $(this.jOptionsDiv).addClass(\"journal-options\");\n this.jInputDiv.appendChild(this.jOptionsDiv);\n this.jLabel = document.createElement(\"label\");\n $(this.jLabel).addClass(\"radio-inline\");\n this.jOptionsDiv.appendChild(this.jLabel);\n this.jTextArea = document.createElement(\"textarea\");\n let self = this;\n this.jTextArea.onchange = function() {\n self.isAnswered = true;\n };\n this.jTextArea.id = this.divid + \"_solution\";\n $(this.jTextArea).attr(\"aria-label\", \"textarea\");\n this.jTextArea.placeholder = this.placeholder;\n $(this.jTextArea).css(\"display:inline, width:530px\");\n $(this.jTextArea).addClass(\"form-control\");\n this.jTextArea.rows = 4;\n this.jTextArea.cols = 50;\n this.jLabel.appendChild(this.jTextArea);\n this.jTextArea.onchange = function() {\n this.feedbackDiv.innerHTML = \"Your answer has not been saved yet!\";\n $(this.feedbackDiv).removeClass(\"alert-success\");\n $(this.feedbackDiv).addClass(\"alert alert-danger\");\n }.bind(this);\n this.fieldSet.appendChild(document.createElement(\"br\"));\n if (this.mathjax) {\n this.renderedAnswer = document.createElement(\"div\");\n $(this.renderedAnswer).addClass(\"latexoutput\");\n this.fieldSet.appendChild(this.renderedAnswer);\n }\n this.buttonDiv = document.createElement(\"div\");\n this.fieldSet.appendChild(this.buttonDiv);\n this.submitButton = document.createElement(\"button\");\n $(this.submitButton).addClass(\"btn btn-success\");\n this.submitButton.type = \"button\";\n this.submitButton.textContent = \"Save\";\n this.submitButton.onclick = function() {\n this.checkCurrentAnswer();\n this.logCurrentAnswer();\n this.renderFeedback();\n }.bind(this);\n this.buttonDiv.appendChild(this.submitButton);\n this.randomSpan = document.createElement(\"span\");\n this.randomSpan.innerHTML = \"Instructor's Feedback\";\n this.fieldSet.appendChild(this.randomSpan);\n this.otherOptionsDiv = document.createElement(\"div\");\n $(this.otherOptionsDiv).css(\"padding-left:20px\");\n $(this.otherOptionsDiv).addClass(\"journal-options\");\n this.fieldSet.appendChild(this.otherOptionsDiv);\n // add a feedback div to give user feedback\n this.feedbackDiv = document.createElement(\"div\");\n //$(this.feedbackDiv).addClass(\"bg-info form-control\");\n //$(this.feedbackDiv).css(\"width:530px, background-color:#eee, font-style:italic\");\n $(this.feedbackDiv).css(\"width:530px, font-style:italic\");\n this.feedbackDiv.id = this.divid + \"_feedback\";\n this.feedbackDiv.innerHTML = \"You have not answered this question yet.\";\n $(this.feedbackDiv).addClass(\"alert alert-danger\");\n //this.otherOptionsDiv.appendChild(this.feedbackDiv);\n this.fieldSet.appendChild(this.feedbackDiv);\n if (this.attachment) {\n let attachDiv = document.createElement(\"div\")\n if (this.graderactive ) {\n // If in grading mode make a button to create a popup with the image\n let viewButton = document.createElement(\"button\")\n viewButton.type = \"button\"\n viewButton.innerHTML = \"View Attachment\"\n viewButton.onclick = this.viewFile.bind(this);\n attachDiv.appendChild(viewButton);\n } else {\n // Otherwise make a button for the student to select a file to upload.\n this.fileUpload = document.createElement(\"input\")\n this.fileUpload.type = \"file\";\n this.fileUpload.id = `${this.divid}_fileme`;\n attachDiv.appendChild(this.fileUpload);\n }\n this.containerDiv.appendChild(attachDiv);\n }\n //this.fieldSet.appendChild(document.createElement(\"br\"));\n $(this.origElem).replaceWith(this.containerDiv);\n // This is a stopgap measure for when MathJax is not loaded at all. There is another\n // more difficult case that when MathJax is loaded asynchronously we will get here\n // before MathJax is loaded. In that case we will need to implement something\n // like `the solution described here `_\n if (typeof MathJax !== \"undefined\") {\n this.queueMathJax(this.containerDiv);\n }\n }\n\n renderMath(value) {\n if (this.mathjax) {\n value = value.replace(/\\$\\$(.*?)\\$\\$/g, \"\\\\[ $1 \\\\]\");\n value = value.replace(/\\$(.*?)\\$/g, \"\\\\( $1 \\\\)\");\n $(this.renderedAnswer).text(value);\n this.queueMathJax(this.renderedAnswer);\n }\n }\n\n checkCurrentAnswer() {}\n\n async logCurrentAnswer(sid) {\n let value = $(document.getElementById(this.divid + \"_solution\")).val();\n this.renderMath(value);\n this.setLocalStorage({\n answer: value,\n timestamp: new Date(),\n });\n let data = {\n event: \"shortanswer\",\n act: value,\n answer: value,\n div_id: this.divid,\n };\n if (typeof sid !== \"undefined\") {\n data.sid = sid;\n }\n await this.logBookEvent(data);\n if (this.attachment) {\n await this.uploadFile();\n }\n }\n\n renderFeedback() {\n this.feedbackDiv.innerHTML = \"Your answer has been saved.\";\n $(this.feedbackDiv).removeClass(\"alert-danger\");\n $(this.feedbackDiv).addClass(\"alert alert-success\");\n }\n setLocalStorage(data) {\n if (!this.graderactive) {\n let key = this.localStorageKey();\n localStorage.setItem(key, JSON.stringify(data));\n }\n }\n checkLocalStorage() {\n // Repopulates the short answer text\n // which was stored into local storage.\n var answer = \"\";\n if (this.graderactive) {\n return;\n }\n var len = localStorage.length;\n if (len > 0) {\n var ex = localStorage.getItem(this.localStorageKey());\n if (ex !== null) {\n try {\n var storedData = JSON.parse(ex);\n answer = storedData.answer;\n } catch (err) {\n // error while parsing; likely due to bad value stored in storage\n console.log(err.message);\n localStorage.removeItem(this.localStorageKey());\n return;\n }\n let solution = $(\"#\" + this.divid + \"_solution\");\n solution.text(answer);\n this.renderMath(answer);\n this.feedbackDiv.innerHTML =\n \"Your current saved answer is shown above.\";\n $(this.feedbackDiv).removeClass(\"alert-danger\");\n $(this.feedbackDiv).addClass(\"alert alert-success\");\n }\n }\n }\n restoreAnswers(data) {\n // Restore answers from storage retrieval done in RunestoneBase\n // sometimes data.answer can be null\n if (!data.answer) {\n data.answer = \"\";\n }\n this.answer = data.answer;\n this.jTextArea.value = this.answer;\n this.renderMath(this.answer);\n\n let p = document.createElement(\"p\");\n this.jInputDiv.appendChild(p);\n var tsString = \"\";\n if (data.timestamp) {\n tsString = new Date(data.timestamp).toLocaleString();\n } else {\n tsString = \"\";\n }\n $(p).text(tsString);\n if (data.last_answer) {\n this.current_answer = \"ontime\";\n let toggle_answer_button = document.createElement(\"button\");\n toggle_answer_button.type = \"button\";\n $(toggle_answer_button).text(\"Show Late Answer\");\n $(toggle_answer_button).addClass(\"btn btn-warning\");\n $(toggle_answer_button).css(\"margin-left\", \"5px\");\n\n $(toggle_answer_button).click(\n function() {\n var display_timestamp, button_text;\n if (this.current_answer === \"ontime\") {\n this.jTextArea.value = data.last_answer;\n this.answer = data.last_answer;\n display_timestamp = new Date(\n data.last_timestamp\n ).toLocaleString();\n button_text = \"Show on-Time Answer\";\n this.current_answer = \"late\";\n } else {\n this.jTextArea.value = data.answer;\n this.answer = data.answer;\n display_timestamp = tsString;\n button_text = \"Show Late Answer\";\n this.current_answer = \"ontime\";\n }\n this.renderMath(this.answer);\n $(p).text(`Submitted: ${display_timestamp}`);\n $(toggle_answer_button).text(button_text);\n }.bind(this)\n );\n\n this.buttonDiv.appendChild(toggle_answer_button);\n }\n let feedbackStr = \"Your current saved answer is shown above.\";\n if (typeof data.score !== \"undefined\") {\n feedbackStr = `Score: ${data.score}`;\n }\n if (data.comment) {\n feedbackStr += ` -- ${data.comment}`;\n }\n this.feedbackDiv.innerHTML = feedbackStr;\n\n $(this.feedbackDiv).removeClass(\"alert-danger\");\n $(this.feedbackDiv).addClass(\"alert alert-success\");\n }\n\n disableInteraction() {\n this.jTextArea.disabled = true;\n }\n\n async uploadFile() {\n const files = this.fileUpload.files\n const data = new FormData()\n if (this.fileUpload.files.length > 0) {\n data.append('file', files[0])\n fetch(`/ns/logger/upload/${this.divid}`, {\n method: 'POST',\n body: data\n })\n .then(response => response.json())\n .then(data => {\n console.log(data)\n })\n .catch(error => {\n console.error(error)\n })\n }\n }\n\n viewFile() {\n // Get the URL from the S3 API -- saved when we display in grader mode\n if (this.attachURL) {\n //window.open(this.attachURL, \"_blank\");\n const image_window = window.open(\"\", \"_blank\")\n image_window.document.write(`\n \n \n \n \n \"Attachment\"\n \n \n `);\n } else {\n alert(\"No attachment for this student.\")\n }\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 $(\"[data-component=shortanswer]\").each(function() {\n if ($(this).closest(\"[data-component=timedAssessment]\").length == 0) {\n // If this element exists within a timed component, don't render it here\n try {\n window.componentMap[this.id] = new ShortAnswer({\n orig: this,\n useRunestoneServices: eBookConfig.useRunestoneServices,\n });\n } catch (err) {\n console.log(`Error rendering ShortAnswer Problem ${this.id}\n Details: ${err}`);\n }\n }\n });\n});\n","import ShortAnswer from \"./shortanswer.js\";\n\nexport default class TimedShortAnswer extends ShortAnswer {\n constructor(opts) {\n super(opts);\n this.renderTimedIcon(this.containerDiv);\n this.hideButtons();\n }\n hideButtons() {\n $(this.submitButton).hide();\n }\n renderTimedIcon(component) {\n // renders the clock icon on timed components. The component parameter\n // is the element that the icon should be appended to.\n var timeIconDiv = document.createElement(\"div\");\n var timeIcon = document.createElement(\"img\");\n $(timeIcon).attr({\n src: \"../_static/clock.png\",\n style: \"width:15px;height:15px\",\n });\n timeIconDiv.className = \"timeTip\";\n timeIconDiv.title = \"\";\n timeIconDiv.appendChild(timeIcon);\n $(component).prepend(timeIconDiv);\n }\n checkCorrectTimed() {\n return \"I\"; // we ignore this in the grading\n }\n hideFeedback() {\n $(this.feedbackDiv).hide();\n }\n}\n\nif (typeof window.component_factory === \"undefined\") {\n window.component_factory = {};\n}\n\nwindow.component_factory.shortanswer = function (opts) {\n if (opts.timed) {\n return new TimedShortAnswer(opts);\n }\n return new ShortAnswer(opts);\n};\n"],"names":["ShortAnswer","constructor","opts","super","orig","this","useRunestoneServices","eBookConfig","origElem","divid","id","question","innerHTML","optional","attachURL","$","is","mathjax","attachment","placeholder","data","renderHTML","caption","addCaption","checkServer","Prism","highlightAllUnder","containerDiv","document","createElement","addClass","getAttribute","newForm","name","action","appendChild","fieldSet","firstLegendDiv","jInputDiv","jOptionsDiv","jLabel","jTextArea","self","onchange","isAnswered","attr","css","rows","cols","feedbackDiv","removeClass","bind","renderedAnswer","buttonDiv","submitButton","type","textContent","onclick","checkCurrentAnswer","logCurrentAnswer","renderFeedback","randomSpan","otherOptionsDiv","attachDiv","graderactive","viewButton","viewFile","fileUpload","replaceWith","MathJax","queueMathJax","renderMath","value","replace","text","sid","getElementById","val","setLocalStorage","answer","timestamp","Date","event","act","div_id","logBookEvent","uploadFile","key","localStorageKey","localStorage","setItem","JSON","stringify","checkLocalStorage","length","ex","getItem","parse","err","console","log","message","removeItem","restoreAnswers","p","tsString","toLocaleString","last_answer","current_answer","toggle_answer_button","click","display_timestamp","button_text","last_timestamp","feedbackStr","score","comment","disableInteraction","disabled","files","FormData","append","fetch","method","body","then","response","json","catch","error","window","open","write","alert","on","each","closest","componentMap","TimedShortAnswer","renderTimedIcon","hideButtons","hide","component","timeIconDiv","timeIcon","src","style","className","title","prepend","checkCorrectTimed","hideFeedback","component_factory","shortanswer","timed"],"sourceRoot":""}