|
| 1 | +<!-- Sample HTML Template made for the Open-Source software WinWidgets --> |
| 2 | +<style> |
| 3 | + @import url("https://fonts.googleapis.com/css2?family=Jaldi&display=swap"); |
| 4 | + |
| 5 | + body, |
| 6 | + html { |
| 7 | + background: rgb(19, 19, 19); |
| 8 | + display: flex; |
| 9 | + justify-content: center; |
| 10 | + align-items: center; |
| 11 | + font-family: Jaldi, sans-serif, monospace; |
| 12 | + overflow: hidden; |
| 13 | + user-select: none; |
| 14 | + -moz-user-select: none; |
| 15 | + } |
| 16 | + |
| 17 | + .calculator-body { |
| 18 | + display: flex; |
| 19 | + flex-direction: column; |
| 20 | + gap: 8px; |
| 21 | + width: 360px; |
| 22 | + z-index: 1; |
| 23 | + font-weight: semibold; |
| 24 | + } |
| 25 | + |
| 26 | + .buttons { |
| 27 | + display: flex; |
| 28 | + flex-direction: row; |
| 29 | + gap: 8px; |
| 30 | + } |
| 31 | + |
| 32 | + .button { |
| 33 | + display: flex; |
| 34 | + justify-content: center; |
| 35 | + align-items: center; |
| 36 | + background: black; |
| 37 | + opacity: 0.8; |
| 38 | + color: white; |
| 39 | + padding: 10px 0; |
| 40 | + width: 0.5rem; |
| 41 | + border-radius: 10px; |
| 42 | + flex: 1 1 10px; |
| 43 | + transition: background-color 0.1s ease-in-out, border 0.1s ease-in-out; |
| 44 | + cursor: pointer; |
| 45 | + border: 1px solid black; |
| 46 | + } |
| 47 | + |
| 48 | + .button:hover { |
| 49 | + background-color: rgb(19, 19, 19); |
| 50 | + border: 1px solid rgb(209, 67, 15); |
| 51 | + } |
| 52 | + |
| 53 | + .display { |
| 54 | + background: black; |
| 55 | + opacity: 0.8; |
| 56 | + color: white; |
| 57 | + width: 100%; |
| 58 | + padding: 20px; |
| 59 | + border-radius: 10px; |
| 60 | + min-height: 20px; |
| 61 | + display: flex; |
| 62 | + align-items: center; |
| 63 | + } |
| 64 | + |
| 65 | + .equals { |
| 66 | + background: rgb(209, 67, 15); |
| 67 | + } |
| 68 | +</style> |
| 69 | + |
| 70 | +<script> |
| 71 | + var isMouseOverDOM = false; |
| 72 | + |
| 73 | + var keyPressTime = new Date(); |
| 74 | + |
| 75 | + var toExec = " "; |
| 76 | + |
| 77 | + var expressionRegistry = { |
| 78 | + "tan(":"Math.tan(", |
| 79 | + "sin(":"Math.sin(", |
| 80 | + "cos(":"Math.cos(", |
| 81 | + "deg":"*Math.PI/180", |
| 82 | + "ln(":"Math.log(", |
| 83 | + "lg(":"Math.log10(", |
| 84 | + "^":"**", |
| 85 | + "°":"*Math.PI*180", |
| 86 | + "rad":"*180/Math.PI", |
| 87 | + "e":"Math.E", |
| 88 | + "π":"Math.PI", |
| 89 | + "abs(":"Math.abs(", |
| 90 | + "^3":"**3", |
| 91 | + "^-1":"**-1", |
| 92 | + "√(":"Math.sqrt(", |
| 93 | + "%":"/100" |
| 94 | + }; |
| 95 | + |
| 96 | + document.addEventListener('mouseover', () => isMouseOverDOM = true); |
| 97 | + |
| 98 | + document.addEventListener('mouseout', () => isMouseOverDOM = false); |
| 99 | + |
| 100 | + function onClear() { |
| 101 | + document.getElementById("calculation").innerText = ""; |
| 102 | + toExec = ""; |
| 103 | + document.getElementById("toExec").innerText = toExec; |
| 104 | + } |
| 105 | + |
| 106 | + function onEqualsClicked() { |
| 107 | + const calc = document.getElementById("calculation"); |
| 108 | + calc.innerText = eval(toExec); |
| 109 | + toExec = calc.innerText; |
| 110 | + } |
| 111 | + |
| 112 | + function onButtonClicked(e) { |
| 113 | + document.getElementById("calculation").innerText += e; |
| 114 | + toExec += e; |
| 115 | + //document.getElementById("toExec").innerText = toExec; |
| 116 | + } |
| 117 | + |
| 118 | + function onSpecialClicked(e){ |
| 119 | + document.getElementById("calculation").innerText += e; |
| 120 | + toExec += expressionRegistry[e]; |
| 121 | + //document.getElementById("toExec").innerText = toExec; |
| 122 | + } |
| 123 | + |
| 124 | + function onNativeKeyEvents(key) { |
| 125 | + /* |
| 126 | + ** 1- Checking if the input type is a keyboard event |
| 127 | + ** 2- Checking if the time between the last key press and the current one is greater than 150ms |
| 128 | + ** 3- Checking if the mouse is over the DOM |
| 129 | + */ |
| 130 | + if (key.eventType == "keyboardEvent" && (new Date() - keyPressTime) > 150 && isMouseOverDOM) { |
| 131 | + //Getting the key code |
| 132 | + var code = parseInt(key.keycode); |
| 133 | + // Just input validation |
| 134 | + if ((code >= 40 && code <= 43)||(code >= 47 && code <= 57)) { |
| 135 | + const char = String.fromCharCode(parseInt(key.keycode)); |
| 136 | + keyPressTime = new Date(); |
| 137 | + onButtonClicked(char); |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | +</script> |
| 145 | + |
| 146 | +<!DOCTYPE html> |
| 147 | +<html> |
| 148 | + <head> |
| 149 | + <meta name="applicationTitle" content="Calculator" /> |
| 150 | + <meta name="windowSize" content="450 500" />x |
| 151 | + <meta name="windowBorderRadius" content="10" /> |
| 152 | + <meta name="previewSize" content="450 400" /> |
| 153 | + <meta name="windowOpacity" content="240" /> |
| 154 | + </head> |
| 155 | + <body> |
| 156 | + <div class="calculator-body"> |
| 157 | + <div class="display" id="calculation"></div> |
| 158 | + <div class="buttons"> |
| 159 | + <div class="button" onclick="onSpecialClicked('abs(')">abs</div> |
| 160 | + <div class="button" onclick="onSpecialClicked('^3')">^3</div> |
| 161 | + <div class="button" onclick="onSpecialClicked('^-1')">^-1</div> |
| 162 | + <div class="button" onclick="onSpecialClicked('√(')">√</div> |
| 163 | + <div class="button" onclick="onSpecialClicked('^2')">x^2</div> |
| 164 | + <div class="button" onclick="onSpecialClicked('^')">^x</sup></div> |
| 165 | + </div> |
| 166 | + <div class="buttons"> |
| 167 | + <div class="button" onclick="onSpecialClicked('lg(')">lg</div> |
| 168 | + <div class="button" onclick="onSpecialClicked('ln(')">ln</div> |
| 169 | + <div class="button" onclick="onSpecialClicked('sin(')">sin</div> |
| 170 | + <div class="button" onclick="onSpecialClicked('cos(')">cos</div> |
| 171 | + <div class="button" onclick="onSpecialClicked('tan(')">tan</div> |
| 172 | + <div class="button" onclick="onSpecialClicked('°')">°</div> |
| 173 | + </div> |
| 174 | + <div class="buttons"> |
| 175 | + <div class="button" onclick="onSpecialClicked('asin(')">asin</div> |
| 176 | + <div class="button" onclick="onSpecialClicked('acos(')">acos</div> |
| 177 | + <div class="button" onclick="onSpecialClicked('atan(')">atan</div> |
| 178 | + <div class="button" onclick="onButtonClicked('(')">(</div> |
| 179 | + <div class="button" onclick="onButtonClicked(')')">)</div> |
| 180 | + <div class="button" onclick="onSpecialClicked('rad')">rad</div> |
| 181 | + </div> |
| 182 | + <div class="buttons"> |
| 183 | + <div class="button" onclick="onButtonClicked('7')">7</div> |
| 184 | + <div class="button" onclick="onButtonClicked('8')">8</div> |
| 185 | + <div class="button" onclick="onButtonClicked('9')">9</div> |
| 186 | + <div class="button" onclick="onSpecialClicked('%')">%</div> |
| 187 | + <div class="button" onclick="onClear()">C</div> |
| 188 | + </div> |
| 189 | + <div class="buttons"> |
| 190 | + <div class="button" onclick="onButtonClicked('4')">4</div> |
| 191 | + <div class="button" onclick="onButtonClicked('5')">5</div> |
| 192 | + <div class="button" onclick="onButtonClicked('6')">6</div> |
| 193 | + <div class="button" onclick="onButtonClicked('*')">*</div> |
| 194 | + <div class="button" onclick="onButtonClicked('/')">/</div> |
| 195 | + </div> |
| 196 | + <div class="buttons"> |
| 197 | + <div class="button" onclick="onButtonClicked('1')">1</div> |
| 198 | + <div class="button" onclick="onButtonClicked('2')">2</div> |
| 199 | + <div class="button" onclick="onButtonClicked('3')">3</div> |
| 200 | + <div class="button" onclick="onButtonClicked('+')">+</div> |
| 201 | + <div class="button" onclick="onButtonClicked('-')">-</div> |
| 202 | + </div> |
| 203 | + <div class="buttons"> |
| 204 | + <div class="button" onclick="onButtonClicked('0')">0</div> |
| 205 | + <div class="button" onclick="onButtonClicked('.')">.</div> |
| 206 | + <div class="button" onclick="onButtonClicked('π')">π</div> |
| 207 | + <div class="button" onclick="onButtonClicked('e')">e</div> |
| 208 | + <div class="button equals" onclick="onEqualsClicked()">=</div> |
| 209 | + </div> |
| 210 | + </div> |
| 211 | + </body> |
| 212 | +</html> |
0 commit comments