Skip to content

Commit 48a0a42

Browse files
committed
Merge branch 'ascholerChemeketa-jquery-replacement-fixes'
2 parents b42d1b2 + 1db3bd0 commit 48a0a42

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

bases/rsptx/interactives/runestone/common/js/runestonebase.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ export default class RunestoneBase {
103103
});
104104
}
105105

106+
// Helper for parsing boolean data-* attributes
107+
// Unset/"false"/"no" means false, anything else, including empty string means true
108+
parseBooleanAttribute(element, attributeName) {
109+
const attrValue = element.getAttribute(attributeName);
110+
if (attrValue === null) {
111+
return false;
112+
}
113+
const lowerValue = attrValue.toLowerCase();
114+
if (lowerValue === "false" || lowerValue === "no") {
115+
return false;
116+
}
117+
return true;
118+
}
119+
106120
// _`logBookEvent`
107121
//----------------
108122
// This function sends the provided ``eventInfo`` to the `hsblog endpoint` of the server. Awaiting this function returns either ``undefined`` (if Runestone services are not available) or the data returned by the server as a JavaScript object (already JSON-decoded).

bases/rsptx/interactives/runestone/mchoice/js/mchoice.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export default class MultipleChoice extends RunestoneBase {
2525
this.useRunestoneServices = opts.useRunestoneServices;
2626
this.multipleanswers = false;
2727
this.divid = orig.id;
28-
if (this.origElem.getAttribute("data-multipleanswers") === "true" || this.origElem.hasAttribute("data-multipleanswers")) {
28+
if (this.parseBooleanAttribute(this.origElem, "data-multipleanswers")) {
2929
this.multipleanswers = true;
3030
}
3131
this.children = this.origElem.childNodes;
3232
this.random = false;
33-
if (this.origElem.hasAttribute("[data-random]") || this.origElem.hasAttribute("data-random")) {
33+
if (this.parseBooleanAttribute(this.origElem, "data-random")) {
3434
this.random = true;
3535
}
3636
this.correct = null;

0 commit comments

Comments
 (0)