Skip to content

Commit 3036471

Browse files
Runestonebase: add boolean data attr parsing helper
1 parent b42d1b2 commit 3036471

1 file changed

Lines changed: 14 additions & 0 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).

0 commit comments

Comments
 (0)