Files
2026-08-01 15:00:14 +00:00

2 lines
15 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";(self.webpackChunkWebComponents=self.webpackChunkWebComponents||[]).push([[919],{9919:(e,t,i)=>{i.r(t),i.d(t,{default:()=>n});var s=i(78673);class r extends s.A{constructor(e){super(e);var t=(e=e||{}).orig;this.origElem=t,this.useRunestoneServices=e.useRunestoneServices,this.multipleanswers=!1,this.divid=t.id,this.parseBooleanAttribute(this.origElem,"data-multipleanswers")&&(this.multipleanswers=!0),this.children=this.origElem.childNodes,this.random=!1,eBookConfig.peer?this.random=!1:this.parseBooleanAttribute(this.origElem,"data-random")&&(this.random=!0),this.correct=null,this.didSubmit=!1,this.answerList=[],this.correctList=[],this.correctIndexList=[],this.feedbackList=[],this.question=null,this.caption="Multiple Choice",this.findAnswers(),this.findQuestion(),this.findFeedbacks(),this.createCorrectList(),this.createMCForm(),this.addCaption("runestone"),this.checkServer("mChoice",!0),this.queueMathJax(this.containerDiv),"undefined"!=typeof Prism&&Prism.highlightAllUnder(this.containerDiv)}findQuestion(){const e=this.origElem.parentElement.querySelector(".exercise-statement");if(e)this.question=e;else{for(var t,i=0;i<this.origElem.childNodes.length;i++)if("LI"===this.origElem.childNodes[i].nodeName){t=this.origElem.childNodes[i].outerHTML;break}var s=this.origElem.innerHTML.split(t);this.question=s[0]}}findAnswers(){for(var e=[],t=0;t<this.children.length;t++){const i=this.children[t];i.nodeType===Node.ELEMENT_NODE&&i.matches("[data-component=answer]")&&e.push(i)}for(var i=0;i<e.length;i++){var s=e[i].id,r=!1;e[i].hasAttribute("data-correct")&&(r=!0);var n={id:s,correct:r,content:e[i].innerHTML};this.answerList.push(n)}}findFeedbacks(){for(var e=0;e<this.children.length;e++){const t=this.children[e];t.nodeType===Node.ELEMENT_NODE&&t.matches("[data-component=feedback]")&&this.feedbackList.push(t.innerHTML)}}createCorrectList(){for(var e=0;e<this.answerList.length;e++)this.answerList[e].correct&&(this.correctList.push(this.answerList[e].id),this.correctIndexList.push(e))}createMCForm(){this.renderMCContainer(),this.renderMCForm(),this.renderMCfeedbackDiv(),this.origElem.replaceWith(this.containerDiv)}renderMCContainer(){this.containerDiv=document.createElement("div"),this.questionDiv=document.createElement("div"),"string"==typeof this.question?this.questionDiv.innerHTML=this.question:this.questionDiv.appendChild(this.question),this.questionDiv.id=this.divid+"_prompt",this.questionDiv.className="exercise-statement",this.containerDiv.appendChild(this.questionDiv);const e=this.origElem.getAttribute("class");e&&this.containerDiv.classList.add(...e.split(" ").filter(Boolean)),this.containerDiv.classList.add("mchoice"),this.containerDiv.id=this.divid}renderMCForm(){this.optsForm=document.createElement("form"),this.optsForm.id=this.divid+"_form",this.optsForm.method="get",this.optsForm.action="",this.optsForm.onsubmit=function(){return!1},this.optsFieldSet=document.createElement("fieldset"),this.optsFieldSet.setAttribute("role","radiogroup"),this.optsFieldSet.setAttribute("aria-labelledby",this.divid+"_prompt"),this.optsForm.appendChild(this.optsFieldSet),this.renderMCFormOpts(),this.renderMCFormButtons();let e=document.createElement("legend");this.multipleanswers?e.textContent="Choose all that apply":e.textContent="Choose one",this.optsFieldSet.appendChild(e),this.containerDiv.appendChild(this.optsForm)}renderMCFormOpts(){this.optionArray=[];var e="radio";this.multipleanswers&&(e="checkbox"),this.indexArray=[];for(var t=0;t<this.answerList.length;t++)this.indexArray.push(t);this.random&&this.randomizeAnswers();let i=this,s=function(){i.isAnswered=!0};for(var r=0;r<this.answerList.length;r++){var n=this.indexArray[r],o=this.divid+"_opt_"+n,a=document.createElement("label");a.className="mchoice-option";var c=this.answerList[n].content,h="";c.startsWith("<p>")&&(h="<p>",c=c.slice(3)),a.innerHTML=`${h}<input type="${e}" name="group1" value="${n}" id="${o}" class="mchoice-input">${String.fromCharCode("A".charCodeAt(0)+r)}. ${c}`;var d={input:a.querySelector("input"),label:a};d.input.onclick=s,this.optionArray.push(d),this.optsFieldSet.appendChild(a)}}renderMCFormButtons(){this.submitButton=document.createElement("button"),this.submitButton.textContent="Check Me",this.submitButton.className="btn btn-success",this.submitButton.name="do answer",this.submitButton.type="button",this.multipleanswers?this.submitButton.addEventListener("click",function(){this.processMCMASubmission(!0)}.bind(this),!1):this.submitButton.addEventListener("click",function(e){e.preventDefault(),this.processMCMFSubmission(!0)}.bind(this),!1),this.optsForm.appendChild(this.submitButton),this.useRunestoneServices&&!eBookConfig.peer&&(this.compareButton=document.createElement("button"),this.compareButton.className="btn btn-default",this.compareButton.id=this.divid+"_bcomp",this.compareButton.disabled=!0,this.compareButton.name="compare",this.compareButton.textContent="Compare me",this.compareButton.addEventListener("click",function(){this.compareAnswers(this.divid)}.bind(this),!1),this.optsForm.appendChild(this.compareButton))}renderMCfeedbackDiv(){this.feedBackDiv=document.createElement("div"),this.feedBackDiv.id=this.divid+"_feedback",this.feedBackDiv.setAttribute("aria-live","polite"),this.feedBackDiv.setAttribute("role","status"),this.containerDiv.appendChild(this.feedBackDiv)}randomizeAnswers(){for(var e,t,i=this.indexArray.length;0!==i;){t=Math.floor(Math.random()*i),i-=1,e=this.indexArray[i],this.indexArray[i]=this.indexArray[t],this.indexArray[t]=e;var s=this.feedbackList[i];this.feedbackList[i]=this.feedbackList[t],this.feedbackList[t]=s}}restoreAnswers(e){e.answer||(e.answer="");for(var t=e.answer.split(","),i=0;i<t.length;i++)for(var s=t[i],r=0;r<this.optionArray.length;r++)this.optionArray[r].input.value==s&&(this.optionArray[r].input.checked=!0);this.multipleanswers?this.processMCMASubmission(!1):this.processMCMFSubmission(!1)}checkLocalStorage(){var e,t;if(!this.graderactive&&localStorage.length>0){var i=localStorage.getItem(this.localStorageKey());let o=!1;if(null!==i){try{t=(e=JSON.parse(i)).answer.split(",")}catch(e){console.log(`Error parsing stored mchoice data for ${this.divid}: ${e.message}`),o=!0}if(o||e.timestamp<eBookConfig.termStartDate)return void localStorage.removeItem(this.localStorageKey());for(var s=0;s<t.length;s++)for(var r=t[s],n=0;n<this.optionArray.length;n++)this.optionArray[n].input.value==r&&(this.optionArray[n].input.checked=!0);this.useRunestoneServices&&(this.enableMCComparison(),this.getSubmittedOpts(),this.multipleanswers?this.logMCMAsubmission():this.logMCMFsubmission())}}}setLocalStorage(e){var t=new Date,i={answer:e.answer,timestamp:t,correct:e.correct};localStorage.setItem(this.localStorageKey(),JSON.stringify(i))}processMCMASubmission(e){this.getSubmittedOpts(),this.scoreMCMASubmission(),this.setLocalStorage({correct:this.correct?"T":"F",answer:this.givenArray.join(",")}),e&&this.logMCMAsubmission(),!eBookConfig.peer||eBookConfig.isInstructor?(this.renderMCMAFeedBack(),this.useRunestoneServices&&this.enableMCComparison()):eBookConfig.peer&&"async"===eBookConfig.peerMode&&"undefined"!=typeof studentVoteCount&&studentVoteCount>1?this.renderMCMAFeedBack():(this.feedBackDiv.innerHTML="<p>Your answer has been recorded</p>",this.feedBackDiv.className="alert alert-info"),this.didSubmit=!0}getSubmittedOpts(){var e;this.singlefeedback="",this.feedbackString="",this.givenArray=[],this.givenlog="";for(var t=this.optsForm.elements.group1,i=0;i<t.length;i++)t[i].checked&&(e=parseInt(t[i].value,10),this.givenArray.push(e),this.feedbackString+=`<li value="${i+1}">${this.feedbackList[i]}</li>`,this.givenlog+=e+",",this.singlefeedback=this.feedbackList[i]);this.givenArray.sort(((e,t)=>e-t))}checkCurrentAnswer(){this.getSubmittedOpts(),0!==this.givenArray.length&&(this.multipleanswers?this.scoreMCMASubmission():this.scoreMCMFSubmission())}async logCurrentAnswer(e){this.multipleanswers?await this.logMCMAsubmission(e):await this.logMCMFsubmission(e)}renderFeedback(){this.multipleanswers?this.renderMCMAFeedBack():this.renderMCMFFeedback(),this.queueMathJax(this.feedBackDiv)}scoreMCMASubmission(){this.correctCount=0;for(var e=0,t=0;e<this.correctIndexList.length&&t<this.givenArray.length;)this.givenArray[t]<this.correctIndexList[e]?t++:this.givenArray[t]==this.correctIndexList[e]?(this.correctCount++,t++,e++):e++;var i=this.givenArray.length,s=this.correctCount,r=this.correctList.length;this.answer=this.givenArray.join(","),this.correct=s===r&&r===i,this.percent=i===r?s/r:s/Math.max(i,r)}async logMCMAsubmission(e){var t=this.answer||"",i=this.correct||!1;let s={event:"mChoice",act:"answer:"+t+":"+(1==i?"correct":"no"),answer:t.toString(),correct:i,div_id:this.divid};eBookConfig.peer&&"undefined"!=typeof studentVoteCount&&(s.act=s.act+`:vote${studentVoteCount}`),void 0!==e&&(s.sid=e),await this.logBookEvent(s)}renderMCMAFeedBack(){var e="answers",t=this.givenArray.length;1===t&&(e="answer");var i=this.correctCount,s=this.correctList.length,r=this.feedbackString;this.correct?(this.feedBackDiv.innerHTML=`✔️ <ol type="A">${r}</ul>`,this.feedBackDiv.className="alert alert-info"):(this.feedBackDiv.innerHTML=`✖️ You gave ${t} ${e} and got ${i} correct of ${s} needed.<ol type="A">${r}</ul>`,this.feedBackDiv.className="alert alert-danger"),this.queueMathJax(this.feedBackDiv)}processMCMFSubmission(e){this.getSubmittedOpts(),this.scoreMCMFSubmission(),this.setLocalStorage({correct:this.correct?"T":"F",answer:this.givenArray.join(",")}),e&&this.logMCMFsubmission(),!eBookConfig.peer||eBookConfig.isInstructor?(this.renderMCMFFeedback(),this.useRunestoneServices&&this.enableMCComparison()):eBookConfig.peer&&"async"===eBookConfig.peerMode&&"undefined"!=typeof studentVoteCount&&studentVoteCount>1?this.renderMCMAFeedBack():(this.feedBackDiv.innerHTML="<p>Your answer has been recorded</p>",this.feedBackDiv.className="alert alert-info"),this.didSubmit=!0}scoreMCMFSubmission(){this.answer=this.givenArray[0],this.givenArray[0]==this.correctIndexList[0]?(this.correct=!0,this.percent=1):null!=this.givenArray[0]&&(this.correct=!1,this.percent=0)}async logMCMFsubmission(e){var t=this.givenArray.length>0?this.givenArray[0]:"",i=this.givenArray[0]==this.correctIndexList[0]?"T":"F";let s={event:"mChoice",act:"answer:"+t+":"+("T"==i?"correct":"no"),answer:t.toString(),correct:i,div_id:this.divid};eBookConfig.peer&&"undefined"!=typeof studentVoteCount&&(s.act=s.act+`:vote${studentVoteCount}`),void 0!==e&&(s.sid=e),await this.logBookEvent(s)}renderMCMFFeedback(){let e=this.givenArray[0]==this.correctIndexList[0],t=this.singlefeedback;e?(this.feedBackDiv.innerHTML="✔️ "+t,this.feedBackDiv.className="alert alert-info"):(null==t&&(t=""),this.feedBackDiv.innerHTML="✖️ "+t,this.feedBackDiv.className="alert alert-danger"),this.queueMathJax(this.feedBackDiv)}enableMCComparison(){eBookConfig.enableCompareMe&&(this.compareButton.disabled=!1)}instructorMchoiceModal(e){var t="<table><tr><th>Student</th><th>Answer(s)</th></tr>";for(var i in e)t+="<tr><td>"+e[i][0]+"</td><td>"+e[i][1]+"</td></tr>";return t+"</table>"}compareModal(e,t,i){var s=e.detail,r=s.answerDict,n=s.misc,o=Object.keys(r).sort(),a="<table>";a+="<tr><th>Answer</th><th>Percent</th></tr>";var c="";for(var h in o){c=o[h]===n.correct?"success":"info",a+="<tr><td>"+o[h]+"</td><td class='compare-me-progress'>";var d=r[o[h]]+"%";a+="<div class='progress'>",a+=" <div class='progress-bar progress-bar-"+c+"' style='width:"+d+";'>"+d,a+=" </div>",a+="</div></td></tr>"}a+="</table>","unavailable"!==n.yourpct&&(a+="<br /><p>You have "+n.yourpct+"% correct for all questions</p>"),void 0!==s.reslist&&(a+=this.instructorMchoiceModal(s.reslist));const l=document.createElement("div");l.style.position="fixed",l.style.inset="0",l.style.background="rgba(0,0,0,0.5)",l.style.zIndex="9999";const u=document.createElement("div");u.style.maxWidth="720px",u.style.margin="10vh auto",u.style.background="#fff",u.style.borderRadius="6px",u.style.boxShadow="0 2px 12px rgba(0,0,0,0.3)",u.style.padding="16px";const m=document.createElement("div"),p=document.createElement("button");p.type="button",p.textContent="×",p.setAttribute("aria-label","Close"),p.style.float="right",p.className="btn btn-light",p.onclick=function(){document.body.removeChild(l)};const v=document.createElement("h4");v.className="modal-title",v.textContent="Distribution of Answers",m.appendChild(p),m.appendChild(v);const g=document.createElement("div");g.innerHTML=a,u.appendChild(m),u.appendChild(g),l.appendChild(u),document.body.appendChild(l)}async compareAnswers(){var e={};e.div_id=this.divid,e.course_name=eBookConfig.course;try{const t=new URLSearchParams(e),i=await fetch(`${eBookConfig.new_server_prefix}/assessment/getaggregateresults?${t.toString()}`),s=await i.json();this.compareModal(s)}catch(e){console.error("Error fetching aggregate results:",e)}}disableInteraction(){for(var e=0;e<this.optionArray.length;e++)this.optionArray[e].input.disabled=!0}enableInteraction(){for(var e=0;e<this.optionArray.length;e++)this.optionArray[e].input.disabled=!1}}document.addEventListener("runestone:login-complete",(function(){document.querySelectorAll("[data-component=multiplechoice]").forEach((function(e,t){var i={orig:e,useRunestoneServices:eBookConfig.useRunestoneServices};e.closest("[data-component=timedAssessment]")||(window.componentMap[e.id]=new r(i))}))}));class n extends r{constructor(e){super(e),this.containerDiv.classList.add("runestone"),this.needsReinitialization=!0,this.renderTimedIcon(this.MCContainer),this.hideButtons()}renderTimedIcon(e){var t=document.createElement("div"),i=document.createElement("img");i.src="../_static/clock.png",i.style.width="15px",i.style.height="15px",t.className="timeTip",t.title="",t.appendChild(i),e&&(e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t))}hideButtons(){this.submitButton&&(this.submitButton.setAttribute("disabled","true"),this.submitButton.style.display="none"),this.compareButton&&(this.compareButton.style.display="none")}renderMCMAFeedBack(){this.feedbackTimedMC()}renderMCMFFeedback(e,t){this.feedbackTimedMC()}feedbackTimedMC(){for(var e=0;e<this.indexArray.length;e++){var t=this.indexArray[e];this.feedBackEachArray[e].innerHTML=String.fromCharCode(65+e)+". "+this.feedbackList[e];var i=this.answerList[t].id;this.correctList.indexOf(i)>=0?this.feedBackEachArray[e].classList.add("alert","alert-success"):this.feedBackEachArray[e].classList.add("alert","alert-danger")}}renderMCFormOpts(){super.renderMCFormOpts(),this.feedBackEachArray=[];for(var e=0;e<this.answerList.length;e++){var t=this.indexArray[e],i=document.createElement("div");i.id=this.divid+"_eachFeedback_"+t,i.classList.add("eachFeedback"),this.feedBackEachArray.push(i),this.optsForm.appendChild(i)}}checkCorrectTimedMCMA(){switch(this.correctCount===this.correctList.length&&this.correctList.length===this.givenArray.length?this.correct=!0:0!==this.givenArray.length?this.correct=!1:this.correct=null,this.correct){case!0:return"T";case!1:return"F";default:return null}}checkCorrectTimedMCMF(){switch(this.correct){case!0:return"T";case!1:return"F";default:return null}}checkCorrectTimed(){return this.multipleanswers?this.checkCorrectTimedMCMA():this.checkCorrectTimedMCMF()}hideFeedback(){for(var e=0;e<this.feedBackEachArray.length;e++)this.feedBackEachArray[e].style.display="none"}reinitializeListeners(){let e=this,t=function(){e.isAnswered=!0};for(let e of this.optionArray)e.input.onclick=t}}void 0===window.component_factory&&(window.component_factory={}),window.component_factory.multiplechoice=function(e){return e.timed?new n(e):new r(e)}}}]);
//# sourceMappingURL=919.418ace202c450968.js.map