2 lines
17 KiB
JavaScript
Executable File
2 lines
17 KiB
JavaScript
Executable File
(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)=>`<script-eval expr=${JSON.stringify(t)}></script-eval>`)),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<r;i++){var s=.02519603282416938*(e+=t.charCodeAt(i));s-=e=s>>>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;a<e.length;a++)(i-=t(e[a]))<0&&(i+=1),(r-=t(e[a]))<0&&(r+=1),(s-=t(e[a]))<0&&(s+=1);c=t.version,t=null}function l(e){return parseInt(e,10)===e}var h=function(){var e=2091639*i+2.3283064365386963e-10*n;return i=r,r=s,s=e-(n=0|e)};return h.fract53=function(){return h()+11102230246251565e-32*(2097152*h()|0)},h.int32=function(){return 4294967296*h()},h.cycle=function(e){(e=void 0===e?1:+e)<1&&(e=1);for(var t=0;t<e;t++)h()},h.range=function(){var e,t;return 1===arguments.length?(e=0,t=arguments[0]):(e=arguments[0],t=arguments[1]),arguments[0]>arguments[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;r<this.blankArray.length;r++)this.blankArray[r].value=t[r]||"",t[r]&&(i=!0);this.feedbackArray?i&&this.checkCurrentAnswer():(this.displayFeed=e.displayFeed,this.correct=e.correct,this.isCorrectArray=e.isCorrectArray,void 0!==this.displayFeed&&void 0!==this.correct&&void 0!==this.isCorrectArray&&this.renderFeedback(),this.problemHtml=e.problemHtml,this.problemHtml&&(this.descriptionDiv.innerHTML=this.problemHtml,this.queueMathJax(this.descriptionDiv),this.setupBlanks()))}checkLocalStorage(){var e;if(!this.graderactive&&localStorage.length>0){var t=localStorage.getItem(this.localStorageKey());if(null!==t){let i=!1;try{e=JSON.parse(t)}catch(e){console.log(`Error parsing stored FITB data for ${this.divid}: ${e.message}`),i=!0}if(i||e.timestamp<eBookConfig.termStartDate)return 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<t.length;c++){const d=t[c];if(""===d)a.push(null),o.push("No answer provided."),s=!1;else{const l=i[c]||[];let h;for(h=0;h<l.length;h++){if(h===l.length-1){o.push(l[h].feedback);break}if("regex"in l[h]){if(RegExp(l[h].regex,l[h].regexFlags).test(d)){o.push(l[h].feedback);break}}else if("number"in l[h]){const[e,t]=l[h].number,i=+d;if(i>=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;e<this.blankArray.length;e++)this.given_arr.push(this.blankArray[e].value);return[this.blankNames,this.given_arr,this.feedbackArray,this.dyn_vars_eval]}async randomize(){if(this.feedbackArray)this.seed=Math.floor(Math.random()*2**32),this.renderDynamicContent(),this.queueMathJax(this.descriptionDiv);else{const e=new Request("/assessment/results",{method:"POST",body:JSON.stringify({div_id:this.divid,course:eBookConfig.course,event:"fillb",sid:this.sid,new_seed:!0}),headers:this.jsonHeaders}),t=await fetch(e);if(!t.ok)return void alert(`HTTP error getting results: ${t.statusText}`);const i=(await t.json()).detail;this.seed=i.seed,this.descriptionDiv.innerHTML=i.problemHtml,this.queueMathJax(this.descriptionDiv),this.setupBlanks()}this.given_arr=Array(this.blankArray.len).fill(""),this.blankArray.forEach((e=>e.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<this.blankArray.length;e++)this.blankArray[e].classList.remove("input-validation-error")}else{null===this.displayFeed&&(this.displayFeed="");for(let e=0;e<this.blankArray.length;e++)!0!==this.isCorrectArray[e]?this.blankArray[e].classList.add("input-validation-error"):this.blankArray[e].classList.remove("input-validation-error");this.feedBackDiv.className="alert alert-danger fitb-feedback"}for(var e="<ul>",t=0;t<this.displayFeed.length;t++){let i=this.displayFeed[t],r=!0===this.isCorrectArray[t]?"✔️":"✖️";"string"==typeof this.dyn_vars&&(i=a(this.blankNames,this.given_arr,t,i,this.dyn_vars_eval),i=void 0!==i?.[0]?i[0].parentElement.innerHTML:"No feedback provided"),e+=`<li>${r} ${i}</li>`}e+="</ul>",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,"<table>");for(var n in s+="<tr><th>Answer</th><th>Count</th></tr>",r)s+="<tr><td>"+r[n].answer+"</td><td>"+r[n].count+" times</td></tr>";s+="</table>";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<this.blankArray.length;e++)this.blankArray[e].disabled=!0}}document.addEventListener("runestone:login-complete",(function(){document.querySelectorAll("[data-component=fillintheblank]").forEach((function(e,t){var i={orig:e,useRunestoneServices:eBookConfig.useRunestoneServices};if(!e.closest("[data-component=timedAssessment]"))try{l[e.id]=new h(i),window.componentMap[e.id]=l[e.id]}catch(t){console.assert(!1,`Error rendering Fill in the Blank Problem ${e.id}\n Details: ${t}`)}}))}));class u extends h{constructor(e){super(e),this.renderTimedIcon(this.inputDiv),this.hideButtons(),this.needsReinitialization=!0}hideButtons(){this.submitButton&&(this.submitButton.style.display="none"),this.compareButton&&(this.compareButton.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&&(e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t))}checkCorrectTimed(){switch(this.correct){case!0:return"T";case!1:return"F";default:return null}}hideFeedback(){for(var e=0;e<this.blankArray.length;e++)this.blankArray[e].classList.remove("input-validation-error");this.feedBackDiv.style.display="none"}reinitializeListeners(){this.setupBlanks()}}void 0===window.component_factory&&(window.component_factory={}),window.component_factory.fillintheblank=function(e){return e.timed?new u(e):new h(e)}}}]);
|
||
//# sourceMappingURL=466.63840a83388af9f2.js.map
|