countupjs-rails 1.3.2
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 +7 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.md +31 -0
- data/lib/countupjs-rails.rb +8 -0
- data/lib/countupjs/version.rb +5 -0
- data/vendor/assets/javascripts/countUp.js +186 -0
- metadata +91 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1c1981def32cd588401f300301dc872567605677
|
|
4
|
+
data.tar.gz: dd3feabb51799745ed8b27c4946057cf65471b19
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bd1b3a967a48cc77e332da3b39fba384e21d156699e25e1cf3572cb9618180d19449fa5e9731920330c59010b322db9959ae51eefbe0750b73836679d4491036
|
|
7
|
+
data.tar.gz: ece5e8221446d60df34259df24d930e2f823667e3885077c85be7f29f72f34d3397ef07f0671130cd9ce6409b81eaf1b7bc6b880dc13c9ae341438f29f55ae2d
|
data/MIT-LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Richard Tan
|
|
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
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Countupjs::Rails
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'countupjs-rails'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install countupjs-rails
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
TODO: Write usage instructions here
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/countupjs-rails/fork )
|
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
31
|
+
5. Create a new Pull Request
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
countUp.js
|
|
4
|
+
by @inorganik
|
|
5
|
+
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// target = id of html element or var of previously selected html element where counting occurs
|
|
9
|
+
// startVal = the value you want to begin at
|
|
10
|
+
// endVal = the value you want to arrive at
|
|
11
|
+
// decimals = number of decimal places, default 0
|
|
12
|
+
// duration = duration of animation in seconds, default 2
|
|
13
|
+
// options = optional object of options (see below)
|
|
14
|
+
|
|
15
|
+
function countUp(target, startVal, endVal, decimals, duration, options) {
|
|
16
|
+
|
|
17
|
+
// make sure requestAnimationFrame and cancelAnimationFrame are defined
|
|
18
|
+
// polyfill for browsers without native support
|
|
19
|
+
// by Opera engineer Erik Möller
|
|
20
|
+
var lastTime = 0;
|
|
21
|
+
var vendors = ['webkit', 'moz', 'ms', 'o'];
|
|
22
|
+
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
|
23
|
+
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
|
|
24
|
+
window.cancelAnimationFrame =
|
|
25
|
+
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
|
|
26
|
+
}
|
|
27
|
+
if (!window.requestAnimationFrame) {
|
|
28
|
+
window.requestAnimationFrame = function(callback, element) {
|
|
29
|
+
var currTime = new Date().getTime();
|
|
30
|
+
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
|
31
|
+
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
|
|
32
|
+
timeToCall);
|
|
33
|
+
lastTime = currTime + timeToCall;
|
|
34
|
+
return id;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!window.cancelAnimationFrame) {
|
|
38
|
+
window.cancelAnimationFrame = function(id) {
|
|
39
|
+
clearTimeout(id);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// default options
|
|
44
|
+
this.options = options || {
|
|
45
|
+
useEasing : true, // toggle easing
|
|
46
|
+
useGrouping : true, // 1,000,000 vs 1000000
|
|
47
|
+
separator : ',', // character to use as a separator
|
|
48
|
+
decimal : '.', // character to use as a decimal
|
|
49
|
+
}
|
|
50
|
+
if (this.options.separator == '') this.options.useGrouping = false;
|
|
51
|
+
if (this.options.prefix == null) this.options.prefix = '';
|
|
52
|
+
if (this.options.suffix == null) this.options.suffix = '';
|
|
53
|
+
|
|
54
|
+
var self = this;
|
|
55
|
+
|
|
56
|
+
this.d = (typeof target === 'string') ? document.getElementById(target) : target;
|
|
57
|
+
this.startVal = Number(startVal);
|
|
58
|
+
this.endVal = Number(endVal);
|
|
59
|
+
this.countDown = (this.startVal > this.endVal) ? true : false;
|
|
60
|
+
this.startTime = null;
|
|
61
|
+
this.timestamp = null;
|
|
62
|
+
this.remaining = null;
|
|
63
|
+
this.frameVal = this.startVal;
|
|
64
|
+
this.rAF = null;
|
|
65
|
+
this.decimals = Math.max(0, decimals || 0);
|
|
66
|
+
this.dec = Math.pow(10, this.decimals);
|
|
67
|
+
this.duration = duration * 1000 || 2000;
|
|
68
|
+
|
|
69
|
+
this.version = function () { return '1.3.2' }
|
|
70
|
+
|
|
71
|
+
// Print value to target
|
|
72
|
+
this.printValue = function(value) {
|
|
73
|
+
var result = (!isNaN(value)) ? self.formatNumber(value) : '--';
|
|
74
|
+
if (self.d.tagName == 'INPUT') {
|
|
75
|
+
this.d.value = result;
|
|
76
|
+
}
|
|
77
|
+
else if (self.d.tagName == 'text') {
|
|
78
|
+
this.d.textContent = result;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.d.innerHTML = result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Robert Penner's easeOutExpo
|
|
86
|
+
this.easeOutExpo = function(t, b, c, d) {
|
|
87
|
+
return c * (-Math.pow(2, -10 * t / d) + 1) * 1024 / 1023 + b;
|
|
88
|
+
}
|
|
89
|
+
this.count = function(timestamp) {
|
|
90
|
+
|
|
91
|
+
if (self.startTime === null) self.startTime = timestamp;
|
|
92
|
+
|
|
93
|
+
self.timestamp = timestamp;
|
|
94
|
+
|
|
95
|
+
var progress = timestamp - self.startTime;
|
|
96
|
+
self.remaining = self.duration - progress;
|
|
97
|
+
|
|
98
|
+
// to ease or not to ease
|
|
99
|
+
if (self.options.useEasing) {
|
|
100
|
+
if (self.countDown) {
|
|
101
|
+
var i = self.easeOutExpo(progress, 0, self.startVal - self.endVal, self.duration);
|
|
102
|
+
self.frameVal = self.startVal - i;
|
|
103
|
+
} else {
|
|
104
|
+
self.frameVal = self.easeOutExpo(progress, self.startVal, self.endVal - self.startVal, self.duration);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
if (self.countDown) {
|
|
108
|
+
var i = (self.startVal - self.endVal) * (progress / self.duration);
|
|
109
|
+
self.frameVal = self.startVal - i;
|
|
110
|
+
} else {
|
|
111
|
+
self.frameVal = self.startVal + (self.endVal - self.startVal) * (progress / self.duration);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// don't go past endVal since progress can exceed duration in the last frame
|
|
116
|
+
if (self.countDown) {
|
|
117
|
+
self.frameVal = (self.frameVal < self.endVal) ? self.endVal : self.frameVal;
|
|
118
|
+
} else {
|
|
119
|
+
self.frameVal = (self.frameVal > self.endVal) ? self.endVal : self.frameVal;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// decimal
|
|
123
|
+
self.frameVal = Math.round(self.frameVal*self.dec)/self.dec;
|
|
124
|
+
|
|
125
|
+
// format and print value
|
|
126
|
+
self.printValue(self.frameVal);
|
|
127
|
+
|
|
128
|
+
// whether to continue
|
|
129
|
+
if (progress < self.duration) {
|
|
130
|
+
self.rAF = requestAnimationFrame(self.count);
|
|
131
|
+
} else {
|
|
132
|
+
if (self.callback != null) self.callback();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
this.start = function(callback) {
|
|
136
|
+
self.callback = callback;
|
|
137
|
+
// make sure values are valid
|
|
138
|
+
if (!isNaN(self.endVal) && !isNaN(self.startVal)) {
|
|
139
|
+
self.rAF = requestAnimationFrame(self.count);
|
|
140
|
+
} else {
|
|
141
|
+
console.log('countUp error: startVal or endVal is not a number');
|
|
142
|
+
self.printValue();
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
this.stop = function() {
|
|
147
|
+
cancelAnimationFrame(self.rAF);
|
|
148
|
+
}
|
|
149
|
+
this.reset = function() {
|
|
150
|
+
self.startTime = null;
|
|
151
|
+
self.startVal = startVal;
|
|
152
|
+
cancelAnimationFrame(self.rAF);
|
|
153
|
+
self.printValue(self.startVal);
|
|
154
|
+
}
|
|
155
|
+
this.resume = function() {
|
|
156
|
+
self.stop();
|
|
157
|
+
self.startTime = null;
|
|
158
|
+
self.duration = self.remaining;
|
|
159
|
+
self.startVal = self.frameVal;
|
|
160
|
+
requestAnimationFrame(self.count);
|
|
161
|
+
}
|
|
162
|
+
this.formatNumber = function(nStr) {
|
|
163
|
+
nStr = nStr.toFixed(self.decimals);
|
|
164
|
+
nStr += '';
|
|
165
|
+
var x, x1, x2, rgx;
|
|
166
|
+
x = nStr.split('.');
|
|
167
|
+
x1 = x[0];
|
|
168
|
+
x2 = x.length > 1 ? self.options.decimal + x[1] : '';
|
|
169
|
+
rgx = /(\d+)(\d{3})/;
|
|
170
|
+
if (self.options.useGrouping) {
|
|
171
|
+
while (rgx.test(x1)) {
|
|
172
|
+
x1 = x1.replace(rgx, '$1' + self.options.separator + '$2');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return self.options.prefix + x1 + x2 + self.options.suffix;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// format startVal on initialization
|
|
179
|
+
self.printValue(self.startVal);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Example:
|
|
183
|
+
// var numAnim = new countUp("SomeElementYouWantToAnimate", 0, 99.99, 2, 2.5);
|
|
184
|
+
// numAnim.start();
|
|
185
|
+
// with optional callback:
|
|
186
|
+
// numAnim.start(someMethodToCallOnComplete);
|
metadata
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: countupjs-rails
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.3.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Richard Tan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.7'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.7'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: railties
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.1'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.1'
|
|
55
|
+
description: ''
|
|
56
|
+
email:
|
|
57
|
+
- chardos@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- MIT-LICENSE.txt
|
|
63
|
+
- README.md
|
|
64
|
+
- lib/countupjs-rails.rb
|
|
65
|
+
- lib/countupjs/version.rb
|
|
66
|
+
- vendor/assets/javascripts/countUp.js
|
|
67
|
+
homepage: ''
|
|
68
|
+
licenses:
|
|
69
|
+
- MIT
|
|
70
|
+
metadata: {}
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubyforge_project:
|
|
87
|
+
rubygems_version: 2.4.5
|
|
88
|
+
signing_key:
|
|
89
|
+
specification_version: 4
|
|
90
|
+
summary: This gem provides countUp.js for your rails application.
|
|
91
|
+
test_files: []
|