diff --git a/src/js/textInput.js b/src/js/textInput.js index 2e4cbbe37898b4f4968f00742529ce14abb33929..a7371b2983e0f4841ab2b31245e1b8ffb04b6ac8 100644 --- a/src/js/textInput.js +++ b/src/js/textInput.js @@ -5,10 +5,10 @@ Macro.add("textinput", { handler: function() { if (this.args.length < 2) { - var errors = []; + const errors = []; if (this.args.length < 1) { errors.push("variable name"); } if (this.args.length < 2) { errors.push("default value"); } - return this.error("no " + errors.join(" or ") + " specified"); + return this.error(`no ${errors.join(" or ")} specified`); } // Ensure that the variable name argument is a string. @@ -16,16 +16,16 @@ Macro.add("textinput", { return this.error("variable name argument is not a string"); } - var varName = this.args[0].trim(); + const varName = this.args[0].trim(); // Try to ensure that we receive the variable's name (incl. sigil), not its value. if (varName[0] !== "$" && varName[0] !== "_") { - return this.error("variable name '" + varName + "' is missing its sigil ($ or _)"); + return this.error(`variable name '${varName}' is missing its sigil ($ or _)`); } - var that = this; - var defaultValue = this.args[1]; - var el = document.createElement("textarea"); + const that = this; + const defaultValue = this.args[1]; + const el = document.createElement("textarea"); // Setup and append the textarea element to the output buffer. jQuery(el) @@ -37,8 +37,9 @@ Macro.add("textinput", { .addClass("macro-textarea") // "hijack" the .macro-textarea class .on("input", function() { Wikifier.setValue(varName, this.value); - if (that.payload[0].contents !== "") + if (that.payload[0].contents !== "") { Wikifier.wikifyEval(that.payload[0].contents.trim()); + } }) .appendTo(this.output); diff --git a/src/js/textbox2.js b/src/js/textbox2.js index 6d605fa36c20c11d34ac8e3def99aebd91901170..a372a788e562f4eb1b58ea6b8d58bfa9a29d5fe4 100644 --- a/src/js/textbox2.js +++ b/src/js/textbox2.js @@ -1,22 +1,22 @@ Macro.add("textbox2", { handler: function() { if (this.args.length < 2) { - var e = []; - return this.args.length < 1 && e.push("variable name"), this.args.length < 2 && e.push("default value"), this.error("no " + e.join(" or ") + " specified") + const e = []; + return this.args.length < 1 && e.push("variable name"), this.args.length < 2 && e.push("default value"), this.error(`no ${ e.join(" or ") } specified`); } - if ("string" != typeof this.args[0]) return this.error("variable name argument is not a string"); - var t = this.args[0].trim(); - if ("$" !== t[0] && "_" !== t[0]) return this.error('variable name "' + this.args[0] + '" is missing its sigil ($ or _)'); + if ("string" !== typeof this.args[0]) return this.error("variable name argument is not a string"); + const t = this.args[0].trim(); + if ("$" !== t[0] && "_" !== t[0]) return this.error(`variable name "${ this.args[0] }" is missing its sigil ($ or _)`); Config.debug && this.debugView.modes({ block: true }); - var r = Util.slugify(t); - var a = this.args[1]; - var isNumber = typeof(a) === "number"; - var inputElement = document.createElement("input"), - autofocus = false, - passage = void 0; - var setargs = null; + const r = Util.slugify(t); + const a = this.args[1]; + const isNumber = typeof(a) === "number"; + const inputElement = document.createElement("input"); + let autofocus = false; + let passage = void 0; + let setargs = null; if (this.args.length > 3) { passage = this.args[2]; autofocus = "autofocus" === this.args[3]; @@ -30,7 +30,7 @@ Macro.add("textbox2", { passage = this.args[2]; } } - if (passage !== (void 0) && _typeof(passage) === "object") { + if (passage !== (void 0) && typeof(passage) === "object") { passage = passage.link; } if (!passage) { @@ -39,34 +39,35 @@ Macro.add("textbox2", { function gotoPassage() { if (passage) { - var currentScrollPosition = window.pageYOffset; - var currentPassage = State.passage; + const currentScrollPosition = window.pageYOffset; + const currentPassage = State.passage; if (setargs) { Scripting.evalTwineScript(setargs); } Engine.play(passage); - if (currentPassage == passage) { - Scripting.evalJavaScript("window.scrollTo(0, " + currentScrollPosition + ");"); + if (currentPassage === passage) { + Scripting.evalJavaScript(`window.scrollTo(0, ${ currentScrollPosition });`); } } } function valueToNumberIfSame(v) { - if (!isNumber) - return v; // Do nothing + if (!isNumber) { + return v; + } // Do nothing try { return parseInt(v, 10); - } catch(e) { + } catch (e) { return v; } } jQuery(inputElement).attr({ - id: this.name + "-" + r, - name: this.name + "-" + r, + id: `${this.name }-${ r}`, + name: `${this.name }-${ r}`, // type: isNumber ? "number" : "text", /* TODO - hide spinner if we do this */ tabindex: 0 - }).addClass("macro-" + this.name) + }).addClass(`macro-${ this.name}`) .on("change", function() { State.setVar(t, valueToNumberIfSame(this.value)); }).on("blur", function() { @@ -76,11 +77,11 @@ Macro.add("textbox2", { } }) .on("keypress", function(e) { - 13 === e.which && (e.preventDefault(), State.setVar(t, valueToNumberIfSame(this.value)), gotoPassage()) - }).appendTo(this.output), State.setVar(t, a), inputElement.value = a, autofocus && (inputElement.setAttribute("autofocus", "autofocus"), postdisplay["#autofocus:" + inputElement.id] = function(e) { + 13 === e.which && (e.preventDefault(), State.setVar(t, valueToNumberIfSame(this.value)), gotoPassage()); + }).appendTo(this.output), State.setVar(t, a), inputElement.value = a, autofocus && (inputElement.setAttribute("autofocus", "autofocus"), postdisplay[`#autofocus:${ inputElement.id}`] = function(e) { delete postdisplay[e], setTimeout(function() { - return inputElement.focus() - }, Engine.minDomActionDelay) - }) + return inputElement.focus(); + }, Engine.minDomActionDelay); + }); } -}) +}); diff --git a/src/js/textboxJS.js b/src/js/textboxJS.js index d0798dbd0c6c486764a2a1a31904d9e40713e233..cb5213593f77e0f4021a7174b771459b7c0be3c0 100644 --- a/src/js/textboxJS.js +++ b/src/js/textboxJS.js @@ -1,27 +1,27 @@ /* eslint-disable no-undef */ /* Nicked off greyelf, works for replace textboxes */ window.setReplaceTextboxMaxLength = function (storyVarName, maxLength) { - var textboxId = '#textbox-' + Util.slugify(storyVarName); + const textboxId = `#textbox-${ Util.slugify(storyVarName)}`; $(textboxId) - .attr('maxlength', maxLength) + .attr("maxlength", maxLength) .css({ - 'min-width' : 'initial', - width : maxLength + 'em', - padding : '3px 2px' + "min-width": "initial", + "width": `${maxLength }em`, + "padding": "3px 2px" }); }; /* Nicked off TheMadExile, works for non-replace textboxes */ window.setTextboxMaxLength = function (storyVarName, maxLength) { - var textboxId = '#textbox-' + Util.slugify(storyVarName); - postdisplay[textboxId + '-maxlength'] = function (taskName) { + const textboxId = `#textbox-${ Util.slugify(storyVarName)}`; + postdisplay[`${textboxId }-maxlength`] = function (taskName) { delete postdisplay[taskName]; $(textboxId) - .attr('maxlength', maxLength) + .attr("maxlength", maxLength) .css({ - 'min-width' : 'initial', - width : maxLength + 'em', - padding : '3px 2px' + "min-width": "initial", + "width": `${maxLength }em`, + "padding": "3px 2px" }); }; };