jscalc 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/jscalc/index.js +0 -0
- data/app/assets/javascripts/myCalculator_v3.js +183 -0
- data/app/assets/stylesheets/jscalc/index.css +0 -0
- data/app/assets/stylesheets/myCalculator_v3.css +42 -0
- metadata +10 -43
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE.txt +0 -22
- data/README.md +0 -29
- data/Rakefile +0 -1
- data/jscalc.gemspec +0 -23
- data/lib/jscalc.rb +0 -5
- data/lib/jscalc/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c43b9225a2b24de21aee39e0c5c41c2295ac2c06
|
4
|
+
data.tar.gz: e3697da25dbe574edf5d4add1c61d9c8cb285e7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f42bd6683a2619f230521be82b47cb061f3f74de97aee20df1354a9bb94ed9c02bea1b23377e0dd89b0f315ca4212f9c5a5d586c3b5f3ce39083d2dae36470ee
|
7
|
+
data.tar.gz: 2a7f2c1c44321c8957dc4331b324fe9c604e41a61dc5e26eee835e0e2b7f8adf6017a1b07cb70697f23c5ffeac7fa4a887d69386616968a6714bce5c13b47110
|
File without changes
|
@@ -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', '×', "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', '÷', "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', '–', "button"));//Subtract
|
119
|
+
|
120
|
+
//Row Four
|
121
|
+
document.getElementById('calcRowFour').appendChild(elementGenerate('0','mybtn', '0', "button"));//
|
122
|
+
document.getElementById('calcRowFour').appendChild(elementGenerate('btnDecPoint','mybtn', '.', "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
|
+
|
File without changes
|
@@ -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,58 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jscalc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomgdow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.3'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ! '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ! '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
description: javascript calculator
|
42
|
-
email:
|
43
|
-
- thomasgdowling@gmail.com
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ! "An experimetal gem. \nA JavaScript Calculator, preliminary version.\n"
|
14
|
+
email: thomasgdowling@gmail.com
|
44
15
|
executables: []
|
45
16
|
extensions: []
|
46
17
|
extra_rdoc_files: []
|
47
18
|
files:
|
48
|
-
- .
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
- Rakefile
|
53
|
-
- jscalc.gemspec
|
54
|
-
- lib/jscalc.rb
|
55
|
-
- lib/jscalc/version.rb
|
19
|
+
- app/assets/javascripts/myCalculator_v3.js
|
20
|
+
- app/assets/javascripts/jscalc/index.js
|
21
|
+
- app/assets/stylesheets/myCalculator_v3.css
|
22
|
+
- app/assets/stylesheets/jscalc/index.css
|
56
23
|
homepage: http://rubygems.org/gems/jscalc
|
57
24
|
licenses:
|
58
25
|
- MIT
|
@@ -76,5 +43,5 @@ rubyforge_project:
|
|
76
43
|
rubygems_version: 2.1.5
|
77
44
|
signing_key:
|
78
45
|
specification_version: 4
|
79
|
-
summary:
|
46
|
+
summary: An experimental JavaScript Calculator
|
80
47
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 TODO: Write your name
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Jscalc
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'jscalc'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install jscalc
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
data/jscalc.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'jscalc/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "jscalc"
|
8
|
-
spec.version = Jscalc::VERSION
|
9
|
-
spec.authors = ["tomgdow"]
|
10
|
-
spec.email = ["thomasgdowling@gmail.com"]
|
11
|
-
spec.description = %q{javascript calculator}
|
12
|
-
spec.summary = %q{javascript calculator}
|
13
|
-
spec.homepage = 'http://rubygems.org/gems/jscalc'
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
end
|
data/lib/jscalc.rb
DELETED
data/lib/jscalc/version.rb
DELETED