"use strict";(self.webpackChunkWebComponents=self.webpackChunkWebComponents||[]).push([[350,380,506,817,850],{46424:(t,e,i)=>{i.r(e),i.d(e,{default:()=>h});var s=i(78673),n=(i(98139),i(9919),i(48819),i(73565),i(58529),i(83349),i(52420),i(14566));class r extends n.MatchingProblem{constructor(t){super(t),this.renderTimedIcon(this.containerDiv),this.hideButtons(),this.needsReinitialization=!0}hideButtons(){this.gradeBtn.style.display="none",this.helpBtn.style.display="none"}renderTimedIcon(t){var e=document.createElement("div"),i=document.createElement("img");i.src="../_static/clock.png",i.style.width="15px",i.style.height="15px",e.className="timeTip",e.title="",e.appendChild(i),t.prepend(e)}checkCorrectTimed(){switch(this.correct){case!0:return"T";case!1:return"F";default:return null}}hideFeedback(){this.connList.style.display="none"}reinitializeListeners(){}}void 0===window.component_factory&&(window.component_factory={}),window.component_factory.matching=function(t){return t.timed?new r(t):new n.MatchingProblem(t)};var a=i(10662),o=i(34089);class h extends s.A{constructor(t){super(t);var e=t.orig;this.origElem=e,this.divid=e.id,this.children=this.origElem.childNodes,this.visited=[],this.timeLimit=0,this.limitedTime=!1,isNaN((0,o.Qt)(this.origElem,"time"))||(this.timeLimit=60*parseInt((0,o.Qt)(this.origElem,"time"),10),this.startingTime=this.timeLimit,this.limitedTime=!0),this.showFeedback=!0,this.origElem.hasAttribute("data-no-feedback")&&(this.showFeedback=!1),this.origElem.hasAttribute("data-show-feedback")&&("yes"===this.origElem.getAttribute("data-show-feedback")?this.showFeedback=!0:this.showFeedback=!1),this.showResults=!1,this.origElem.hasAttribute("data-result")&&(this.showResults=!1),this.random=!1,this.origElem.hasAttribute("data-random")&&(this.random=!0),this.showTimer=!0,this.origElem.hasAttribute("data-no-timer")&&(this.showTimer=!1),this.origElem.hasAttribute("data-timer")&&("yes"===this.origElem.getAttribute("data-timer")?this.showTimer=!0:this.showTimer=!1),this.fullwidth=!1,this.origElem.hasAttribute("data-fullwidth")&&(this.fullwidth=!0),this.nopause=!1,this.origElem.hasAttribute("data-no-pause")&&(this.nopause=!0),this.origElem.hasAttribute("data-pause")&&("yes"===this.origElem.getAttribute("data-pause")?this.nopause=!1:this.nopause=!0),eBookConfig.enableScratchAC=!1,this.running=0,this.paused=0,this.done=0,this.taken=0,this.score=0,this.incorrect=0,this.correctStr="",this.incorrectStr="",this.skippedStr="",this.skipped=0,this.currentQuestionIndex=0,this.renderedQuestionArray=[],this.getNewChildren(),eBookConfig.enableDebug||(document.body.oncontextmenu=function(){return!1}),this.checkAssessmentStatus().then(function(){this.renderTimedAssess()}.bind(this))}getNewChildren(){this.newChildren=[];let t=this.origElem.querySelectorAll(".runestone");for(var e=0;e1&&this.renderNavControls(),this.renderSubmitButton(),this.renderFeedbackContainer(),this.useRunestoneServices=eBookConfig.useRunestoneServices,this.origElem.replaceWith(this.containerDiv),this.styleExamElements(),this.checkServer("timedExam",!0)}disableCutCopyPaste(){document.addEventListener("cut",(function(t){t.preventDefault()})),document.addEventListener("copy",(function(t){t.preventDefault()})),document.addEventListener("paste",(function(t){t.preventDefault()}))}renderContainer(){this.containerDiv=document.createElement("div"),this.fullwidth&&this.containerDiv.classList.add("timed-container-fullwidth"),this.containerDiv.classList.add("runestone-sphinx"),this.containerDiv.id=this.divid,this.timedDiv=document.createElement("div"),this.navDiv=document.createElement("div"),this.navDiv.classList.add("timed-center"),this.flagDiv=document.createElement("div"),this.flagDiv.classList.add("timed-center"),this.switchContainer=document.createElement("div"),this.switchContainer.classList.add("switchcontainer"),this.switchContainer.classList.add("ptx-runestone-container"),this.switchDiv=document.createElement("div"),this.timedDiv.appendChild(this.navDiv),this.timedDiv.appendChild(this.flagDiv),this.timedDiv.appendChild(this.switchContainer),this.switchContainer.appendChild(this.switchDiv),this.timedDiv.id="timed_Test",this.timedDiv.classList.add("timed-hidden")}renderTimer(){this.wrapperDiv=document.createElement("div"),this.timerContainer=document.createElement("P"),this.wrapperDiv.id=this.divid+"-startWrapper",this.timerContainer.id=this.divid+"-output",this.wrapperDiv.appendChild(this.timerContainer),this.showTime()}renderControlButtons(){this.controlDiv=document.createElement("div"),this.controlDiv.id="controls",this.controlDiv.classList.add("timed-center"),this.startBtn=document.createElement("button"),this.pauseBtn=document.createElement("button"),this.startBtn.setAttribute("class","btn btn-success"),this.startBtn.id="start",this.startBtn.tabIndex=0,this.startBtn.setAttribute("role","button"),this.startBtn.textContent="Start",this.startBtn.addEventListener("click",async function(){this.finishButton.classList.add("timed-hidden"),this.flagButton&&this.flagButton.classList.remove("timed-hidden");let t=document.createElement("p");t.innerHTML="Warning: You will not be able to continue the exam if you close this tab, close the window, or navigate away from this page! Make sure you click the Finish Exam button when you are done to submit your work!",this.controlDiv.appendChild(t),t.classList.add("examwarning"),await this.renderTimedQuestion(),this.startAssessment()}.bind(this),!1),this.pauseBtn.setAttribute("class","btn btn-default"),this.pauseBtn.id="pause",this.pauseBtn.disabled=!0,this.pauseBtn.tabIndex=0,this.pauseBtn.setAttribute("role","button"),this.pauseBtn.textContent="Pause",this.pauseBtn.addEventListener("click",function(){this.pauseAssessment()}.bind(this),!1),this.taken||this.controlDiv.appendChild(this.startBtn),this.nopause||this.controlDiv.appendChild(this.pauseBtn),this.containerDiv.appendChild(this.wrapperDiv),this.containerDiv.appendChild(this.controlDiv)}renderNavControls(){var t,e;this.pagNavList=document.createElement("ul"),this.pagNavList.classList.add("pagination"),this.leftContainer=document.createElement("li"),this.leftNavButton=document.createElement("button"),this.leftNavButton.innerHTML="‹ Prev",this.leftNavButton.setAttribute("aria-label","Previous"),this.leftNavButton.tabIndex=0,this.leftNavButton.setAttribute("role","button"),this.leftNavButton.classList.add("timed-cursor-pointer"),this.leftContainer.appendChild(this.leftNavButton),this.pagNavList.appendChild(this.leftContainer),this.flaggingPlace=document.createElement("ul"),this.flaggingPlace.classList.add("pagination"),this.flagContainer=document.createElement("li"),this.flagButton=document.createElement("button"),this.flagButton.classList.add("flagBtn"),this.flagButton.innerHTML="Flag Question",this.flagButton.setAttribute("aria-labelledby","Flag"),this.flagButton.tabIndex=5,this.flagButton.setAttribute("role","button"),this.flagButton.id="flag",this.flagButton.classList.add("timed-cursor-pointer"),this.flagContainer.appendChild(this.flagButton),this.flaggingPlace.appendChild(this.flagContainer),this.rightContainer=document.createElement("li"),this.rightNavButton=document.createElement("button"),this.rightNavButton.setAttribute("aria-label","Next"),this.rightNavButton.tabIndex=0,this.rightNavButton.setAttribute("role","button"),this.rightNavButton.id="next",this.rightNavButton.innerHTML="Next ›",this.rightNavButton.classList.add("timed-cursor-pointer"),this.rightContainer.appendChild(this.rightNavButton),this.pagNavList.appendChild(this.rightContainer),this.ensureButtonSafety(),this.navDiv.appendChild(this.pagNavList),this.flagDiv.appendChild(this.flaggingPlace),this.break=document.createElement("br"),this.navDiv.appendChild(this.break),this.qNumList=document.createElement("ul"),this.qNumList.id="pageNums",this.qNumWrapperList=document.createElement("ul"),this.qNumWrapperList.classList.add("pagination");for(var i=0;i ul > li")[t]}async navigateAway(){"broken_exam"==this.renderedQuestionArray[this.currentQuestionIndex].state&&this.qNumItem(this.currentQuestionIndex)?.classList.add("broken"),"exam_ended"==this.renderedQuestionArray[this.currentQuestionIndex].state&&this.qNumItem(this.currentQuestionIndex)?.classList.add("toolate"),this.renderedQuestionArray[this.currentQuestionIndex].question.isAnswered&&(this.qNumItem(this.currentQuestionIndex)?.classList.add("answered"),await this.renderedQuestionArray[this.currentQuestionIndex].question.checkCurrentAnswer(),this.done||await this.renderedQuestionArray[this.currentQuestionIndex].question.logCurrentAnswer())}async handleNextPrev(t){this.taken||await this.navigateAway();var e=t.target.textContent;if(e.match(/Next/)){if(this.rightContainer.classList.contains("disabled"))return;this.currentQuestionIndex++}else if(e.match(/Prev/)){if(this.leftContainer.classList.contains("disabled"))return;this.currentQuestionIndex--}await this.renderTimedQuestion(),this.ensureButtonSafety();for(var i=0;ithis.renderedQuestionArray.length&&(console.log(`Error: bad index for ${s}`),this.currentQuestionIndex=n);let r=this.qNumItem(this.currentQuestionIndex);r?.classList.add("active"),r?.classList.contains("flagcolor")?this.flagButton.innerHTML="Unflag Question":this.flagButton.innerHTML="Flag Question",await this.renderTimedQuestion(),this.ensureButtonSafety()}navBtnListeners(){this.pagNavList.addEventListener("click",this.handleNextPrev.bind(this),!1),this.qNumList.addEventListener("click",this.handleNumberedNav.bind(this),!1)}flagBtnListener(){this.flaggingPlace.addEventListener("click",this.handleFlag.bind(this),!1)}renderSubmitButton(){this.buttonContainer=document.createElement("div"),this.buttonContainer.classList.add("timed-center"),this.finishButton=document.createElement("button"),this.finishButton.id="finish",this.finishButton.setAttribute("class","btn btn-primary"),this.finishButton.textContent="Finish Exam",this.finishButton.addEventListener("click",async function(){let t=this.renderedQuestionArray.filter((t=>!t.question.isAnswered)).length,e=t>0?`You have skipped ${t} question(s).`:"";window.confirm(`${e} Clicking OK means you are ready to submit your answers and are finished with this assessment.`)&&(await this.finishAssessment(),this.flagButton.classList.add("timed-hidden"))}.bind(this),!1),this.controlDiv.appendChild(this.finishButton),this.finishButton.classList.add("timed-hidden"),this.timedDiv.appendChild(this.buttonContainer)}ensureButtonSafety(){0===this.currentQuestionIndex&&(1!=this.renderedQuestionArray.length&&this.rightContainer.classList.remove("disabled"),this.leftContainer.classList.add("disabled")),this.currentQuestionIndex>=this.renderedQuestionArray.length-1&&(1!=this.renderedQuestionArray.length&&this.leftContainer.classList.remove("disabled"),this.rightContainer.classList.add("disabled")),this.currentQuestionIndex>0&&this.currentQuestionIndexYou have already taken this exam",this.scoreDiv.classList.add("timed-visible")):(this.scoreDiv.id=this.divid+"results",this.scoreDiv.classList.add("timed-hidden")),this.containerDiv.appendChild(this.scoreDiv)}createRenderedQuestionArray(){for(var t,e=0;e [data-component]");s&&(i=s,t.orig=i),i.matches("[data-component]")&&this.renderedQuestionArray.push(t)}}randomizeRQA(){for(var t,e,i=this.renderedQuestionArray.length;0!==i;)e=Math.floor(Math.random()*i),i-=1,t=this.renderedQuestionArray[i],this.renderedQuestionArray[i]=this.renderedQuestionArray[e],this.renderedQuestionArray[e]=t}async renderTimedQuestion(){if(this.currentQuestionIndex>=this.renderedQuestionArray.length)return;let t,e=this.renderedQuestionArray[this.currentQuestionIndex];if("prepared"===e.state||"forreview"===e.state||"broken_exam"===e.state&&e.initAttempts<3){let t=e.orig;if(t&&t.matches("[data-component=selectquestion]"))if(this.done&&"prepared"==e.state)this.renderedQuestionArray[this.currentQuestionIndex].state="exam_ended";else{e.rqa=this.renderedQuestionArray;let t=new a.default(e);this.renderedQuestionArray[this.currentQuestionIndex]={question:t};try{await t.initialize(),"broken_exam"==e.state&&this.qNumItem(this.currentQuestionIndex)?.classList.remove("broken")}catch(t){e.state="broken_exam",this.renderedQuestionArray[this.currentQuestionIndex]=e,console.log(`Error initializing question: Details ${t}`)}}else if(t&&t.matches("[data-component]")){let i=t.dataset.component;this.renderedQuestionArray[this.currentQuestionIndex]={question:window.component_factory[i](e),state:e.state}}}else if("broken_exam"===e.state)return;t=this.renderedQuestionArray[this.currentQuestionIndex].question,"forreview"===e.state&&(await t.component_ready_promise,await t.checkCurrentAnswer(),t.renderFeedback(),t.disableInteraction()),this.visited.includes(this.currentQuestionIndex)||(this.visited.push(this.currentQuestionIndex),this.visited.length!==this.renderedQuestionArray.length||this.done||this.finishButton.classList.remove("timed-hidden")),t.containerDiv&&(0==t.containerDiv.classList.contains("runestone")&&t.containerDiv.classList.add("runestone"),this.switchDiv.replaceWith(t.containerDiv),this.switchDiv=t.containerDiv),t.needsReinitialization&&t.reinitializeListeners(this.taken)}handlePrevAssessment(){this.startBtn.classList.add("timed-hidden"),this.pauseBtn.disabled=!0,this.finishButton.disabled=!0,this.running=0,this.done=1,this.showResults&&this.showFeedback?(this.timedDiv.classList.remove("timed-hidden"),this.restoreAnsweredQuestions()):(this.pauseBtn.classList.add("timed-hidden"),this.timerContainer.classList.add("timed-hidden"))}startAssessment(){if(this.taken)this.handlePrevAssessment();else{if(d(document.getElementById("relations-next")),d(document.getElementById("relations-prev")),this.startBtn.classList.add("timed-hidden"),this.pauseBtn.disabled=!1,0===this.running&&0===this.paused){this.running=1,this.lastTime=Date.now(),this.timedDiv.classList.remove("timed-hidden"),this.increment(),this.logBookEvent({event:"timedExam",act:"start",div_id:this.divid});var t=new Date,e={answer:[0,0,this.renderedQuestionArray.length,0],timestamp:t};localStorage.setItem(this.localStorageKey(),JSON.stringify(e))}this.beforeUnloadHandler=function(t){if(!this.done)return t.preventDefault(),t.returnValue="Are you sure you want to leave? Your work will be lost! And you will need your instructor to reset the exam!","Are you sure you want to leave? Your work will be lost!"}.bind(this),window.addEventListener("beforeunload",this.beforeUnloadHandler),window.addEventListener("pagehide",async function(t){this.done||(await this.finishAssessment(),console.log("Exam exited by leaving page"))}.bind(this))}}pauseAssessment(){0===this.done&&(1===this.running?(this.logBookEvent({event:"timedExam",act:"pause",div_id:this.divid}),this.running=0,this.paused=1,this.pauseBtn.innerHTML="Resume",this.timedDiv.classList.add("timed-hidden")):(this.logBookEvent({event:"timedExam",act:"resume",div_id:this.divid}),this.running=1,this.paused=0,this.increment(),this.pauseBtn.innerHTML="Pause",this.timedDiv.classList.remove("timed-hidden")))}showTime(){if(this.showTimer){var t=Math.floor(this.timeLimit/60),e=Math.floor(this.timeLimit)%60,i=t,s=e;t<10&&(i="0"+t),e<10&&(s="0"+e);var n="Time Remaining ";this.limitedTime||(n="Time Taken ");var r=n+i+":"+s;if(this.done||this.taken){var a=Math.floor(this.timeTaken/60),o=Math.floor(this.timeTaken%60);a<10&&(a="0"+a),o<10&&(o="0"+o),r="Time taken: "+a+":"+o}this.timerContainer.innerHTML=r;for(var h=document.getElementsByClassName("timeTip"),d=0;d<=h.length-1;d++)h[d].title=r}else this.timerContainer.classList.add("timed-hidden")}increment(){1!==this.running||this.taken||setTimeout(function(){let t=Date.now();if(this.limitedTime?this.timeLimit=this.timeLimit-Math.floor((t-this.lastTime)/1e3):this.timeLimit=this.timeLimit+Math.floor((t-this.lastTime)/1e3),this.lastTime=t,localStorage.setItem(eBookConfig.email+":"+this.divid+"-time",this.timeLimit),this.showTime(),this.timeLimit>0)this.increment();else if(this.startBtn.disabled=!0,this.finishButton.disabled=!0,this.running=0,this.done=1,!this.taken){this.taken=!0;let t=document.createElement("h1");t.innerHTML="Sorry but you ran out of time. Your answers are being submitted",this.controlDiv.appendChild(t),this.finishAssessment()}}.bind(this),1e3)}styleExamElements(){this.timerContainer.classList.add("timed-summary-style"),this.scoreDiv.classList.add("timed-summary-style");for(const t of document.querySelectorAll(".tooltipTime"))t.classList.add("timed-tooltip-time")}async finishAssessment(){c(document.getElementById("relations-next")),c(document.getElementById("relations-prev")),this.showFeedback||(this.timedDiv.classList.add("timed-hidden"),this.pauseBtn.classList.add("timed-hidden"),this.timerContainer.classList.add("timed-hidden")),this.findTimeTaken(),this.running=0,this.done=1,this.taken=1,await this.finalizeProblems(),this.checkScore(),this.displayScore(),this.storeScore(),this.logScore(),this.pauseBtn.disabled=!0,this.finishButton.disabled=!0,this.beforeUnloadHandler&&window.removeEventListener("beforeunload",this.beforeUnloadHandler),setTimeout((()=>{this.submitAutograde()}),2e3)}async submitAutograde(){try{let t=await fetch("/assignment/student/autograde",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({assignment_id:this.divid,is_timed:!0})}),e=await t.json();0==e.success?console.log(e.message):console.log("Autograder completed")}catch(t){console.log(`Error submitting exam for autograding: ${t}`)}}async finalizeProblems(){var t=this.renderedQuestionArray[this.currentQuestionIndex].question;await t.checkCurrentAnswer(),await t.logCurrentAnswer(),t.renderFeedback(),t.disableInteraction();for(var e=0;e0?this.correctStr=this.correctStr.substring(0,this.correctStr.length-2):this.correctStr="None",this.skippedStr.length>0?this.skippedStr=this.skippedStr.substring(0,this.skippedStr.length-2):this.skippedStr="None",this.incorrectStr.length>0?this.incorrectStr=this.incorrectStr.substring(0,this.incorrectStr.length-2):this.incorrectStr="None"}findTimeTaken(){this.limitedTime?this.timeTaken=this.startingTime-this.timeLimit:this.timeTaken=this.timeLimit}storeScore(){var t=[];t.push(this.score,this.correctStr,this.incorrect,this.incorrectStr,this.skipped,this.skippedStr,this.timeTaken);var e=new Date,i=JSON.stringify({answer:t,timestamp:e});localStorage.setItem(this.localStorageKey(),i)}logScore(){this.logBookEvent({event:"timedExam",act:"finish",div_id:this.divid,correct:this.score,incorrect:this.incorrect,skipped:this.skipped,time_taken:this.timeTaken})}shouldUseServer(t){var e;if(0===localStorage.length)return!0;var i=localStorage.getItem(this.localStorageKey());if(null===i)return!0;try{var s=JSON.parse(i).answer;if(4==s.length){if(t.correct==s[0]&&t.incorrect==s[1]&&t.skipped==s[2]&&t.timeTaken==s[3])return!0}else if(7==s.length&&t.correct==s[0]&&t.incorrect==s[2]&&t.skipped==s[4]&&t.timeTaken==s[6])return!1;e=new Date(JSON.parse(i[1]).timestamp)}catch(t){return console.log(t.message),localStorage.removeItem(this.localStorageKey()),!0}return!(new Date(t.timestamp)0&&null!==localStorage.getItem(this.localStorageKey())?(this.taken=1,this.restoreAnswers("")):this.taken=0}async restoreAnswers(t){var e;if(this.taken=1,""===t){let t,i=!1;try{t=JSON.parse(localStorage.getItem(this.localStorageKey())),e=t.answer}catch(t){console.log(`Error parsing stored Timed data for ${this.divid}: ${t.message}`),i=!0}if(i||t.timestamp0||this.incorrectStr.length>0||this.skippedStr.length>0?(e=`Num Correct: ${this.score}. Questions: ${this.correctStr}
Num Wrong: ${this.incorrect}. Questions: ${this.incorrectStr}
Num Skipped: ${this.skipped}. Questions: ${this.skippedStr}
`,t=this.score+this.incorrect+this.skipped,e+="Percent Correct: "+(this.score/t*100).toFixed(2)+"%",this.scoreDiv.innerHTML=e,this.scoreDiv.classList.add("timed-visible")):(e=`Num Correct: ${this.score}
Num Wrong: ${this.incorrect}
Num Skipped: ${this.skipped}
`,t=this.score+this.incorrect+this.skipped,e+="Percent Correct: "+(this.score/t*100).toFixed(2)+"%",this.scoreDiv.innerHTML=e,this.scoreDiv.classList.add("timed-visible")),this.highlightNumberedList()}else this.scoreDiv.innerHTML="Thank you for taking the exam. Your answers have been recorded.",this.scoreDiv.classList.add("timed-visible")}highlightNumberedList(){var t=this.correctStr,e=this.incorrectStr,i=this.skippedStr;t=t.replace(/ /g,"").split(","),e=e.replace(/ /g,"").split(","),i=i.replace(/ /g,"").split(",");var s=document.querySelectorAll("ul#pageNums > ul > li");for(const t of s)t.classList.remove("answered");const n=(t,e)=>{for(const i of t){const t=s[parseInt(i)-1];t&&t.classList.add(e)}};n(t,"correctCount"),n(e,"incorrectCount"),n(i,"skippedCount")}}function d(t){t&&t.classList.add("timed-hidden")}function c(t){t&&t.classList.remove("timed-hidden")}document.addEventListener("runestone:login-complete",(function(){for(let t of document.querySelectorAll("[data-component=timedAssessment]"))window.componentMap[t.id]=new h({orig:t,useRunestoneServices:eBookConfig.useRunestoneServices})}))}}]); //# sourceMappingURL=506.4550bb38b777d36c.js.map