Tweaked {JavaScript, TypeScript, HTML} code to encapsulate the application members.

pull/39/merge
Project Nayuki 6 years ago
parent 3ab5e7827c
commit 6d79c97c42

@ -24,6 +24,8 @@
"use strict";
var app = new function() {
function initialize() {
var elems = document.querySelectorAll("input[type=number], textarea");
for (var i = 0; i < elems.length; i++) {
@ -143,7 +145,7 @@ function redrawQrCode() {
}
function handleVersionMinMax(which) {
this.handleVersionMinMax = function(which) {
var minElem = document.getElementById("version-min-input");
var maxElem = document.getElementById("version-max-input");
var minVal = parseInt(minElem.value, 10);
@ -161,3 +163,4 @@ function handleVersionMinMax(which) {
initialize();
}

@ -95,8 +95,8 @@
<tr>
<td>Version range:</td>
<td>
Minimum = <input type="number" value="1" min="1" max="40" step="1" id="version-min-input" style="width:4em" oninput="handleVersionMinMax('min');">,
maximum = <input type="number" value="40" min="1" max="40" step="1" id="version-max-input" style="width:4em" oninput="handleVersionMinMax('max');">
Minimum = <input type="number" value="1" min="1" max="40" step="1" id="version-min-input" style="width:4em" oninput="app.handleVersionMinMax('min');">,
maximum = <input type="number" value="40" min="1" max="40" step="1" id="version-max-input" style="width:4em" oninput="app.handleVersionMinMax('max');">
</td>
</tr>
<tr>

@ -24,26 +24,24 @@
"use strict";
{
const myWindow = window as any;
namespace app {
function initialize(): void {
let elems = document.querySelectorAll("input[type=number], textarea");
for (let el of elems) {
if (!el.id.startsWith("version-"))
(el as any).oninput = myWindow.redrawQrCode;
(el as any).oninput = redrawQrCode;
}
elems = document.querySelectorAll("input[type=radio], input[type=checkbox]");
for (let el of elems)
(el as HTMLInputElement).onchange = myWindow.redrawQrCode;
myWindow.redrawQrCode();
(el as HTMLInputElement).onchange = redrawQrCode;
redrawQrCode();
}
/*---- Functions called from HTML code ----*/
myWindow.redrawQrCode = function(): void {
function redrawQrCode(): void {
// Show/hide rows based on bitmap/vector image output
const bitmapOutput: boolean = getInput("output-format-bitmap").checked;
const scaleRow : HTMLElement = getElem("scale-row");
@ -150,7 +148,7 @@
}
myWindow.handleVersionMinMax = function(which: "min"|"max"): void {
export function handleVersionMinMax(which: "min"|"max"): void {
const minElem: HTMLInputElement = getInput("version-min-input");
const maxElem: HTMLInputElement = getInput("version-max-input");
let minVal: number = parseInt(minElem.value, 10);
@ -163,7 +161,7 @@
minVal = maxVal;
minElem.value = minVal.toString();
maxElem.value = maxVal.toString();
myWindow.redrawQrCode();
redrawQrCode();
}

Loading…
Cancel
Save