4 (defun add-break (elem)
5 (.append-child elem
(.create-element document
"br")))
7 ;V Insert text into /calc-in/ at cursor and give it focus.V
9 (defvar curpos
(+ calc-in.selection-start str.length
))
12 (+ (.substring calc-in.value
0 calc-in.selection-start
)
13 str
(.substring calc-in.value calc-in.selection-end
)))
14 (setf calc-in.selection-start curpos
15 calc-in.selection-end curpos
)
18 ;V Called when the "clear" button is pressed.V
20 (setf calc-in.value
"")
23 ;V Called when the "OK" button is pressed.V
27 (+ "text=" (.replace calc-in.value
(regex "/\\+/g") "%2B"))
29 (setf (slot-value (.get-element-by-id document
"resultPre")
34 (defun show-a-button (name elem onclick width fcolor bcolor
)
35 (unless width
(setf width
25))
36 (unless fcolor
(setf fcolor
"#000000"))
37 (unless bcolor
(setf bcolor
"#D3D3D3"))
38 (let ((b (.create-element document
"button")))
39 (setf b.inner-h-t-m-l name
)
42 (+ "color: " fcolor
"; background-color: " bcolor
43 "; height: 25px; width: " width
"px"))
44 (.set-attribute b
"onclick" onclick
)
45 (.append-child elem b
)))
47 ;-- BEGIN SPECIAL BUTTON CREATORS --
48 (defun show-input-button (name elem tosend width fcolor bcolor
)
49 (show-a-button name elem
(+ "uinput(\"" tosend
"\")")
52 (defun show-num (name elem
)
54 name elem name
25 "white" "black"))
56 ;V Use the button operation as a name.V
57 (defun show-binop (name elem width fcolor bcolor
)
59 name elem name width fcolor bcolor
))
61 (defun show-func (name elem width fcolor bcolor
)
62 (show-input-button name elem
(+ "(" name
" ")
65 (defun clear-button (elem)
66 (show-a-button "clear" elem
"cleartext()" 45 "white" "darkred"))
68 (defun ok-button (elem)
69 (show-a-button "ok" elem
"sendCalc()" 25 "white" "green"))
71 (defun memory-buttons (elem)
72 (show-input-button "recall" elem
"(recall \\\"" 50 "white" "DarkSlateGray")
73 (show-input-button "store" elem
"(store \\\"" 50 "white" "SlateBlue"))
75 ;-- END SPECIAL BUTTON CREATORS --
77 ;V Show the calculator-layout thing. V
78 (defun show-standops (elem)
79 (show-input-button "^" elem
"(expt ")
82 (show-input-button "√" elem
"(sqrt ")
87 (show-num "7" elem
) (show-num "8" elem
) (show-num "9" elem
)
88 (show-input-button "×" elem
"(* ")
90 (show-num "4" elem
) (show-num "5" elem
) (show-num "6" elem
)
93 (show-num "1" elem
) (show-num "2" elem
) (show-num "3" elem
)
96 (show-input-button "0" elem
"0" 50 "white" "black")
100 (memory-buttons elem
))
102 ;V Show linear algebra functions/operations.V
103 ;V (not linear operators :) V
104 (defun show-linops (elem)
105 (show-func "rr-ef" elem
40)
106 (show-func "r-ef" elem
40)
107 (show-func "det" elem
35)
109 (show-func "transpose" elem
80)
110 (show-func "inverse" elem
60)
112 (show-func "dot" elem
35)
113 (show-func "cross" elem
45)
114 (show-func "proj" elem
40)
115 (show-func "orth" elem
40)
117 (show-func "cat" elem
35)
118 (show-func "vcat" elem
40)
119 (show-func "crop" elem
40)
120 (show-func "vcrop" elem
45))
123 (defun append-name-buttons (names vardiv
)
124 (defvar curbutt
) (defvar curname
)
125 (dotimes (x names.length
)
126 (setf curname
(aref names x
)
127 curbutt
(.create-element document
"button")
128 curbutt.inner-h-t-m-l curname
)
129 ;V When you click on a name, call the uinput V
130 ;V function with the name as an argument. V
131 (.set-attribute curbutt
"onClick"
132 (+ "uinput(\"" curname
"\");"))
133 (.append-child vardiv curbutt
)))