make evaluateDataChecks a function, not a method in Location. make so can in main-nav
make evaluateDataChecks a function, not a method in Location. make so can in main-nav
diff --git a/js/game.js b/js/game.js
index c9f57ca..ef37921 100644
--- a/js/game.js
+++ b/js/game.js
@@ -489,6 +489,47 @@ function interpolateVariables(text)
}
return text;
}
+/**
+ * A data-ck attribute on any tag other than an x-present tag can
+ * contain a Javascript boolean expression to control the display
+ * or non-display of that element. This is similar to a ck attribute
+ * of an x-present tag. This method evalutes data-ck expressions for
+ * each tag in the text in its section argument and adds a class="none"
+ * attribute to that tag if it evaluates to false (causing it not to
+ * display). The string after these substitutions is returned.
+ *
+ * @param {string} section of text to check for data-ck attributes and
+ * for which to carry out the above described substitutions
+ * @return {string} after substitutions have been carried out.
+ */
+function evaluateDataChecks(section)
+{
+ let quote = `(?:(?:'([^']*)')|(?:"([^"]*)"))`;
+ let old_section = "";
+ while (section != old_section) {
+ old_section = section;
+ let data_ck_pattern = new RegExp(
+ "\<(?:[^\>]+)(data\-ck\s*\=\s*(" + quote + "))(?:[^\>]*)\>",
+ 'i');
+ let data_ck_match = section.match(data_ck_pattern);
+ if (!data_ck_match) {
+ continue;
+ }
+ let condition = (typeof data_ck_match[3] == 'string') ?
+ data_ck_match[3] : data_ck_match[4];
+ if (typeof condition == 'string') {
+ let check_result = (condition.replace(/\s+/, "") != "") ?
+ eval(condition) : true;
+ if (check_result) {
+ section = section.replace(data_ck_match[1], " ");
+ } else {
+ section = section.replace(data_ck_match[1],
+ " class='none' ");
+ }
+ }
+ }
+ return section;
+}
/**
* Returns the game object with the provided id.
* @param {string} object_id to get game object for
@@ -651,6 +692,7 @@ class Location
content.originalHTML = content.innerHTML;
}
content.innerHTML = interpolateVariables(content.originalHTML);
+ content.innerHTML = evaluateDataChecks(content.innerHTML);
game.initializeGameNavListeners();
}
let control_types = ["input", "textarea", "select"];
@@ -772,47 +814,6 @@ class Location
}
return [check_result, proceed, pause];
}
- /**
- * A data-ck attribute on any tag other than an x-present tag can
- * contain a Javascript boolean expression to control the display
- * or non-display of that element. This is similar to a ck attribute
- * of an x-present tag. This method evalutes data-ck expressions for
- * each tag in the text in its section argument and adds a class="none"
- * attribute to that tag if it evaluates to false (causing it not to
- * display). The string after these substitutions is returned.
- *
- * @param {string} section of text to check for data-ck attributes and
- * for which to carry out the above described substitutions
- * @return {string} after substitutions have been carried out.
- */
- evaluateDataChecks(section)
- {
- let quote = `(?:(?:'([^']*)')|(?:"([^"]*)"))`;
- let old_section = "";
- while (section != old_section) {
- old_section = section;
- let data_ck_pattern = new RegExp(
- "\<(?:[^\>]+)(data\-ck\s*\=\s*(" + quote + "))(?:[^\>]*)\>",
- 'i');
- let data_ck_match = section.match(data_ck_pattern);
- if (!data_ck_match) {
- continue;
- }
- let condition = (typeof data_ck_match[3] == 'string') ?
- data_ck_match[3] : data_ck_match[4];
- if (typeof condition == 'string') {
- let check_result = (condition.replace(/\s+/, "") != "") ?
- eval(condition) : true;
- if (check_result) {
- section = section.replace(data_ck_match[1], " ");
- } else {
- section = section.replace(data_ck_match[1],
- " class='none' ");
- }
- }
- }
- return section;
- }
/**
* A given Location contains one or more x-present tags which are
* used when rendering that location to the game-content area. This
@@ -828,7 +829,7 @@ class Location
{
let old_section = "";
let quote = `(?:(?:'([^']*)')|(?:"([^"]*)"))`;
- section = this.evaluateDataChecks(section);
+ section = evaluateDataChecks(section);
section = interpolateVariables(section);
while (section != old_section) {
old_section = section;