-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractiveElements.js
More file actions
116 lines (116 loc) · 5.37 KB
/
Copy pathinteractiveElements.js
File metadata and controls
116 lines (116 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"use strict";
// This file should be the only one that has top-level code.
// Preinitialization
let result = new UncertainNumber({}); // = 0
// let operation: string = ""
$(document).ready(() => {
//****************************************************************
// EVENT LISTENER
//****************************************************************
// $("#operatorSelect input[name='operator']").on("change", function () {
// console.log($(this).attr("id")); // Logs the ID of the selected radio button
// });
//****************************************************************
// SUBMIT button
//****************************************************************
$('#submit').on('click', () => {
console.log("SUBMIT PRESSED");
// console.log("Selected operation: ", $("#operatorSelect input[name='operator']:checked").attr("id"));
// Parse both inputs
let x = $("#xA").val();
// User types in as % (100x too big) if relative
let error = $("#errorA").val();
let isAbsolute = $("#absoluteA").prop("checked");
const a = UncertainNumber.New({
x: x,
error: isAbsolute ? error : (error * 0.01),
isAbsolute: isAbsolute
});
x = $("#xB").val();
error = $("#errorB").val();
isAbsolute = $("#absoluteB").prop("checked");
const b = UncertainNumber.New({
x: x,
error: isAbsolute ? error : (error * 0.01),
isAbsolute: isAbsolute
});
console.log("Both UncertainNumber's parsed.");
// Switch based on operation selected
// $("#operatorSelect input[name='operator']").addClass('highlight');
// Update operation
/*const operation: string*/ // operation = $("#operatorSelect input[name='operator']:checked").first().attr('id');
// Find the selected operation.
// let operation: string = "";
// Scan each of the 5 radio buttons.
// for (const radioButton of $("#operatorSelect input")) {
// const id: string = radioButton.attr('id');
// const isChecked = radioButton.prop('checked');
// console.log("#${id} is checked? ${isChecked}.")
// if (isChecked) {
// operation = id;
// break;
// }
// }
if ($("#plus").prop("checked")) {
result = a.plus(b);
}
else if ($("#minus").prop("checked")) {
result = a.minus(b);
}
else if ($("#times").prop("checked")) {
result = a.times(b);
}
else if ($("#divideBy").prop("checked")) {
result = a.divideBy(b);
}
else {
result = a.raiseTo(b);
}
// console.log(operation);
// switch (operation) {
// case "plus": result = a.plus(b); break;
// case "minus": result = a.minus(b); break;
// case "times": result = a.times(b); break;
// case "divideBy": result = a.divideBy(b); break;
// case "raiseTo": result = a.raiseTo(b); break;
// default: console.log("Operation switch default");
// }
// Display the answer & extra info
$('#answer').html(result.toString({ reportAbsolute: true }) + "<br>" + result.toString({ reportAbsolute: false }));
$('#summary').prepend(result.summary + "<br>");
});
});
//class jQueryElement {
// element: any; // The HTML element reference.
//
// private constructor(element: any) {
// this.element = element;
// }
//
// // Initialize from id.
// static fromId(idString: string): jQueryElement {
// return new this($('#' + idString));
// }
//
// // Initialize from class.
// static fromClass(classString: string): jQueryElement {
// return new this($('.' + classString));
// }
//
// set text(toString: string): void {
// this.element.text(toString);
// }
//}
// class ClickableElement {
// element: any;
// handleClick: () => void;
// constructor(jQuerySelection: any, handleClick: () => void = () => {}) {
// this.element = jQuerySelection;
// this.handleClick = handleClick;
// }
// onClick(): void {
// this.element.on('click', this.handleClick);
// }
// }
// new ClickableElement($('#changeColorCheme'), () => {
// }