-
-
Notifications
You must be signed in to change notification settings - Fork 133
/
jsfile.js
149 lines (140 loc) · 5.55 KB
/
jsfile.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
window.onload = function() {
document.getElementById('calc-diameter').style.display = "none";
document.getElementById('calc-side1').style.display = "none";
document.getElementById('calc-side2').style.display = "none";
document.getElementById('calc-side3').style.display = "none";
document.getElementById('calculate-circle').style.display = "none";
document.getElementById('calculate-triangle').style.display = "none";
}
function rectangle() {
w = Number(document.calculator.width.value);
l = Number(document.calculator.length.value);
d = Number(document.calculator.depth.value);
w = w * (1 / 3);
l = l * (1 / 3);
d = d * (1 / 36);
z = w * l * d;
z = Math.round(z * 100) / 100;
document.calculator.total.value = z;
}
function circle() {
dia = Number(document.calculator.diameter.value);
d = Number(document.calculator.depth.value);
p = Math.PI;
d = d * (1 / 36);
dia = dia * (1 / 3);
dia = dia * dia;
z = (p * dia * d) / 4;
z = Math.round(z * 100) / 100;
document.calculator.total.value = z;
}
function triangle() {
s1 = Number(document.calculator.side1.value);
s2 = Number(document.calculator.side2.value);
s3 = Number(document.calculator.side3.value);
d = Number(document.calculator.depth.value);
s1 = s1 * (1 / 3);
s2 = s2 * (1 / 3);
s3 = s3 * (1 / 3);
d = d * (1 / 36);
parim = (s1 + s2 + s3) / 2;
sq = parim * (parim - s1) * (parim - s2) * (parim - s3);
sq = Math.sqrt(sq);
z = sq * d;
z = Math.round(z * 100) / 100;
document.calculator.total.value = z;
}
function rectangleSelect() {
document.getElementById('calc-diameter').style.display = "none";
document.getElementById('calc-width').style.display = "block";
document.getElementById('calc-length').style.display = "block";
document.getElementById('calc-side1').style.display = "none";
document.getElementById('calc-side2').style.display = "none";
document.getElementById('calc-side3').style.display = "none";
document.getElementById('calculate-rectangle').style.display = "block";
document.getElementById('calculate-circle').style.display = "none";
document.getElementById('calculate-triangle').style.display = "none";
document.getElementById('calculate-triangle').style.display = "none";
document.getElementById("rectangleButton").className += "calculatorSelected";
document.getElementById("circleButton").className = "";
document.getElementById("triangleButton").className = "";
}
function circleSelect() {
document.getElementById('calc-diameter').style.display = "block";
document.getElementById('calc-width').style.display = "none";
document.getElementById('calc-length').style.display = "none";
document.getElementById('calc-side1').style.display = "none";
document.getElementById('calc-side2').style.display = "none";
document.getElementById('calc-side3').style.display = "none";
document.getElementById('calculate-rectangle').style.display = "none";
document.getElementById('calculate-circle').style.display = "block";
document.getElementById('calculate-triangle').style.display = "none";
document.getElementById("rectangleButton").className = "";
document.getElementById("circleButton").className += "calculatorSelected";
document.getElementById("triangleButton").className = "";
}
function triangleSelect() {
document.getElementById('calc-diameter').style.display = "none";
document.getElementById('calc-width').style.display = "none";
document.getElementById('calc-length').style.display = "none";
document.getElementById('calc-side1').style.display = "block";
document.getElementById('calc-side2').style.display = "block";
document.getElementById('calc-side3').style.display = "block";
document.getElementById('calculate-rectangle').style.display = "none";
document.getElementById('calculate-circle').style.display = "none";
document.getElementById('calculate-triangle').style.display = "block";
document.getElementById("rectangleButton").className = "";
document.getElementById("circleButton").className = "";
document.getElementById("triangleButton").className += "calculatorSelected";
}
function getEventX(event) {
var posx = 0;
if (event.pageX || event.pageY) {
posx = event.pageX;
}
else if (event.clientX || event.clientY) {
posx = event.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
}
return posx;
}
function getOffset(elem) {
var box = (typeof elem.getBoundingClientRect !== 'undefined') ?
elem.getBoundingClientRect() : {top: 0, left: 0};
var w = window, d = elem.ownerDocument.documentElement;
return {
top: box.top + (w.pageYOffset || d.scrollTop) - (d.clientTop || 0),
left: box.left + (w.pageXOffset || d.scrollLeft) - (d.clientLeft || 0)
};
}
function getElementX(obj) {
return Math.round(getOffset(obj).left);
}
function zeroPad(str,len) {
var i;
var pad = "";
var s = str.toString();
for(i=s.length; i < len; i++) {
pad = "0".toString() + pad.toString();
}
return pad.toString() + s.toString();
}
function dateToTimestamp(date) {
return date.getFullYear() +
zeroPad(date.getMonth()+1,2) +
zeroPad(date.getDay()+1,2) +
zeroPad(date.getHours(),2) +
zeroPad(date.getMinutes(),2) +
zeroPad(date.getSeconds(),2);
}
function calcTimestamp(event,element,firstMS,lastMS) {
var eventX = getEventX(event);
var elementX = getElementX(element);
var elementWidth = element.width;
var msWidth = lastMS - firstMS;
var x = eventX - elementX;
var pct = x / elementWidth;
var pctDate = pct * msWidth;
var date = pctDate + firstMS;
return dateToTimestamp(new Date(date));
}