Skip to content

Commit 35696bd

Browse files
authored
Merge pull request #1094 from ascholerChemeketa/refactor-data-attrs
Refactor boolean data attr parsing
2 parents f954d92 + 2082579 commit 35696bd

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

bases/rsptx/interactives/runestone/activecode/js/activecode.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class ActiveCode extends RunestoneBase {
9292
this.tie = $(orig).data("tie");
9393
this.dburl = $(orig).data("dburl");
9494
this.runButton = null;
95-
this.enabledownload = $(orig).data("enabledownload");
95+
this.enabledownload = this.parseBooleanAttribute(orig, "data-enabledownload");
9696
this.downloadButton = null;
9797
this.saveButton = null;
9898
this.loadButton = null;
@@ -101,7 +101,7 @@ export class ActiveCode extends RunestoneBase {
101101
this.runCount = 0;
102102
this.firstAfterRun = true;
103103
this.logResults = true;
104-
if (!eBookConfig.allow_pairs || $(orig).data("nopair")) {
104+
if (!eBookConfig.allow_pairs || this.parseBooleanAttribute(orig, "data-nopair")) {
105105
this.enablePartner = false;
106106
} else {
107107
this.enablePartner = true;
@@ -113,7 +113,7 @@ export class ActiveCode extends RunestoneBase {
113113
this.controlDiv = null;
114114
this.historyScrubber = null;
115115
this.timestamps = ["Original"];
116-
this.autorun = $(orig).data("autorun");
116+
this.autorun = this.parseBooleanAttribute(orig, "data-autorun");
117117
this.outputLineCount = 0;
118118
this.outputLines = [];
119119
if (this.chatcodes && eBookConfig.enable_chatcodes) {
@@ -1076,15 +1076,15 @@ export class ActiveCode extends RunestoneBase {
10761076
if (!this.hidecode && !this.hidehistory) {
10771077
this.addHistoryScrubber(true);
10781078
}
1079-
if ($(this.origElem).data("gradebutton") && !this.graderactive) {
1079+
if (this.parseBooleanAttribute(this.origElem, "data-gradebutton") && !this.graderactive) {
10801080
this.addFeedbackButton(ctrlDiv);
10811081
}
10821082
// Show/Hide Code
10831083
if (this.hidecode) {
10841084
this.enableHideShow(ctrlDiv);
10851085
}
10861086
// CodeLens
1087-
if ($(this.origElem).data("codelens") && !this.graderactive) {
1087+
if (this.parseBooleanAttribute(this.origElem, "data-codelens") && !this.graderactive) {
10881088
this.enableCodeLens(ctrlDiv);
10891089
}
10901090

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ export default class RunestoneBase {
4040
if (opts.enforceDeadline) {
4141
this.deadline = opts.deadline;
4242
}
43-
if ($(opts.orig).data("optional")) {
44-
this.optional = true;
45-
} else {
46-
this.optional = false;
47-
}
43+
this.optional = this.parseBooleanAttribute(opts.orig, "data-optional");
4844
if (opts.selector_id) {
4945
this.selector_id = opts.selector_id;
5046
}

bases/rsptx/interactives/runestone/datafile/js/datafile.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ class DataFile extends RunestoneBase {
2121
var orig = opts.orig; // entire <pre> element that will be replaced by new HTML
2222
this.origElem = orig;
2323
this.divid = orig.id;
24-
this.dataEdit = false;
25-
this.isImage = orig.dataset.isimage === "true" || orig.dataset.isimage === "" ? true : false;
26-
this.fileName = orig.dataset.filename || null;
27-
if (orig.dataset.edit === "true") {
28-
this.dataEdit = true;
29-
}
24+
this.dataEdit = this.parseBooleanAttribute(orig, "data-edit");
25+
this.isImage = this.parseBooleanAttribute(orig, "data-isimage");
3026
this.displayClass = "block"; // Users can specify the non-edit component to be hidden--default is not hidden
31-
if (orig.hasAttribute("data-hidden")) {
27+
if (this.parseBooleanAttribute(orig, "data-hidden")) {
3228
this.displayClass = "none";
3329
}
3430
// Users can specify numbers of rows/columns when editing is true

bases/rsptx/interactives/runestone/hparsons/js/hparsons.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export default class HParsons extends RunestoneBase {
2222
super(opts);
2323
// getting settings
2424
var orig = opts.orig.querySelector("textarea");
25-
this.reuse = orig.getAttribute("data-reuse") ? true : false;
26-
this.randomize = orig.getAttribute("data-randomize") ? true : false;
27-
this.isBlockGrading = orig.getAttribute("data-blockanswer") ? true : false;
25+
this.reuse = this.parseBooleanAttribute(orig, "data-reuse");
26+
this.randomize = this.parseBooleanAttribute(orig, "data-randomize");
27+
this.isBlockGrading = this.parseBooleanAttribute(orig, "data-blockanswer");
2828
this.language = orig.getAttribute("data-language");
2929
// Detect math mode
3030
if (this.language === undefined && orig.textContent.includes('span class="process-math"')) {

0 commit comments

Comments
 (0)