4 * Description: Simple Calculator Application
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
10 use Friendica\Core\Hook;
13 function calc_install() {
14 Hook::register('app_menu', 'addon/calc/calc.php', 'calc_app_menu');
17 function calc_app_menu(array &$b)
19 $b['app_menu'][] = '<div class="app-title"><a href="calc">Calculator</a></div>';
23 * This is a statement rather than an actual function definition. The simple
24 * existence of this method is checked to figure out if the addon offers a
27 function calc_module() {}
33 <script language="JavaScript">
34 /**************************************
35 * www.FemaleNerd.com *
36 **************************************/
38 // Declare global variables
45 function addDisplay(n){
46 id = document.getElementById("display");
49 id.value = displayText
53 function addNumbers() {
54 if (displayText == "") {
57 num1 = parseFloat(displayText)
63 function subtractNumbers() {
64 if (displayText == "") {
67 num1 = parseFloat(displayText)
68 operatorType = "subtract"
73 function multiplyNumbers() {
74 if (displayText == "") {
77 num1 = parseFloat(displayText)
78 operatorType = "multiply"
83 function divideNumbers() {
84 if (displayText == "") {
87 num1 = parseFloat(displayText)
88 operatorType = "divide"
94 id = document.getElementById("display");
95 if (displayText == "") {
99 num1 = parseFloat(displayText)
102 result = Math.sin(num1)
107 alert("Please write the number first")
113 id = document.getElementById("display");
114 if (displayText == "") {
118 num1 = parseFloat(displayText)
121 result = Math.cos(num1)
126 alert("Please write the number first")
132 id = document.getElementById("display");
133 if (displayText == "") {
137 num1 = parseFloat(displayText)
140 result = Math.asin(num1)
145 alert("Please write the number first")
151 id = document.getElementById("display");
152 if (displayText == "") {
156 num1 = parseFloat(displayText)
159 result = Math.acos(num1)
164 alert("Please write the number first")
170 id = document.getElementById("display");
171 if (displayText == "") {
175 num1 = parseFloat(displayText)
178 result = Math.sqrt(num1)
183 alert("Please write the number first")
187 // Square number (number to the power of two)
189 id = document.getElementById("display");
190 if (displayText == "") {
194 num1 = parseFloat(displayText)
202 alert("Please write the number first")
206 // Convert degrees to radians
207 function degToRad() {
208 id = document.getElementById("display");
209 if (displayText == "") {
213 num1 = parseFloat(displayText)
216 result = num1 * Math.PI / 180
221 alert("Please write the number first")
225 // Convert radians to degrees
226 function radToDeg() {
227 id = document.getElementById("display");
228 if (displayText == "") {
232 num1 = parseFloat(displayText)
235 result = num1 * 180 / Math.PI
240 alert("Please write the number first")
245 function calculate() {
246 id = document.getElementById("display");
248 if (displayText != "") {
249 num2 = parseFloat(displayText)
251 if (operatorType == "add") {
256 if (operatorType == "subtract") {
260 // Calc: Multiplication
261 if (operatorType == "multiply") {
266 if (operatorType == "divide") {
273 id.value = "Oops! Error!"
278 function clearDisplay() {
279 id = document.getElementById("display");
287 DI::page()['htmlhead'] .= $x;
290 function calc_content($app) {
300 <table bgcolor="#af9999" border="1">
302 <table border="1" cellpadding="2" cellspacing="2">
305 <TR><TD VALIGN=top colspan=6 ALIGN="center"> <H2>Calculator</H2> </TD>
308 <td colspan="5"><input size="22" id="display" name="display" type="text"></td>
309 </tr><tr align="left" valign="middle">
310 <td><input name="one" value=" 1 " onclick="addDisplay(1)" type="button"></td>
311 <td><input name="two" value=" 2 " onclick="addDisplay(2)" type="button"></td>
312 <td><input name="three" value=" 3 " onclick="addDisplay(3)" type="button"></td>
313 <td><input name="plus" value=" + " onclick="addNumbers()" type="button"></td>
314 </tr><tr align="left" valign="middle">
315 <td><input name="four" value=" 4 " onclick="addDisplay(4)" type="button"></td>
316 <td><input name="five" value=" 5 " onclick="addDisplay(5)" type="button"></td>
317 <td><input name="six" value=" 6 " onclick="addDisplay(6)" type="button"></td>
318 <td><input name="minus" value=" - " onclick="subtractNumbers()" type="button"></td>
319 </tr><tr align="left" valign="middle">
320 <td><input name="seven" value=" 7 " onclick="addDisplay(7)" type="button"></td>
321 <td><input name="eight" value=" 8 " onclick="addDisplay(8)" type="button"></td>
322 <td><input name="nine" value=" 9 " onclick="addDisplay(9)" type="button"></td>
323 <td><input name="multiplication" value=" * " onclick="multiplyNumbers()" type="button"></td>
324 </tr><tr align="left" valign="middle">
325 <td><input name="zero" value=" 0 " onclick="addDisplay(0)" type="button"></td>
326 <td><input name="pi" value=" Pi " onclick="addDisplay(Math.PI)" type="button"> </td>
327 <td><input name="dot" value=" . " onclick='addDisplay(".")' type="button"></td>
328 <td><input name="division" value=" / " onclick="divideNumbers()" type="button"></td>
329 </tr><tr align="left" valign="middle">
330 <td><input name="sqareroot" value="sqrt" onclick="sqrt()" type="button"></td>
331 <td><input name="squarex" value=" x^2" onclick="square()" type="button"></td>
332 <td><input name="deg-rad" value="d2r " onclick="degToRad()" type="button"></td>
333 <td><input name="rad-deg" value="r2d " onclick="radToDeg()" type="button"></td>
334 </tr><tr align="left" valign="middle">
335 <td><input name="sine" value=" sin " onclick="sin()" type="button"></td>
336 <td><input name="arcsine" value="asin" onclick="arcSin()" type="button"></td>
337 <td><input name="cosine" value="cos" onclick="cos()" type="button"></td>
338 <td><input name="arccosine" value="acs" onclick="arcCos()" type="button"></td>
340 </tr><tr align="left" valign="middle">
341 <td colspan="2"><input name="clear" value=" Clear " onclick="clearDisplay()" type="button"></td>
342 <td colspan="3"><input name="enter" value=" = " onclick="calculate()" type="button"></td>
344 </tr></tbody></table>
349 <B>NOTE:</B> All sine and cosine calculations are
350 <br>done in radians. Remember to convert first
351 <br>if using degrees.
355 </td></tr></tbody></table>
358 </td></tr></tbody></table>