diff --git a/src/js/textbox2.js b/src/js/textbox2.js index 49939341d27058b2c07faab4e754f6543206dcdf..6d605fa36c20c11d34ac8e3def99aebd91901170 100644 --- a/src/js/textbox2.js +++ b/src/js/textbox2.js @@ -14,8 +14,8 @@ Macro.add("textbox2", { var a = this.args[1]; var isNumber = typeof(a) === "number"; var inputElement = document.createElement("input"), - autofocus = false, - passage = void 0; + autofocus = false, + passage = void 0; var setargs = null; if (this.args.length > 3) { passage = this.args[2]; @@ -64,20 +64,20 @@ Macro.add("textbox2", { jQuery(inputElement).attr({ id: this.name + "-" + r, name: this.name + "-" + r, -// type: isNumber ? "number" : "text", /* TODO - hide spinner if we do this */ + // type: isNumber ? "number" : "text", /* TODO - hide spinner if we do this */ tabindex: 0 }).addClass("macro-" + this.name) - .on("change", function() { - State.setVar(t, valueToNumberIfSame(this.value)); - }).on("blur", function() { - State.setVar(t, valueToNumberIfSame(this.value)); - if (this.value != a) { // If the value has actually changed, reload the page. Note != and not !== because types might be different - gotoPassage(); - } - }) - .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) { + .on("change", function() { + State.setVar(t, valueToNumberIfSame(this.value)); + }).on("blur", function() { + State.setVar(t, valueToNumberIfSame(this.value)); + if (this.value != a) { // If the value has actually changed, reload the page. Note != and not !== because types might be different + gotoPassage(); + } + }) + .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) { delete postdisplay[e], setTimeout(function() { return inputElement.focus() }, Engine.minDomActionDelay)