-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.html
217 lines (181 loc) · 5.32 KB
/
calculator.html
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<meta charset="utf-8">
<title>Calculator</title>
<meta name="description" content="Saar">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="style.css">
<script src="jquery.js" type="text/javascript"></script>
<script src="Calculator.js" type="text/javascript"></script>
</head>
<body>
<div id="calculator">
<div id="kb_xtra_toggle">º</div>
<div id="outcome">
<div id="control_unit">
<div id="last_memory"></div>
<div id="last_operation"></div>
</div>
0
</div>
<div id="keypad_extra">
<div class="keyrow">
<button id="btn_pi" class="btn_e steel" data-digit="pi">
<small>π</small></button>
<button id="btn_pow2" class="btn_e steel" data-digit="pow2">
<small>x²</small></button>
<button id="btn_pow2" class="btn_e steel" data-digit="pow3">
<small>x³</small></button>
<button id="btn_sqrt" class="btn_e steel" data-digit="sqrt">
<small>√</small></button>
</div>
</div>
<div id="keypad">
<div class="keyrow">
<button id="btn_clear" class="btn gray" data-digit="clear">C</button>
<button id="btn_negative" class="btn gray" data-digit="negative">±</button>
<button id="btn_percent" class="btn gray" data-digit="percent">%</button>
<button id="btn_divide" class="btn orange" data-digit="divide">÷</button>
</div>
<div class="keyrow">
<button id="btn_k7" class="btn" data-digit="7">7</button>
<button id="btn_k8" class="btn" data-digit="8">8</button>
<button id="btn_k9" class="btn" data-digit="9">9</button>
<button id="btn_multiply" class="btn orange" data-digit="multiply">×</button>
</div>
<div class="keyrow">
<button id="btn_k4" class="btn" data-digit="4">4</button>
<button id="btn_k5" class="btn" data-digit="5">5</button>
<button id="btn_k6" class="btn" data-digit="6">6</button>
<button id="btn_minus" class="btn orange" data-digit="minus">-</button>
</div>
<div class="keyrow">
<button id="btn_k1" class="btn" data-digit="1">1</button>
<button id="btn_k2" class="btn" data-digit="2">2</button>
<button id="btn_k3" class="btn" data-digit="3">3</button>
<button id="btn_plus" class="btn orange" data-digit="plus">+</button>
</div>
<div class="keyrow">
<button id="btn_k0" class="btn btn2" data-digit="0">0</button>
<button id="btn_dot" class="btn" data-digit=".">·</button>
<button id="btn_compute" class="btn green" data-digit="compute">=</button>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
var debug = false;
if (window.location.hash &&
(window.location.hash === "#debug")) {
debug = true;
}
$(document).on("keypress", function(event) {
switch (event.which) {
case 13:
$("#btn_compute").trigger("click");
break;
case 61:
$("#btn_compute").trigger("click");
break;
case 99:
$("#btn_clear").trigger("click");
break;
case 37:
$("#btn_percent").trigger("click");
break;
case 177:
$("#btn_negative").trigger("click");
break;
case 42:
$("#btn_multiply").trigger("click");
break;
case 43:
$("#btn_plus").trigger("click");
break;
case 45:
$("#btn_minus").trigger("click");
break;
case 47:
$("#btn_divide").trigger("click");
break;
case 46:
$("#btn_dot").trigger("click");
break;
case 48:
$("#btn_k0").trigger("click");
break;
case 49:
$("#btn_k1").trigger("click");
break;
case 50:
$("#btn_k2").trigger("click");
break;
case 51:
$("#btn_k3").trigger("click");
break;
case 52:
$("#btn_k4").trigger("click");
break;
case 53:
$("#btn_k5").trigger("click");
break;
case 54:
$("#btn_k6").trigger("click");
break;
case 55:
$("#btn_k7").trigger("click");
break;
case 56:
$("#btn_k8").trigger("click");
break;
case 57:
$("#btn_k9").trigger("click");
break;
default:
//alert(event.which);
break;
}
});
$("#kb_xtra_toggle").on("click", function() {
$("#keypad_extra").toggle();
});
var sC = $("#calculator");
var sCw = sC.width();
var sCh = sC.height();
var sW = $(window).width();
var sH = $(window).height();
sC.css('left', ((sW - sCw) / 2) + 'px');
sC.css('top', ((sH - sCh) / 2) + 'px');
$(window).resize(function() {
sW = $(window).width();
sH = $(window).height();
sC.css('left', ((sW - sCw) / 2) + 'px');
sC.css('top', ((sH - sCh) / 2) + 'px');
});
var display = $("#outcome");
var cUnit = $("#control_unit");
var calculator = new Calculator(10, false, debug);
$(".btn").on("click", function() {
var digit = $(this).data("digit");
calculator.compute(digit);
display.text(calculator.display());
display.prepend(cUnit);
cUnit.find("#last_operation").html(
calculator.operation() + " " + calculator.memory_save);
cUnit.find("#last_memory").text(calculator.memoryDisplay());
});
$(".btn_e").on("click", function() {
var digit = $(this).data("digit");
calculator.compute(digit);
display.text(calculator.display());
display.prepend(cUnit);
cUnit.find("#last_operation").html(
calculator.operation() + " " + calculator.memory_save);
cUnit.find("#last_memory").text(calculator.memoryDisplay());
});
});
</script>
</body>
</html>