jquery-final_countdown-rails 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +42 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +70 -0
- data/Rakefile +26 -0
- data/jquery-final_countdown-rails.gemspec +21 -0
- data/lib/generators/jquery/final_countdown/install/install_generator.rb +37 -0
- data/lib/jquery-final_countdown-rails..rb +1 -0
- data/lib/jquery/final_countdown/rails.rb +17 -0
- data/lib/jquery/final_countdown/rails/engine.rb +8 -0
- data/lib/jquery/final_countdown/rails/railtie.rb +15 -0
- data/lib/jquery/final_countdown/rails/sprockets.rb +7 -0
- data/lib/jquery/final_countdown/rails/version.rb +7 -0
- data/vendor/assets/javascripts/jquery.countdown.js +206 -0
- data/vendor/assets/javascripts/jquery.countdown.min.js +22 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0f5d07b1e4bf2ea2e7ee87cf8c261c1647033e8
|
4
|
+
data.tar.gz: 642dd571dadd44863450f013f2e19716fac8ad16
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 286e06d641e7d0cf7446281710ebf681b4f69260cac66c3abe7cd3ce5b15564e2c7ff534389d9dec4aea8f7bcee925720fda66bed3182471893f8a73d2ab54ab
|
7
|
+
data.tar.gz: 31987620a0193cb04a0d4e8c6b2fea3ca9597087df3241db54bb8e0ba164165465f0e748932754977ce90c8928f0c67a84bad4911394de7e8b111b9f20fb92c2
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
### Updating jQuery.Countdown (The Final Countdown)
|
4
|
+
|
5
|
+
If the [jQuery.countdown][jquery-final-countdown] is outdated, please open an issue inform me to update.
|
6
|
+
|
7
|
+
[jquery-final-countdown]: https://github.com/hilios/jQuery.countdown
|
8
|
+
|
9
|
+
**Everyone** is encouraged to help improve this project.
|
10
|
+
|
11
|
+
Ways to contribute:
|
12
|
+
|
13
|
+
* by reporting bugs
|
14
|
+
* by writing or editing documentation
|
15
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up
|
16
|
+
inconsistent whitespace)
|
17
|
+
* by refactoring code
|
18
|
+
* by fixing [issues][]
|
19
|
+
* by reviewing patches
|
20
|
+
|
21
|
+
[issues]: https://github.com/juanitofatas/comer_de_tapas/issues
|
22
|
+
|
23
|
+
## Submit an Issue
|
24
|
+
|
25
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
26
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
27
|
+
already been submitted. When submitting a bug report, please include a [Gist][]
|
28
|
+
that includes a stack trace and any details that may be necessary to reproduce
|
29
|
+
the bug, including your gem version, Ruby version, and operating system.
|
30
|
+
|
31
|
+
[gist]: https://gist.github.com/
|
32
|
+
|
33
|
+
## Submit a Pull Request
|
34
|
+
|
35
|
+
1. [Fork the repository.][fork]
|
36
|
+
2. Create a topic branch.
|
37
|
+
3. Implement your feature or bug fix.
|
38
|
+
4. Add, commit, and push your changes.
|
39
|
+
5. [Submit a pull request.][pr]
|
40
|
+
|
41
|
+
[fork]: https://help.github.com/articles/fork-a-repo
|
42
|
+
[pr]: https://help.github.com/articles/using-pull-requests
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Juanito Fatas
|
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,70 @@
|
|
1
|
+
jquery-final_countdown-rails
|
2
|
+
============================
|
3
|
+
|
4
|
+
[![Gem Version](http://img.shields.io/gem/v/jquery-final_countdown-rails.svg)][gem]
|
5
|
+
|
6
|
+
[jQuery.countdown (aka The Final Countdown)][jquery-final-countdown] for Rails Asset Pipeline or
|
7
|
+
standalone sprockets applications.
|
8
|
+
|
9
|
+
[gem]: https://rubygems.org/gems/jquery-final_countdown-rails
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
:warning: jQuery.countdown needs jQuery. That is, you need to have `'jquery-rails'` in your Gemfile.
|
15
|
+
|
16
|
+
### Rails 3.1+
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'jquery-final_countdown-rails'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Add following directive to your JavaScript manifest file (`app/assets/javascripts/application.js`):
|
27
|
+
|
28
|
+
```js
|
29
|
+
//= require jquery.countdown
|
30
|
+
```
|
31
|
+
|
32
|
+
That's it!
|
33
|
+
|
34
|
+
### Rails < 3.1 (or greater with asset pipeline *disabled*)
|
35
|
+
|
36
|
+
This gem adds a single generator: `jquery:final_countdown:install`. Running the generator will copy `jquery.countdown.js` and `jquery.countdown.min.js` to `public/javascripts` directory.
|
37
|
+
|
38
|
+
This gem contains the minified and un-minified versions of `jquery.countdown`, only the minified versions will be included in the `:defaults` when Rails is in `production` or `test` mode (un-minified versions will be included when Rails is in `development` mode).
|
39
|
+
|
40
|
+
To invoke the generator, run:
|
41
|
+
|
42
|
+
```sh
|
43
|
+
rails generate jquery:final_countdown:install
|
44
|
+
```
|
45
|
+
|
46
|
+
That's it!
|
47
|
+
|
48
|
+
Versions
|
49
|
+
--------
|
50
|
+
|
51
|
+
*The jquery-final_countdown-rails version is the same as jQuery.countdown version.*
|
52
|
+
|
53
|
+
If a bug in gem is discovered, a 4th version identifier will be added. Like `2.0.4.1`.
|
54
|
+
|
55
|
+
Contributing
|
56
|
+
------------
|
57
|
+
|
58
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
59
|
+
|
60
|
+
Thanks
|
61
|
+
------
|
62
|
+
|
63
|
+
I gemify this gem by mock the [jquery-rails](https://github.com/rails/jquery-rails).
|
64
|
+
|
65
|
+
[jquery-final-countdown]: https://github.com/hilios/jQuery.countdown
|
66
|
+
|
67
|
+
License
|
68
|
+
-------
|
69
|
+
|
70
|
+
MIT License. Please see [LICENSE](/LICENSE).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
task :update_jquery_final_countdown do
|
4
|
+
puts 'Downloading jquery.countdown.js'
|
5
|
+
puts `curl -o vendor/assets/javascripts/jquery.countdown.js https://raw.githubusercontent.com/hilios/jQuery.countdown/master/dist/jquery.countdown.js`
|
6
|
+
puts 'Downloading jquery.countdown.min.js'
|
7
|
+
puts `curl -o vendor/assets/javascripts/jquery.countdown.min.js https://raw.githubusercontent.com/hilios/jQuery.countdown/master/dist/jquery.countdown.min.js`
|
8
|
+
|
9
|
+
puts 'Updating version.rb'
|
10
|
+
version = false
|
11
|
+
File.foreach('vendor/assets/javascripts/jquery.countdown.js') do |line|
|
12
|
+
version = line.match(/The Final Countdown for jQuery v([\S]+)/)
|
13
|
+
version = version && version[1]
|
14
|
+
break if version
|
15
|
+
end
|
16
|
+
|
17
|
+
version_path = 'lib/jquery/final_countdown/rails/version.rb'
|
18
|
+
lines = IO.readlines(version_path).map do |line|
|
19
|
+
line.gsub(/VERSION = "([\d\.]+)"/, "VERSION = \"#{version}\"")
|
20
|
+
end
|
21
|
+
File.open(version_path, 'w') do |file|
|
22
|
+
file.puts lines
|
23
|
+
end
|
24
|
+
|
25
|
+
puts "\e[32mDone!\e[0m"
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jquery/final_countdown/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'jquery-final_countdown-rails'
|
8
|
+
s.version = '2.0.4'
|
9
|
+
s.authors = ['Juanito Fatas']
|
10
|
+
s.email = ['katehuang0320@gmail.com']
|
11
|
+
s.summary = 'jQuery.countdown (The Final Countdown) for Rails'
|
12
|
+
s.description = 'This gem provides jQuery.countdown driver for your Rails application.'
|
13
|
+
s.homepage = 'https://github.com/jquery-final_countdown-rails'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.add_dependency 'railties', '>= 3.0', '< 5.0'
|
17
|
+
s.add_dependency 'thor', '>= 0.14', '< 2.0'
|
18
|
+
|
19
|
+
s.files = `git ls-files -z`.split("\x0")
|
20
|
+
s.require_path = ['lib']
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
# Supply generator for Rails 3.0.x or if asset pipeline is not enabled
|
4
|
+
if ::Rails.version < "3.1" || ::Rails.application.config.assets.enabled == false
|
5
|
+
module Jquery
|
6
|
+
module FinalCountdown
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < ::Rails::Generators::Base
|
9
|
+
|
10
|
+
desc "This generator installs jQuery.countdown #{Jquery::FinalCountdown::Rails::VERSION}"
|
11
|
+
source_root File.expand_path('../../../../../../vendor/assets/javascripts', __FILE__)
|
12
|
+
|
13
|
+
def copy_jquery_final_countdown
|
14
|
+
say_status("copying", "jQuery.countdown (#{Jquery::FinalCountdown::Rails::VERSION})", :green)
|
15
|
+
copy_file "jquery.countdown.js", "public/javascripts/jquery.countdown.js"
|
16
|
+
copy_file "jquery.countdown.min.js", "public/javascripts/jquery.countdown.min.js"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
else # Rails 3.1+
|
23
|
+
module Jquery
|
24
|
+
module FinalCountdown
|
25
|
+
module Generators
|
26
|
+
class InstallGenerator < ::Rails::Generators::Base
|
27
|
+
desc "Just show instructions so people will know what to do when mistakenly using generator"
|
28
|
+
|
29
|
+
def do_nothing
|
30
|
+
say("The jQuery.countdown is ready to use in your asset pipeline.", :green)
|
31
|
+
say("Just add `//= require jquery.countdown` to your app/assets/javascripts/application.js and that's it!", :green)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'jquery/final_countdown/rails'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'jquery/final_countdown/rails/version'
|
2
|
+
|
3
|
+
module Jquery
|
4
|
+
module FinalCountdown
|
5
|
+
module Rails
|
6
|
+
if defined? ::Rails
|
7
|
+
if ::Rails.version < "3.1"
|
8
|
+
require 'jquery/final_countdown/rails/railtie'
|
9
|
+
else
|
10
|
+
require 'jquery/final_countdown/rails/engine'
|
11
|
+
end
|
12
|
+
elsif defined? ::Sprockets
|
13
|
+
require 'jquery/final_countdown/rails/sprockets'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Jquery
|
2
|
+
module FinalCountdown
|
3
|
+
module Rails
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
config.before_configuration do
|
6
|
+
if config.action_view.javascript_expansions
|
7
|
+
the_final_countdown_default = ::Rails.env.production? || ::Rails.env.test? ? %w(jquery.countdown.min) : %w(jquery.countdown)
|
8
|
+
|
9
|
+
# Add jQuery.countdown
|
10
|
+
config.action_view.javascript_expansions[:defaults] |= the_final_countdown_default
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
/*!
|
2
|
+
* The Final Countdown for jQuery v2.0.4 (http://hilios.github.io/jQuery.countdown/)
|
3
|
+
* Copyright (c) 2014 Edson Hilios
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
* this software and associated documentation files (the "Software"), to deal in
|
7
|
+
* the Software without restriction, including without limitation the rights to
|
8
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
* the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
* subject to the following conditions:
|
11
|
+
*
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
13
|
+
* copies or substantial portions of the Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
(function(factory) {
|
23
|
+
"use strict";
|
24
|
+
if (typeof define === "function" && define.amd) {
|
25
|
+
define([ "jquery" ], factory);
|
26
|
+
} else {
|
27
|
+
factory(jQuery);
|
28
|
+
}
|
29
|
+
})(function($) {
|
30
|
+
"use strict";
|
31
|
+
var PRECISION = 100;
|
32
|
+
var instances = [], matchers = [];
|
33
|
+
matchers.push(/^[0-9]*$/.source);
|
34
|
+
matchers.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source);
|
35
|
+
matchers.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source);
|
36
|
+
matchers = new RegExp(matchers.join("|"));
|
37
|
+
function parseDateString(dateString) {
|
38
|
+
if (dateString instanceof Date) {
|
39
|
+
return dateString;
|
40
|
+
}
|
41
|
+
if (String(dateString).match(matchers)) {
|
42
|
+
if (String(dateString).match(/^[0-9]*$/)) {
|
43
|
+
dateString = Number(dateString);
|
44
|
+
}
|
45
|
+
if (String(dateString).match(/\-/)) {
|
46
|
+
dateString = String(dateString).replace(/\-/g, "/");
|
47
|
+
}
|
48
|
+
return new Date(dateString);
|
49
|
+
} else {
|
50
|
+
throw new Error("Couldn't cast `" + dateString + "` to a date object.");
|
51
|
+
}
|
52
|
+
}
|
53
|
+
var DIRECTIVE_KEY_MAP = {
|
54
|
+
Y: "years",
|
55
|
+
m: "months",
|
56
|
+
w: "weeks",
|
57
|
+
d: "days",
|
58
|
+
D: "totalDays",
|
59
|
+
H: "hours",
|
60
|
+
M: "minutes",
|
61
|
+
S: "seconds"
|
62
|
+
};
|
63
|
+
function strftime(offsetObject) {
|
64
|
+
return function(format) {
|
65
|
+
var directives = format.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);
|
66
|
+
if (directives) {
|
67
|
+
for (var i = 0, len = directives.length; i < len; ++i) {
|
68
|
+
var directive = directives[i].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/), regexp = new RegExp(directive[0]), modifier = directive[1] || "", plural = directive[3] || "", value = null;
|
69
|
+
directive = directive[2];
|
70
|
+
if (DIRECTIVE_KEY_MAP.hasOwnProperty(directive)) {
|
71
|
+
value = DIRECTIVE_KEY_MAP[directive];
|
72
|
+
value = Number(offsetObject[value]);
|
73
|
+
}
|
74
|
+
if (value !== null) {
|
75
|
+
if (modifier === "!") {
|
76
|
+
value = pluralize(plural, value);
|
77
|
+
}
|
78
|
+
if (modifier === "") {
|
79
|
+
if (value < 10) {
|
80
|
+
value = "0" + value.toString();
|
81
|
+
}
|
82
|
+
}
|
83
|
+
format = format.replace(regexp, value.toString());
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
format = format.replace(/%%/, "%");
|
88
|
+
return format;
|
89
|
+
};
|
90
|
+
}
|
91
|
+
function pluralize(format, count) {
|
92
|
+
var plural = "s", singular = "";
|
93
|
+
if (format) {
|
94
|
+
format = format.replace(/(:|;|\s)/gi, "").split(/\,/);
|
95
|
+
if (format.length === 1) {
|
96
|
+
plural = format[0];
|
97
|
+
} else {
|
98
|
+
singular = format[0];
|
99
|
+
plural = format[1];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
if (Math.abs(count) === 1) {
|
103
|
+
return singular;
|
104
|
+
} else {
|
105
|
+
return plural;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
var Countdown = function(el, finalDate, callback) {
|
109
|
+
this.el = el;
|
110
|
+
this.$el = $(el);
|
111
|
+
this.interval = null;
|
112
|
+
this.offset = {};
|
113
|
+
this.instanceNumber = instances.length;
|
114
|
+
instances.push(this);
|
115
|
+
this.$el.data("countdown-instance", this.instanceNumber);
|
116
|
+
if (callback) {
|
117
|
+
this.$el.on("update.countdown", callback);
|
118
|
+
this.$el.on("stoped.countdown", callback);
|
119
|
+
this.$el.on("finish.countdown", callback);
|
120
|
+
}
|
121
|
+
this.setFinalDate(finalDate);
|
122
|
+
this.start();
|
123
|
+
};
|
124
|
+
$.extend(Countdown.prototype, {
|
125
|
+
start: function() {
|
126
|
+
if (this.interval !== null) {
|
127
|
+
clearInterval(this.interval);
|
128
|
+
}
|
129
|
+
var self = this;
|
130
|
+
this.update();
|
131
|
+
this.interval = setInterval(function() {
|
132
|
+
self.update.call(self);
|
133
|
+
}, PRECISION);
|
134
|
+
},
|
135
|
+
stop: function() {
|
136
|
+
clearInterval(this.interval);
|
137
|
+
this.interval = null;
|
138
|
+
this.dispatchEvent("stoped");
|
139
|
+
},
|
140
|
+
pause: function() {
|
141
|
+
this.stop.call(this);
|
142
|
+
},
|
143
|
+
resume: function() {
|
144
|
+
this.start.call(this);
|
145
|
+
},
|
146
|
+
remove: function() {
|
147
|
+
this.stop();
|
148
|
+
instances[this.instanceNumber] = null;
|
149
|
+
delete this.$el.data().countdownInstance;
|
150
|
+
},
|
151
|
+
setFinalDate: function(value) {
|
152
|
+
this.finalDate = parseDateString(value);
|
153
|
+
},
|
154
|
+
update: function() {
|
155
|
+
if (this.$el.closest("html").length === 0) {
|
156
|
+
this.remove();
|
157
|
+
return;
|
158
|
+
}
|
159
|
+
this.totalSecsLeft = this.finalDate.getTime() - new Date().getTime();
|
160
|
+
this.totalSecsLeft = Math.ceil(this.totalSecsLeft / 1e3);
|
161
|
+
this.totalSecsLeft = this.totalSecsLeft < 0 ? 0 : this.totalSecsLeft;
|
162
|
+
this.offset = {
|
163
|
+
seconds: this.totalSecsLeft % 60,
|
164
|
+
minutes: Math.floor(this.totalSecsLeft / 60) % 60,
|
165
|
+
hours: Math.floor(this.totalSecsLeft / 60 / 60) % 24,
|
166
|
+
days: Math.floor(this.totalSecsLeft / 60 / 60 / 24) % 7,
|
167
|
+
totalDays: Math.floor(this.totalSecsLeft / 60 / 60 / 24),
|
168
|
+
weeks: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 7),
|
169
|
+
months: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 30),
|
170
|
+
years: Math.floor(this.totalSecsLeft / 60 / 60 / 24 / 365)
|
171
|
+
};
|
172
|
+
if (this.totalSecsLeft === 0) {
|
173
|
+
this.stop();
|
174
|
+
this.dispatchEvent("finish");
|
175
|
+
} else {
|
176
|
+
this.dispatchEvent("update");
|
177
|
+
}
|
178
|
+
},
|
179
|
+
dispatchEvent: function(eventName) {
|
180
|
+
var event = $.Event(eventName + ".countdown");
|
181
|
+
event.finalDate = this.finalDate;
|
182
|
+
event.offset = $.extend({}, this.offset);
|
183
|
+
event.strftime = strftime(this.offset);
|
184
|
+
this.$el.trigger(event);
|
185
|
+
}
|
186
|
+
});
|
187
|
+
$.fn.countdown = function() {
|
188
|
+
var argumentsArray = Array.prototype.slice.call(arguments, 0);
|
189
|
+
return this.each(function() {
|
190
|
+
var instanceNumber = $(this).data("countdown-instance");
|
191
|
+
if (instanceNumber !== undefined) {
|
192
|
+
var instance = instances[instanceNumber], method = argumentsArray[0];
|
193
|
+
if (Countdown.prototype.hasOwnProperty(method)) {
|
194
|
+
instance[method].apply(instance, argumentsArray.slice(1));
|
195
|
+
} else if (String(method).match(/^[$A-Z_][0-9A-Z_$]*$/i) === null) {
|
196
|
+
instance.setFinalDate.call(instance, method);
|
197
|
+
instance.start();
|
198
|
+
} else {
|
199
|
+
$.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi, method));
|
200
|
+
}
|
201
|
+
} else {
|
202
|
+
new Countdown(this, argumentsArray[0], argumentsArray[1]);
|
203
|
+
}
|
204
|
+
});
|
205
|
+
};
|
206
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*!
|
2
|
+
* The Final Countdown for jQuery v2.0.4 (http://hilios.github.io/jQuery.countdown/)
|
3
|
+
* Copyright (c) 2014 Edson Hilios
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
* this software and associated documentation files (the "Software"), to deal in
|
7
|
+
* the Software without restriction, including without limitation the rights to
|
8
|
+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
* the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
* subject to the following conditions:
|
11
|
+
*
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
13
|
+
* copies or substantial portions of the Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
*/
|
22
|
+
!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";function b(a){if(a instanceof Date)return a;if(String(a).match(g))return String(a).match(/^[0-9]*$/)&&(a=Number(a)),String(a).match(/\-/)&&(a=String(a).replace(/\-/g,"/")),new Date(a);throw new Error("Couldn't cast `"+a+"` to a date object.")}function c(a){return function(b){var c=b.match(/%(-|!)?[A-Z]{1}(:[^;]+;)?/gi);if(c)for(var e=0,f=c.length;f>e;++e){var g=c[e].match(/%(-|!)?([a-zA-Z]{1})(:[^;]+;)?/),i=new RegExp(g[0]),j=g[1]||"",k=g[3]||"",l=null;g=g[2],h.hasOwnProperty(g)&&(l=h[g],l=Number(a[l])),null!==l&&("!"===j&&(l=d(k,l)),""===j&&10>l&&(l="0"+l.toString()),b=b.replace(i,l.toString()))}return b=b.replace(/%%/,"%")}}function d(a,b){var c="s",d="";return a&&(a=a.replace(/(:|;|\s)/gi,"").split(/\,/),1===a.length?c=a[0]:(d=a[0],c=a[1])),1===Math.abs(b)?d:c}var e=100,f=[],g=[];g.push(/^[0-9]*$/.source),g.push(/([0-9]{1,2}\/){2}[0-9]{4}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g.push(/[0-9]{4}([\/\-][0-9]{1,2}){2}( [0-9]{1,2}(:[0-9]{2}){2})?/.source),g=new RegExp(g.join("|"));var h={Y:"years",m:"months",w:"weeks",d:"days",D:"totalDays",H:"hours",M:"minutes",S:"seconds"},i=function(b,c,d){this.el=b,this.$el=a(b),this.interval=null,this.offset={},this.instanceNumber=f.length,f.push(this),this.$el.data("countdown-instance",this.instanceNumber),d&&(this.$el.on("update.countdown",d),this.$el.on("stoped.countdown",d),this.$el.on("finish.countdown",d)),this.setFinalDate(c),this.start()};a.extend(i.prototype,{start:function(){null!==this.interval&&clearInterval(this.interval);var a=this;this.update(),this.interval=setInterval(function(){a.update.call(a)},e)},stop:function(){clearInterval(this.interval),this.interval=null,this.dispatchEvent("stoped")},pause:function(){this.stop.call(this)},resume:function(){this.start.call(this)},remove:function(){this.stop(),f[this.instanceNumber]=null,delete this.$el.data().countdownInstance},setFinalDate:function(a){this.finalDate=b(a)},update:function(){return 0===this.$el.closest("html").length?void this.remove():(this.totalSecsLeft=this.finalDate.getTime()-(new Date).getTime(),this.totalSecsLeft=Math.ceil(this.totalSecsLeft/1e3),this.totalSecsLeft=this.totalSecsLeft<0?0:this.totalSecsLeft,this.offset={seconds:this.totalSecsLeft%60,minutes:Math.floor(this.totalSecsLeft/60)%60,hours:Math.floor(this.totalSecsLeft/60/60)%24,days:Math.floor(this.totalSecsLeft/60/60/24)%7,totalDays:Math.floor(this.totalSecsLeft/60/60/24),weeks:Math.floor(this.totalSecsLeft/60/60/24/7),months:Math.floor(this.totalSecsLeft/60/60/24/30),years:Math.floor(this.totalSecsLeft/60/60/24/365)},void(0===this.totalSecsLeft?(this.stop(),this.dispatchEvent("finish")):this.dispatchEvent("update")))},dispatchEvent:function(b){var d=a.Event(b+".countdown");d.finalDate=this.finalDate,d.offset=a.extend({},this.offset),d.strftime=c(this.offset),this.$el.trigger(d)}}),a.fn.countdown=function(){var b=Array.prototype.slice.call(arguments,0);return this.each(function(){var c=a(this).data("countdown-instance");if(void 0!==c){var d=f[c],e=b[0];i.prototype.hasOwnProperty(e)?d[e].apply(d,b.slice(1)):null===String(e).match(/^[$A-Z_][0-9A-Z_$]*$/i)?(d.setFinalDate.call(d,e),d.start()):a.error("Method %s does not exist on jQuery.countdown".replace(/\%s/gi,e))}else new i(this,b[0],b[1])})}});
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-final_countdown-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juanito Fatas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: railties
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: thor
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.14'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.14'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.0'
|
53
|
+
description: This gem provides jQuery.countdown driver for your Rails application.
|
54
|
+
email:
|
55
|
+
- katehuang0320@gmail.com
|
56
|
+
executables: []
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- ".gitignore"
|
61
|
+
- CHANGELOG.md
|
62
|
+
- CONTRIBUTING.md
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- jquery-final_countdown-rails.gemspec
|
68
|
+
- lib/generators/jquery/final_countdown/install/install_generator.rb
|
69
|
+
- lib/jquery-final_countdown-rails..rb
|
70
|
+
- lib/jquery/final_countdown/rails.rb
|
71
|
+
- lib/jquery/final_countdown/rails/engine.rb
|
72
|
+
- lib/jquery/final_countdown/rails/railtie.rb
|
73
|
+
- lib/jquery/final_countdown/rails/sprockets.rb
|
74
|
+
- lib/jquery/final_countdown/rails/version.rb
|
75
|
+
- vendor/assets/javascripts/jquery.countdown.js
|
76
|
+
- vendor/assets/javascripts/jquery.countdown.min.js
|
77
|
+
homepage: https://github.com/jquery-final_countdown-rails
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: jQuery.countdown (The Final Countdown) for Rails
|
101
|
+
test_files: []
|
102
|
+
has_rdoc:
|