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AE,MAAO4F,GACLC,QAAQC,IAAI,uCAAuC/F,KAAKK,gCAC7CwF,IACf,CAER,GACJ,IC/We,MAAMyC,UAAyB3I,EAC1C,WAAAC,CAAYC,GACRC,MAAMD,GACNG,KAAKuI,gBAAgBvI,KAAKsB,cAC1BtB,KAAK2C,SAAU,EACf3C,KAAKwI,aACT,CACA,WAAAA,GACI9H,EAAEV,KAAKiD,cAAcwF,MACzB,CACA,eAAAF,CAAgBG,GAGZ,IAAIC,EAAcpH,SAASC,cAAc,OACrCoH,EAAWrH,SAASC,cAAc,OACtCd,EAAEkI,GAAUrG,KAAK,CACbsG,IAAK,uBACLC,MAAO,2BAEXH,EAAYI,UAAY,UACxBJ,EAAYK,MAAQ,GACpBL,EAAY7G,YAAY8G,GACxBlI,EAAEgI,GAAWO,QAAQN,EACzB,CACA,iBAAAO,GACI,MAAO,GACX,CACA,YAAAC,GACIzI,EAAEV,KAAK4C,aAAa6F,MACxB,OAGoC,IAA7BX,OAAOsB,oBACdtB,OAAOsB,kBAAoB,CAAC,GAGhCtB,OAAOsB,kBAAkBC,YAAc,SAAUxJ,GAC7C,OAAIA,EAAKyJ,MACE,IAAIhB,EAAiBzI,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 <p> 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 this.mathjax = true;\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.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.jOptionsDiv.appendChild(this.jTextArea);\n this.jTextArea.onchange = function () {\n this.isAnswered = true;\n if (this.isTimed) {\n this.feedbackDiv.innerHTML = \"Your answer is automatically saved.\";\n } else {\n this.feedbackDiv.innerHTML = \"Your answer has not been saved yet!\";\n }\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 <https://stackoverflow.com/questions/3014018/how-to-detect-when-mathjax-is-fully-loaded>`_\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 value = value.replace(/\\n/g, \"<br/>\"); // add line breaks\n $(this.renderedAnswer).html(value);\n this.queueMathJax(this.renderedAnswer);\n }\n }\n\n async checkCurrentAnswer() {\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 }\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 <html>\n <head>\n </head>\n <body>\n <img src=\"${this.attachURL}\" alt=\"Attachment\" >\n </body>\n </html>\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.isTimed = true;\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","jTextArea","self","onchange","isAnswered","attr","css","rows","cols","isTimed","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","html","getElementById","val","setLocalStorage","answer","timestamp","Date","sid","event","act","div_id","logBookEvent","uploadFile","key","localStorageKey","localStorage","setItem","JSON","stringify","checkLocalStorage","length","ex","getItem","parse","err","console","log","message","removeItem","text","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":""}