2 lines
9.9 KiB
JavaScript
2 lines
9.9 KiB
JavaScript
"use strict";(self.webpackChunkWebComponents=self.webpackChunkWebComponents||[]).push([[529],{58529:(e,t,i)=>{i.r(t),i.d(t,{default:()=>s});var r=i(78673);class c extends r.A{constructor(e){super(e);var t=e.orig;this.origElem=t,this.divid=t.id,this.useRunestoneServices=e.useRunestoneServices,this.clickableArray=[],this.correctArray=[],this.incorrectArray=[],this.isTable=!1,null!==this.origElem.getAttribute("data-cc")&&(this.origElem.hasAttribute("data-table")?(this.isTable=!0,this.ccArray=this.origElem.getAttribute("data-cc").split(";"),this.ciArray=this.origElem.getAttribute("data-ci").split(";")):(this.ccArray=this.origElem.getAttribute("data-cc").split(","),this.ciArray=this.origElem.getAttribute("data-ci").split(","))),this.clickIndex=0,this.clickableCounter=0,this.getQuestion(),this.getFeedback(),this.renderNewElements(),this.caption="Clickable",this.addCaption("runestone"),this.checkServer("clickableArea",!0),"undefined"!=typeof Prism&&Prism.highlightAllUnder(this.containerDiv)}getQuestion(){for(var e=0;e<this.origElem.childNodes.length;e++){const t=this.origElem.childNodes[e];if(t.nodeType===Node.ELEMENT_NODE&&t.hasAttribute("data-question")){this.question=t,this.question.classList.add("exercise-statement");break}}}getFeedback(){this.feedback="";for(var e=0;e<this.origElem.childNodes.length;e++){const t=this.origElem.childNodes[e];t.nodeType===Node.ELEMENT_NODE&&t.hasAttribute("data-feedback")&&(this.feedback=t)}""!==this.feedback&&(this.feedback.remove(),this.feedback=this.feedback.innerHTML)}renderNewElements(){this.containerDiv=document.createElement("div"),this.containerDiv.id=this.origElem.id,this.containerDiv.appendChild(this.question);const e=this.origElem.getAttribute("class");e&&this.containerDiv.classList.add(...e.split(" ").filter(Boolean)),this.newDiv=document.createElement("div");for(var t=this.origElem.innerHTML;"\n"===t[0];)t=t.slice(1);this.newDiv.innerHTML=t,this.newDiv.classList.add("exercise-content"),this.containerDiv.appendChild(this.newDiv),this.createButtons(),this.createFeedbackDiv(),this.origElem.replaceWith(this.containerDiv)}createButtons(){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.submitButton.onclick=function(){this.checkCurrentAnswer(),this.logCurrentAnswer(),this.renderFeedback()}.bind(this),this.containerDiv.appendChild(this.submitButton)}createFeedbackDiv(){this.feedBackDiv=document.createElement("div"),this.containerDiv.appendChild(document.createElement("br")),this.containerDiv.appendChild(this.feedBackDiv)}restoreAnswers(e){void 0!==e.answer&&(this.hasStoredAnswers=!0,this.clickedIndexArray=e.answer.split(";")),void 0===this.ccArray?this.modifyClickables(this.newDiv.childNodes):(this.ccCounter=0,this.ccIndex=0,this.ciIndex=0,this.isTable?this.modifyTableViaCC(this.newDiv.children):this.modifyViaCC(this.newDiv.children))}checkLocalStorage(){if(!this.graderactive){var e;if(this.hasStoredAnswers=!1,localStorage.length>0){var t=localStorage.getItem(this.localStorageKey());if(null!==t){this.hasStoredAnswers=!0;let r=!1;try{e=JSON.parse(t)}catch(e){console.log(`Error parsing stored ClickableArea data for ${this.divid}: ${e.message}`),r=!0}if(r||e.timestamp<eBookConfig.termStartDate)return localStorage.removeItem(this.localStorageKey()),this.hasStoredAnswers=!1,void this.restoreAnswers({});if(this.clickedIndexArray=e.answer.split(";"),this.useRunestoneServices){this.givenIndexArray=[];for(var i=0;i<this.clickableArray.length;i++)this.clickableArray[i].classList.contains("clickable-clicked")&&this.givenIndexArray.push(i);this.logBookEvent({event:"clickableArea",act:this.clickedIndexArray.join(";"),answer:this.clickedIndexArray.join(";"),div_id:this.divid,correct:e.correct})}}}this.restoreAnswers({})}}setLocalStorage(e){var t;if(void 0!==e.answer)t=this.clickedIndexArray.join(";");else{this.givenIndexArray=[];for(var i=0;i<this.clickableArray.length;i++)this.clickableArray[i].classList.contains("clickable-clicked")&&this.givenIndexArray.push(i);t=this.givenIndexArray.join(";")}var r=new Date,c={answer:t,correct:e.correct,timestamp:r};localStorage.setItem(this.localStorageKey(),JSON.stringify(c))}modifyClickables(e){for(var t=0;t<e.length;t++){const i=e[t];i.nodeType===Node.ELEMENT_NODE&&(i.hasAttribute("data-correct")||i.hasAttribute("data-incorrect"))&&(this.manageNewClickable(i),i.hasAttribute("data-correct")?(i.removeAttribute("data-correct"),this.correctArray.push(i)):(i.removeAttribute("data-incorrect"),this.incorrectArray.push(i))),i.childNodes&&0!==i.childNodes.length&&this.modifyClickables(i.childNodes)}}modifyViaCC(e){for(var t=0;t<e.length;t++)0!==e[t].children.length?this.modifyViaCC(e[t].children):(this.ccCounter++,this.ccCounter===Math.floor(this.ccArray[this.ccIndex])?(this.manageNewClickable(e[t]),this.correctArray.push(e[t]),this.ccIndex++):this.ccCounter===Math.floor(this.ciArray[this.ciIndex])&&(this.manageNewClickable(e[t]),this.incorrectArray.push(e[t]),this.ciIndex++))}modifyTableViaCC(e){var t=[];for(let i=0;i<e.length;i++)if("TABLE"===e[i].nodeName){let r=e[i];for(let e=0;e<r.children.length;e++)("THEAD"===r.children[e].nodeName||"TBODY"===r.children[e].nodeName||"TFOOT"===r.children[e].nodeName)&&t.push(r.children[e])}for(var i=0;i<t.length;i++)for(let e=0;e<t[i].children.length;e++)if(this.ccCounter++,this.ccIndex<this.ccArray.length&&this.ccCounter===Math.floor(this.ccArray[this.ccIndex].split(",")[0])&&0===Math.floor(this.ccArray[this.ccIndex].split(",")[1]))this.manageNewClickable(t[i].children[e]),this.correctArray.push(t[i].children[e]),this.ccIndex++;else if(this.ciIndex<this.ciArray.length&&this.ccCounter===Math.floor(this.ciArray[this.ciIndex].split(",")[0])&&0===Math.floor(this.ciArray[this.ciIndex].split(",")[1]))this.manageNewClickable(t[i].children[e]),this.incorrectArray.push(t[i].children[e]),this.ciIndex++;else for(let r=0;r<t[i].children[e].children.length;r++){let c=r+1;this.ccIndex<this.ccArray.length&&c===Math.floor(this.ccArray[this.ccIndex].split(",")[1])&&this.ccCounter===Math.floor(this.ccArray[this.ccIndex].split(",")[0])?(this.manageNewClickable(t[i].children[e].children[r]),this.correctArray.push(t[i].children[e].children[r]),this.ccIndex++):this.ciIndex<this.ciArray.length&&c===Math.floor(this.ciArray[this.ciIndex].split(",")[1])&&this.ccCounter===Math.floor(this.ciArray[this.ciIndex].split(",")[0])&&(this.manageNewClickable(t[i].children[e].children[r]),this.incorrectArray.push(t[i].children[e].children[r]),this.ciIndex++)}}manageNewClickable(e){e.classList.add("clickable"),this.hasStoredAnswers&&this.clickedIndexArray[this.clickIndex].toString()===this.clickableCounter.toString()&&(e.classList.add("clickable-clicked"),this.clickIndex++,this.clickIndex===this.clickedIndexArray.length&&(this.hasStoredAnswers=!1));let t=this;e.onclick=function(){t.isAnswered=!0,this.classList.contains("clickable-clicked")?(this.classList.remove("clickable-clicked"),this.classList.remove("clickable-incorrect")):this.classList.add("clickable-clicked")},this.clickableArray.push(e),this.clickableCounter++}checkCurrentAnswer(){this.correct=!0,this.correctNum=0,this.incorrectNum=0;for(let e=0;e<this.correctArray.length;e++)this.correctArray[e].classList.contains("clickable-clicked")?this.correctNum++:this.correct=!1;for(let e=0;e<this.incorrectArray.length;e++)this.incorrectArray[e].classList.contains("clickable-clicked")?(this.correct=!1,this.incorrectNum++):this.incorrectArray[e].classList.remove("clickable-incorrect");this.percent=(this.correctNum-this.incorrectNum)/this.correctArray.length,this.percent=Math.max(0,this.percent),this.setLocalStorage({correct:this.correct?"T":"F"})}async logCurrentAnswer(e){const t=this.givenIndexArray.join(";");let i={event:"clickableArea",answer:t,act:t,div_id:this.divid,correct:this.correct?"T":"F"};void 0!==e&&(i.sid=e),await this.logBookEvent(i)}renderFeedback(){if(this.correct)this.feedBackDiv.innerHTML="You are Correct!",this.feedBackDiv.className="alert alert-info";else{for(let e=0;e<this.incorrectArray.length;e++)this.incorrectArray[e].classList.contains("clickable-clicked")?this.incorrectArray[e].classList.add("clickable-incorrect"):this.incorrectArray[e].classList.remove("clickable-incorrect");this.feedBackDiv.innerHTML="Incorrect. You clicked on "+this.correctNum+" of the "+this.correctArray.length.toString()+" correct elements and "+this.incorrectNum+" of the "+this.incorrectArray.length.toString()+" incorrect elements. "+this.feedback,this.feedBackDiv.className="alert alert-danger"}}disableInteraction(){for(var e=0;e<this.clickableArray.length;e++)this.clickableArray[e].style.cursor="initial",this.clickableArray[e].onclick=function(){}}}document.addEventListener("runestone:login-complete",(function(){document.querySelectorAll("[data-component=clickablearea]").forEach((function(e,t){if(!e.closest("[data-component=timedAssessment]"))try{window.componentMap[e.id]=new c({orig:e,useRunestoneServices:eBookConfig.useRunestoneServices})}catch(t){console.log(`Error rendering ClickableArea Problem ${e.id}\n Details: ${t}`)}}))}));class s extends c{constructor(e){super(e),this.assessmentTaken||this.restoreAnswers({}),this.renderTimedIcon(this.containerDiv),this.hideButtons()}hideButtons(){this.submitButton&&(this.submitButton.style.display="none")}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.insertBefore(t,e.firstChild)}checkCorrectTimed(){switch(0===this.correctNum&&0===this.incorrectNum&&(this.correct=null),this.correct){case!0:return"T";case!1:return"F";default:return null}}hideFeedback(){this.feedBackDiv&&(this.feedBackDiv.style.display="none")}}void 0===window.component_factory&&(window.component_factory={}),window.component_factory.clickablearea=function(e){return e.timed?new s(e):new c(e)}}}]);
|
|
//# sourceMappingURL=529.f5fdfcbb88388877.js.map
|