(self.webpackChunkWebComponents=self.webpackChunkWebComponents||[]).push([[466],{30612:()=>{$.i18n().load({"pt-br":{msg_no_answer:"Nenhuma resposta dada.",msg_fitb_check_me:"Verificar",msg_fitb_compare_me:"Comparar"}})},39604:()=>{$.i18n().load({en:{msg_no_answer:"No answer provided.",msg_fitb_check_me:"Check me",msg_fitb_compare_me:"Compare me",msg_fitb_randomize:"Randomize"}})},64466:(e,t,i)=>{"use strict";i.r(t),i.d(t,{default:()=>u});var r=i(78673);function s(e,t){const i=e.replaceAll(/\[%=\s*((?:.(?!%]))*)\s*%\]/g,((e,t)=>``)),r=(new DOMParser).parseFromString(i,"text/html"),s=r.getElementsByTagName("script-eval");for(;s.length;){const e=s[0],i=e.getAttribute("expr");if(i){const r=window.Function("v",...Object.keys(t),`"use strict;"\nreturn ${i};`)(t,...Object.values(t));e.replaceWith(r)}}return r.body.childNodes}function n(e,t,i){const r=o(t,e,i),s=[];for(const[t,i]of Object.entries(e))s[i]=t;return[r,t.map(((e,t)=>c(s[t],e,t,i)))]}function a(e,t,i,r,n){const a=o(t,e,n),c=Object.assign({ans:t[i],ans_array:t},n,a);try{r=s(r,c)}catch(e){throw console.assert(!1,`Error evaluating feedback index ${i}.`),e}return r}function o(e,t,i){const r={};for(const[s,n]of Object.entries(t))r[s]=c(s,e[n],n,i);return r}function c(e,t,i,r){const s=r.types||d,n=s[e]||s[i]||s;n===Number&&"undefined"!=typeof Number_&&(n=Number_);try{return n(t)}catch(e){if(e instanceof TypeError)return e;throw e}}function d(e){return e}i(39604),i(30612);var l={};class h extends r.A{constructor(e){super(e);var t=e.orig;this.useRunestoneServices=e.useRunestoneServices,this.origElem=t,this.divid=t.id,this.correct=null;const r=this.scriptSelector(this.origElem),s=JSON.parse(r.textContent);r.remove(),void 0!==s.problemHtml?(s.problemHtml.startsWith("<")&&(s.problemHtml=s.problemHtml.replace(/</g,"<").replace(/>/g,">")),eBookConfig.useRunestoneServices&&(s.problemHtml=s.problemHtml.replace(/src="external/g,`src="/ns/books/published/${eBookConfig.basecourse}/external`)),this.problemHtml=s.problemHtml,this.dyn_vars=s.dyn_vars,this.blankNames=s.blankNames,this.feedbackArray=s.feedbackArray):(this.problemHtml=this.origElem.innerHTML,this.feedbackArray=s),this.createFITBElement(),this.setupBlanks(),this.caption="Fill in the Blank",this.addCaption("runestone"),this.dyn_imports={};let n=Promise.resolve();if(void 0!==s.dyn_imports){let e=[];for(const t of s.dyn_imports)"BTM"===t?e.push(i.e(357).then(i.bind(i,15357))):e.push(import(t));n=Promise.all(e).then((e=>this.dyn_imports=Object.assign({},...e))).catch((e=>{throw`Failed dynamic import: ${e}.`}))}n.then((()=>{this.checkServer("fillb",!1).then((()=>{const e=void 0!==s.static_seed,t="string"==typeof this.dyn_vars,i=void 0!==this.seed;e||!t||i?e&&!t?console.assert(!1,"Warning: the provided static seed was ignored, because it only affects client-side, dynamic problems."):e&&t&&!i?(this.seed=s.static_seed,this.renderDynamicContent()):e&&t&&i&&this.seed!==s.static_seed&&console.assert(!1,"Warning: the provided static seed was overridden by the seed found in local storage."):this.randomize(),"undefined"!=typeof Prism&&Prism.highlightAllUnder(this.containerDiv),this.indicate_component_ready()}))})),this.queueMathJax(this.descriptionDiv)}scriptSelector(e){return e.querySelector('script[type="application/json"]')}createFITBElement(){this.renderFITBInput(),this.renderFITBButtons(),this.renderFITBFeedbackDiv(),this.origElem.replaceWith(this.containerDiv)}renderFITBInput(){this.containerDiv=document.createElement("div"),this.containerDiv.id=this.divid,this.descriptionDiv=document.createElement("div"),this.descriptionDiv.classList.add("exercise-statement"),this.containerDiv.appendChild(this.descriptionDiv),this.problemHtml&&(this.descriptionDiv.innerHTML=this.problemHtml,this.descriptionDiv.origInnerHTML=this.problemHtml)}renderFITBButtons(){this.submitButton=document.createElement("button"),this.submitButton.textContent=$.i18n("msg_fitb_check_me"),this.submitButton.className="btn btn-success",this.submitButton.name="do answer",this.submitButton.type="button",this.submitButton.addEventListener("click",async function(){this.checkCurrentAnswer(),await this.logCurrentAnswer()}.bind(this),!1),this.containerDiv.appendChild(this.submitButton),this.useRunestoneServices&&(this.compareButton=document.createElement("button"),this.compareButton.className="btn btn-default",this.compareButton.id=this.origElem.id+"_bcomp",this.compareButton.disabled=!0,this.compareButton.name="compare",this.compareButton.textContent=$.i18n("msg_fitb_compare_me"),this.compareButton.addEventListener("click",function(){this.compareFITBAnswers()}.bind(this),!1),this.containerDiv.appendChild(this.compareButton)),this.dyn_vars&&(this.randomizeButton=document.createElement("button"),this.randomizeButton.className="btn btn-default",this.randomizeButton.id=this.origElem.id+"_bcomp",this.randomizeButton.name="randomize",this.randomizeButton.textContent=$.i18n("msg_fitb_randomize"),this.randomizeButton.addEventListener("click",function(){this.randomize()}.bind(this),!1),this.containerDiv.appendChild(this.randomizeButton)),this.containerDiv.appendChild(document.createElement("div"))}renderFITBFeedbackDiv(){this.feedBackDiv=document.createElement("div"),this.feedBackDiv.id=this.divid+"_feedback",this.feedBackDiv.setAttribute("aria-live","polite"),this.feedBackDiv.setAttribute("role","alert"),this.feedBackDiv.classList.add("fitb-feedback"),this.containerDiv.appendChild(this.feedBackDiv)}clearFeedbackDiv(){this.feedBackDiv.innerHTML="",this.feedBackDiv.className=""}renderDynamicContent(){if("string"==typeof this.dyn_vars){let e;if([e,this.dyn_vars_eval]=function(e,t,i,r,n,a){const o=function(){return function(e){const t="aleaPRNG 1.1.0";var i,r,s,n,a,o=new Uint32Array(3),c="";function d(e){var t=function(){var e=4022871197,t=function(t){for(var i=0,r=(t=t.toString()).length;i>>0,e=(s*=e)>>>0,e+=4294967296*(s-=e)}return 2.3283064365386963e-10*(e>>>0)};return t.version="Mash 0.9",t}();i=t(" "),r=t(" "),s=t(" "),n=1;for(var a=0;aarguments[1]&&(e=arguments[1],t=arguments[0]),l(e)&&l(t)?Math.floor(h()*(t-e+1))+e:h()*(t-e)+e},h.restart=function(){d(a)},h.seed=function(){d(Array.prototype.slice.call(arguments))},h.version=function(){return t},h.versions=function(){return t+", "+c},0===e.length&&(window.crypto.getRandomValues(o),e=[o[0],o[1],o[2]]),a=e,d(e),h}(Array.prototype.slice.call(arguments))}(e),c=window.Function("v","rand",...Object.keys(i),`"use strict";\n${t};\nreturn v;`)(Object.assign({divid:n,prepareCheckAnswers:a},i),o,...Object.values(i));let d;if("function"==typeof c.beforeContentRender)try{c.beforeContentRender(c)}catch(e){throw console.assert(!1,`Error in problem ${n} invoking beforeContentRender`),e}try{d=s(r,c)}catch(e){throw console.assert(!1,`Error rendering problem ${n} text.`),e}return[d,c]}(this.seed,this.dyn_vars,this.dyn_imports,this.descriptionDiv.origInnerHTML,this.divid,this.prepareCheckAnswers.bind(this)),this.descriptionDiv.replaceChildren(...e),"function"==typeof this.dyn_vars_eval.afterContentRender)try{this.dyn_vars_eval.afterContentRender(this.dyn_vars_eval)}catch(e){throw console.assert(!1,`Error in problem ${this.divid} invoking afterContentRender`),e}this.setupBlanks()}}setupBlanks(){const e=this.descriptionDiv.querySelectorAll('input[type="text"],input[type="number"]');e.forEach((e=>{e.className="form form-control selectwidthauto",e.setAttribute("aria-label","input area")})),this.blankArray=Array.from(e);for(let e of this.blankArray)e.addEventListener("change",this.recordAnswered.bind(this))}recordAnswered(){this.isAnswered=!0}restoreAnswers(e){var t;this.seed=e.seed,this.renderDynamicContent(),this.queueMathJax(this.descriptionDiv);try{if(t=JSON.parse(e.answer),!Array.isArray(t))throw new Error}catch(i){t=(e.answer||"").split(",")}let i=!1;for(var r=0;r0){var t=localStorage.getItem(this.localStorageKey());if(null!==t){try{e=JSON.parse(t)}catch(e){return console.assert(!1,e.message),void localStorage.removeItem(this.localStorageKey())}this.restoreAnswers(e)}}}setLocalStorage(e){let t=this.localStorageKey();localStorage.setItem(t,JSON.stringify(e))}checkCurrentAnswer(){this.isCorrectArray=[],this.displayFeed=[];const e=this.prepareCheckAnswers();this.useRunestoneServices&&eBookConfig.enableCompareMe&&this.enableCompareButton(),this.feedbackArray&&([this.displayFeed,this.correct,this.isCorrectArray,this.percent]=function(e,t,i,r){if(r&&"function"==typeof r.beforeCheckAnswers){const[i,s]=n(e,t,r),a=Object.assign({},r,i);try{r.beforeCheckAnswers(a,s)}catch(e){throw console.assert(!1,"Error calling beforeCheckAnswers"),e}}let s=!0;const a=[],o=[];for(let c=0;c=e&&i<=t){o.push(l[h].feedback);break}}else if(r){const[i,s]=n(e,t,r);if(s[c]instanceof TypeError){o.push(s[c].message),h=1;break}const a=window.Function("ans","ans_array",...Object.keys(r),...Object.keys(i),`"use strict;"\nreturn ${l[h].solution_code};`)(s[c],s,...Object.values(r),...Object.values(i));if(a){o.push("string"==typeof a?a:l[h].feedback);break}}else if("solution_code"in l[h]){const e=window.Function("ans","ans_array",`"use strict;"\nreturn ${l[h].solution_code};`)(d,t);if(e){o.push("string"==typeof e?e:l[h].feedback);break}}else console.assert("number"in l[h])}const u=0===h&&l.length>1;a.push(u),u||(s=!1)}}if(r&&"function"==typeof r.afterCheckAnswers){const[i,s]=n(e,t,r),a=Object.assign({},r,i);try{r.afterCheckAnswers(a,s)}catch(e){throw console.assert(!1,"Error calling afterCheckAnswers"),e}}const c=a.filter(Boolean).length/a.length;return[o,s,a,c]}(...e),this.isTimed||this.renderFeedback())}prepareCheckAnswers(){this.given_arr=[];for(var e=0;ee.value="")),this.clearFeedbackDiv(),this.saveAnswersLocallyOnly()}saveAnswersLocallyOnly(){this.setLocalStorage({seed:this.seed,answer:JSON.stringify(this.given_arr),timestamp:new Date,problemHtml:this.descriptionDiv.innerHTML})}async logCurrentAnswer(e){let t=JSON.stringify(this.given_arr),i=!0;this.saveAnswersLocallyOnly();const r={event:"fillb",div_id:this.divid,act:t||"",seed:this.seed,answer:t||"",correct:this.correct?"T":"F",percent:this.percent};void 0!==e&&(r.sid=e,i=!1);const s=await this.logBookEvent(r);if(!i)return;if(this.feedbackArray||!s)return r;const n=s.detail;return this.timestamp=n.timestamp,this.displayFeed=n.displayFeed,this.correct=n.correct,this.isCorrectArray=n.isCorrectArray,this.setLocalStorage({seed:this.seed,answer:t,timestamp:this.timestamp,problemHtml:this.descriptionDiv.innerHTML,displayFeed:this.displayFeed,correct:this.correct,isCorrectArray:this.isCorrectArray}),this.renderFeedback(),s}renderFeedback(){if(this.correct){this.feedBackDiv.className="alert alert-info fitb-feedback";for(let e=0;e${r} ${i}`}e+="",1==this.displayFeed.length&&(e=e.slice(8,-10)),this.feedBackDiv.innerHTML=e,"undefined"!=typeof MathJax&&this.queueMathJax(this.feedBackDiv)}enableCompareButton(){this.compareButton.disabled=!1}async compareFITBAnswers(){var e={};e.div_id=this.divid,e.course=eBookConfig.course;try{const t=new URLSearchParams(e),i=await fetch(`${eBookConfig.new_server_prefix}/assessment/gettop10Answers?${t.toString()}`),r=await i.json();this.compareFITB(r)}catch(e){console.error("Error fetching top answers:",e)}}compareFITB(e,t,i){var r=e.detail.res,s=(e.detail.miscdata,"");for(var n in s+="| Answer | Count |
",r)s+="| "+r[n].answer+" | "+r[n].count+" times |
";s+="
";const a=document.createElement("div");a.style.position="fixed",a.style.inset="0",a.style.background="rgba(0,0,0,0.5)",a.style.zIndex="9999";const o=document.createElement("div");o.className="compare-modal",o.style.maxWidth="720px",o.style.margin="10vh auto",o.style.background="#fff",o.style.borderRadius="6px",o.style.boxShadow="0 2px 12px rgba(0,0,0,0.3)",o.style.padding="16px";const c=document.createElement("div"),d=document.createElement("button");d.type="button",d.textContent="×",d.setAttribute("aria-hidden","true"),d.style.float="right",d.className="btn btn-light",d.onclick=function(){document.body.removeChild(a)};const l=document.createElement("h4");l.className="modal-title",l.textContent="Top Answers",c.appendChild(d),c.appendChild(l);const h=document.createElement("div");h.innerHTML=s,o.appendChild(c),o.appendChild(h),a.appendChild(o),document.body.appendChild(a)}disableInteraction(){for(var e=0;e