jscalc 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2dc0bbf4558d190b8a19c1710bc8f09213c1cbf
4
- data.tar.gz: 7879f82a61fad55b1a6f5462a75ce10bbf80491d
3
+ metadata.gz: 2835643fe84a24690ba1bfab281f2472ffa49e4b
4
+ data.tar.gz: be32f5331451ff4db1f97c9957531191239259b1
5
5
  SHA512:
6
- metadata.gz: 6f8b0d4a8b7b6373897d50452da87adf1d0e8f48e8ca211605b61e8bf7505735d9e2922be67f5bda53c7d64a12a1348adc1e299936b6937e85256620eda82e63
7
- data.tar.gz: 3e3d736a17f37bc8abcb0c149e0144a82a7c11773ab9d5994fba01e2a6666742d27248665f3e921f0802bbb6cd35ebeb93b7fb6a5e65ff7603379909c1c68875
6
+ metadata.gz: 85f8b83a3553e466ce0bf386dccda94032b7b48caf2ee55dc8a4fea62fa0dc6f4bc8d808dbd2c6d0175ecc475f06ec5c07d972ec87d4d6e661b198e6be600308
7
+ data.tar.gz: fdf82d4cb05a8b1ac742d2eb76002a113d2a9c6c8ef5d2db55562f280f9055f69a0165358d0c20a2173d75442030d9df6b358ff780caf92061702d1aca8b93f1
@@ -0,0 +1,5 @@
1
+ module JsCalc
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
5
+
@@ -0,0 +1,183 @@
1
+ var pane = document.getElementById('calcPanel');
2
+
3
+ $(dragDiv);
4
+
5
+ //Functions
6
+ function dragDiv() {
7
+ $('#myCalculator').draggable();
8
+ }
9
+
10
+ function btn_plus_fn () {
11
+
12
+ if(pane.value.slice(-1) !="+" && pane.value.slice(-1) !="-" && pane.value.slice(-1) !="*" && pane.value.slice(-1) !="/" && pane.value.slice(-1) !="%")
13
+ {
14
+ pane.value += '+';
15
+
16
+ }
17
+ } //Buttons (0-9)
18
+
19
+ function btn_subtract_fn () {
20
+
21
+ if(pane.value.slice(-1) !="+" && pane.value.slice(-1) !="-" && pane.value.slice(-1) !="*" && pane.value.slice(-1) !="/" && pane.value.slice(-1) !="%")
22
+ {
23
+ pane.value += '-';
24
+
25
+ }
26
+ }
27
+
28
+ function btn_multiply_fn () {
29
+
30
+ if(pane.value.slice(-1) !="+" && pane.value.slice(-1) !="-" && pane.value.slice(-1) !="*" && pane.value.slice(-1) !="/" && pane.value.slice(-1) !="%")
31
+ {
32
+ pane.value += '*';
33
+
34
+ }
35
+ }
36
+
37
+ function btn_divide_fn () {
38
+
39
+ if(pane.value.slice(-1) !="+" && pane.value.slice(-1) !="-" && pane.value.slice(-1) !="*" && pane.value.slice(-1) !="/" && pane.value.slice(-1) !="%")
40
+ {
41
+ pane.value += '/';
42
+
43
+ }
44
+ }
45
+
46
+ function btn_modulus_fn () {
47
+
48
+ if(pane.value.slice(-1) !="+" && pane.value.slice(-1) !="-" && pane.value.slice(-1) !="*" && pane.value.slice(-1) !="/" && pane.value.slice(-1) !="%")
49
+ {
50
+ pane.value += '%';
51
+
52
+ }
53
+ }
54
+
55
+ function btn_decimal_fn () {
56
+
57
+ //if(pane.value.charAt(pane.value.length - 1) !=".")
58
+ if(pane.value.slice(- 1) !=".")
59
+ {
60
+ pane.value += '.';
61
+
62
+ }
63
+ }
64
+
65
+ function btn_cancelError_fn () {
66
+
67
+ pane.value = pane.value.substring(0, pane.value.length - 1);
68
+
69
+ }
70
+
71
+ var evalAlt = function (fn) {
72
+ return new Function('return ' + fn)();
73
+ };//An Alternative to eval
74
+
75
+ function btn_equals_fn () {
76
+
77
+ pane.value = evalAlt(pane.value);
78
+ } // Evaluate the String
79
+
80
+ function btn_cancel_fn () {
81
+
82
+ pane.value = "";
83
+ }
84
+
85
+ function elementGenerate(myId, myClass,myContent, myElement) {
86
+ var myElement = document.createElement(myElement);
87
+ myElement.setAttribute("id", myId);
88
+ myElement.setAttribute("class", myClass);
89
+ //childNodes[0].nodeValue
90
+ myElement.innerHTML = myContent;
91
+ return myElement;
92
+ }
93
+
94
+ //Generate Button Elements and Add to DOM
95
+
96
+ //Row One
97
+ for(i=1; i<=3; i++) {
98
+
99
+ document.getElementById('calcRowOne').appendChild(elementGenerate(i,'mybtn', i, "button"))
100
+ };// (0-3)
101
+
102
+ document.getElementById('calcRowOne').appendChild(elementGenerate('btnMultiply','mybtn', '&times;', "button"));//multiply
103
+
104
+ //Row Two
105
+ for(i=4; i<=6; i++) {
106
+
107
+ document.getElementById('calcRowTwo').appendChild(elementGenerate(i,'mybtn', i, "button"))
108
+ };//(4-6)
109
+
110
+ document.getElementById('calcRowTwo').appendChild(elementGenerate('btnDivide','mybtn', '&#247;', "button"));//Divide
111
+
112
+ //Row Three
113
+ for(i=7; i<=9; i++) {
114
+
115
+ document.getElementById('calcRowThree').appendChild(elementGenerate(i,'mybtn', i, "button"))
116
+ };//(7-9)
117
+
118
+ document.getElementById('calcRowThree').appendChild(elementGenerate('btnSubtract','mybtn', '&#8211;', "button"));//Subtract
119
+
120
+ //Row Four
121
+ document.getElementById('calcRowFour').appendChild(elementGenerate('0','mybtn', '0', "button"));//
122
+ document.getElementById('calcRowFour').appendChild(elementGenerate('btnDecPoint','mybtn', '&period;', "button"));
123
+ document.getElementById('calcRowFour').appendChild(elementGenerate('btnPlus','mybtnAlt', '+', "button"));
124
+
125
+ //Row Five
126
+ document.getElementById('calcRowFive').appendChild(elementGenerate('(','mybtn', '(', "button"));//
127
+ document.getElementById('calcRowFive').appendChild(elementGenerate(')','mybtn', ')', "button"));
128
+ document.getElementById('calcRowFive').appendChild(elementGenerate('btnModulus','mybtn', 'mod', "button"));
129
+ document.getElementById('calcRowFive').appendChild(elementGenerate('btnCancelError','mybtn', 'Ce', "button"));
130
+
131
+ //Row Six
132
+ document.getElementById('calcRowSix').appendChild(elementGenerate('btnCancel','mybtnAlt', 'C', "button"));
133
+ document.getElementById('calcRowSix').appendChild(elementGenerate('btnEquals','mybtnAlt', '=', "button"));
134
+
135
+
136
+ //EventHandlers and EventListeners
137
+ for(i=0; i<=9; i++) {
138
+
139
+ document.getElementById(i).addEventListener("click", function () {pane.value += this.id}, false)
140
+
141
+ }//Buttons (0-9)
142
+
143
+ document.getElementById('(').addEventListener("click", function () { pane.value += this.id}, false);
144
+ document.getElementById(')').addEventListener("click", function () { pane.value += this.id}, false);
145
+
146
+ document.getElementById('btnPlus').onclick = function () { btn_plus_fn()};
147
+ document.getElementById('btnMultiply').onclick = function () { btn_multiply_fn()};
148
+ document.getElementById('btnDivide').onclick = function () { btn_divide_fn()};
149
+ document.getElementById('btnSubtract').onclick = function () { btn_subtract_fn()};
150
+ document.getElementById('btnEquals').onclick = function () { btn_equals_fn()};
151
+ document.getElementById('btnDecPoint').onclick = function () { btn_decimal_fn()};
152
+
153
+
154
+ document.getElementById('btnCancel').addEventListener("click", function () {btn_cancel_fn()}, false);
155
+ document.getElementById('btnCancelError').addEventListener("click", function () {btn_cancelError_fn()}, false);
156
+ document.getElementById('btnModulus').addEventListener("click", function () {btn_modulus_fn()}, false);
157
+
158
+
159
+ //Lucjen
160
+
161
+ document.addEventListener('keypress',function (e) {
162
+ if (13 == e.keyCode) {
163
+ btn_equals_fn()
164
+ }
165
+ });
166
+
167
+ //Keep These
168
+
169
+ /*function btn_equals_fn () {
170
+
171
+ document.getElementById('calcPanel').value = eval(pane.value.replace(/[^-()\d+.]/g, ''));
172
+ }*/
173
+
174
+ /*function btn_equals_fn () {
175
+
176
+ document.getElementById('calcPanel').value = evalAlt(pane.value);
177
+ }*/
178
+
179
+ /*function btn_equals_fn () {
180
+
181
+ document.getElementById('calcPanel').value = evalAlt(pane.value.replace(/[^-()\d/*+.]/g, ''));
182
+ }*/
183
+
@@ -0,0 +1,42 @@
1
+ h1 {
2
+ font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
3
+ font-style: italic;
4
+ font-weight: bold;
5
+ margin-left: 10px;
6
+ }
7
+
8
+ h2 {
9
+ font-family: verdana, arial, helvetica, sans-serif;
10
+ margin-left: 50px;
11
+ font-weight: bold;
12
+ }
13
+
14
+ .mybtn {
15
+ font-size: 20px;
16
+ height: 55px;
17
+ width: 55px;
18
+ margin: 1px;
19
+ }
20
+ .mybtnAlt {
21
+ font-size: 20px;
22
+ height: 55px;
23
+ width: 115px;
24
+ }
25
+ #calcPanel {
26
+ font-size: 20px;
27
+ margin-top: 10px;
28
+ margin-bottom: 5px;
29
+ margin-left: 10px;
30
+ height: 50px;
31
+ width: 230px;
32
+ }
33
+ #myCalculator {
34
+ margin-top: 30px;
35
+ margin-left: 100px;
36
+ width: 26%;
37
+ background-color: #9CD2EA;
38
+ }
39
+ #buttonsWrapper {
40
+ padding-left: 15px;
41
+ padding-bottom: 15px;
42
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jscalc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - tomgdow
@@ -16,7 +16,10 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - vendor/assets/javascripts/myCalculator_v3.js
20
+ - vendor/assets/stylesheets/myCalculator_v3.css
19
21
  - lib/jscalc.rb
22
+ - lib/jscalc/engine.rb
20
23
  homepage: http://rubygems.org/gems/jscalc
21
24
  licenses:
22
25
  - MIT