countdown-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cc050fe56fda0c65cbd141507a18c3d5a274645
4
+ data.tar.gz: 384e9f2a16d7cc64695152c09a69b314b96e1919
5
+ SHA512:
6
+ metadata.gz: fb440228762bd0dce456a6c3e9ec8c53556a1aec48ae97cc3c76905107420c7d9e8cad1f7e58e12bd6c1722cc27314a75bdb9eb93058e64d2da2b805aefb7540
7
+ data.tar.gz: 4b4ed7aadf68d9630f79ccc80dcdbab464bc0c5a2fe36fda9e2bcc31e6b3872b92e7d8dda9ca9b38575da22e23ccd4dcb100998cc88c94c1230366432ffa6c18
@@ -0,0 +1,63 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .DS_store
12
+ *.gem
13
+ *.rbc
14
+ /.config
15
+ /coverage/
16
+ /InstalledFiles
17
+ /pkg/
18
+ /spec/reports/
19
+ /spec/examples.txt
20
+ /test/tmp/
21
+ /test/version_tmp/
22
+ /tmp/
23
+ .idea/
24
+ .idea/**.*
25
+
26
+ # Used by dotenv library to load environment variables.
27
+ # .env
28
+
29
+ ## Specific to RubyMotion:
30
+ .dat*
31
+ .repl_history
32
+ build/
33
+ *.bridgesupport
34
+ build-iPhoneOS/
35
+ build-iPhoneSimulator/
36
+
37
+ ## Specific to RubyMotion (use of CocoaPods):
38
+ #
39
+ # We recommend against adding the Pods directory to your .gitignore. However
40
+ # you should judge for yourself, the pros and cons are mentioned at:
41
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
42
+ #
43
+ # vendor/Pods/
44
+
45
+ ## Documentation cache and generated files:
46
+ /.yardoc/
47
+ /_yardoc/
48
+ /doc/
49
+ /rdoc/
50
+
51
+ ## Environment normalization:
52
+ /.bundle/
53
+ /vendor/bundle
54
+ /lib/bundler/man/
55
+
56
+ # for a library or gem, you might want to ignore these files since the code is
57
+ # intended to run in multiple environments; otherwise, check them in:
58
+ # Gemfile.lock
59
+ # .ruby-version
60
+ # .ruby-gemset
61
+
62
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
63
+ .rvmrc
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in countdown-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 xiajian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 xiajian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Countdown::Rails
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/countdown/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'countdown-rails'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install countdown-rails
22
+
23
+ ## Usage
24
+
25
+ 参考: https://github.com/rendro/countdown
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/countdown-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,210 @@
1
+ var defaultOptions = {
2
+ date: "June 7, 2087 15:03:25",
3
+ refresh: 1000,
4
+ offset: 0,
5
+ onEnd: function() {
6
+ return;
7
+ },
8
+ render: function (date) {
9
+ this.el.innerHTML = date.years + " years, " +
10
+ date.days + " days, " +
11
+ this.leadingZeros(date.hours) + " hours, " +
12
+ this.leadingZeros(date.min) + " min and " +
13
+ this.leadingZeros(date.sec) + " sec";
14
+ }
15
+ };
16
+
17
+ /**
18
+ * Countdown constructor
19
+ * @param {HTMLElement} el DOM node of the countdown
20
+ * @param {Object} options (optional) Options for the plugin
21
+ */
22
+ var Countdown = function(el, options) {
23
+
24
+ /**
25
+ * Reference to the DOM element
26
+ * @type {HTMLElement}
27
+ */
28
+ this.el = el;
29
+
30
+ /**
31
+ * Options of the countdown plugin
32
+ * @type {Object}
33
+ */
34
+ this.options = {};
35
+
36
+ /**
37
+ * Interval reference or false if counter is stopped
38
+ * @type {Mixed}
39
+ */
40
+ this.interval = false;
41
+
42
+ // merge default options and options into this.options
43
+ this.mergeOptions = function(options) {
44
+ for (var i in defaultOptions) {
45
+ if (defaultOptions.hasOwnProperty(i)) {
46
+ this.options[i] = typeof options[i] !== 'undefined' ? options[i] : defaultOptions[i];
47
+
48
+ if (i === 'date' && typeof this.options.date !== 'object') {
49
+ this.options.date = new Date(this.options.date);
50
+ }
51
+
52
+ // bind context for functions
53
+ if (typeof this.options[i] === 'function') {
54
+ this.options[i] = this.options[i].bind(this);
55
+ }
56
+ }
57
+ }
58
+ if (typeof this.options.date !== 'object') {
59
+ this.options.date = new Date(this.options.date);
60
+ }
61
+ }.bind(this);
62
+
63
+ this.mergeOptions(options);
64
+
65
+
66
+ /**
67
+ * Get the difference between now and the end date
68
+ * @return {Object} Object with the diff information (years, days, hours, min, sec, millisec)
69
+ */
70
+ this.getDiffDate = function() {
71
+ var diff = (this.options.date.getTime() - Date.now() + this.options.offset) / 1000;
72
+
73
+ var dateData = {
74
+ years: 0,
75
+ days: 0,
76
+ hours: 0,
77
+ min: 0,
78
+ sec: 0,
79
+ millisec: 0
80
+ };
81
+
82
+ if (diff <= 0) {
83
+ if (this.interval) {
84
+ this.stop();
85
+ this.options.onEnd();
86
+ }
87
+ return dateData;
88
+ }
89
+
90
+ if (diff >= (365.25 * 86400)) {
91
+ dateData.years = Math.floor(diff / (365.25 * 86400));
92
+ diff -= dateData.years * 365.25 * 86400;
93
+ }
94
+
95
+ if (diff >= 86400) {
96
+ dateData.days = Math.floor(diff / 86400);
97
+ diff -= dateData.days * 86400;
98
+ }
99
+
100
+ if (diff >= 3600) {
101
+ dateData.hours = Math.floor(diff / 3600);
102
+ diff -= dateData.hours * 3600;
103
+ }
104
+
105
+ if (diff >= 60) {
106
+ dateData.min = Math.floor(diff / 60);
107
+ diff -= dateData.min * 60;
108
+ }
109
+
110
+ dateData.sec = Math.round(diff);
111
+
112
+ dateData.millisec = diff % 1 * 1000;
113
+
114
+ return dateData;
115
+ }.bind(this);
116
+
117
+ /**
118
+ * Add leading zeros to a number
119
+ * @param {Number} num Input number
120
+ * @param {Number} length Length of the desired output
121
+ * @return {String} String of the desired length with leading zeros
122
+ */
123
+ this.leadingZeros = function(num, length) {
124
+ length = length || 2;
125
+ num = String(num);
126
+ if (num.length > length) {
127
+ return num;
128
+ }
129
+ return (Array(length + 1).join('0') + num).substr(-length);
130
+ };
131
+
132
+ /**
133
+ * Update the end date of the countdown
134
+ * @param {Mixed} newDate Date object or a String/Number that can be passed to the Date constructor
135
+ * @return {Countdown} Countdown instance
136
+ */
137
+ this.update = function(newDate) {
138
+ if (typeof newDate !== 'object') {
139
+ newDate = new Date(newDate);
140
+ }
141
+ this.options.date = newDate;
142
+ this.render();
143
+ return this;
144
+ }.bind(this);
145
+
146
+ /**
147
+ * Stop the countdown refresh / rerender
148
+ * @return {Countdown} Countdown instance
149
+ */
150
+ this.stop = function() {
151
+ if (this.interval) {
152
+ clearInterval(this.interval);
153
+ this.interval = false;
154
+ }
155
+ return this;
156
+ }.bind(this);
157
+
158
+ /**
159
+ * Render the countdown
160
+ * @return {Countdown} Countdown instance
161
+ */
162
+ this.render = function() {
163
+ this.options.render(this.getDiffDate());
164
+ return this;
165
+ }.bind(this);
166
+
167
+ /**
168
+ * Start the countdown
169
+ * @return {Countdown} Countdown instance
170
+ */
171
+ this.start = function() {
172
+ // don't start if the countdown is already started
173
+ if (this.interval) { return; }
174
+
175
+ this.render();
176
+
177
+ if (this.options.refresh) {
178
+ this.interval = setInterval(this.render, this.options.refresh);
179
+ }
180
+
181
+ return this;
182
+ }.bind(this);
183
+
184
+ /**
185
+ * Update the offset
186
+ * @param {Number} offset New offset in ms
187
+ * @return {Countdown} Countdown instance
188
+ */
189
+ this.updateOffset = function(offset) {
190
+ this.options.offset = offset;
191
+ return this;
192
+ }.bind(this);
193
+
194
+
195
+ /**
196
+ * Restart the countdown and update options
197
+ */
198
+ this.restart = function (options) {
199
+ this.mergeOptions(options);
200
+ this.interval = false;
201
+ this.start();
202
+ return this;
203
+ }.bind(this);
204
+
205
+
206
+ // initial start of the countdown or initial render
207
+ this.start();
208
+ };
209
+
210
+ module.exports = Countdown;
@@ -0,0 +1,18 @@
1
+ var Countdown = require('./countdown.js');
2
+ var NAME = 'countdown';
3
+ var DATA_ATTR = 'date';
4
+
5
+ jQuery.fn.countdown = function(options) {
6
+ return $.each(this, function(i, el) {
7
+ var $el = $(el);
8
+ if (!$el.data(NAME)) {
9
+ // allow setting the date via the data-date attribute
10
+ if ($el.data(DATA_ATTR)) {
11
+ options.date = $el.data(DATA_ATTR);
12
+ }
13
+ $el.data(NAME, new Countdown(el, options));
14
+ }
15
+ });
16
+ };
17
+
18
+ module.exports = Countdown;
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "countdown/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'countdown/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "countdown-rails"
8
+ spec.version = Countdown::Rails::VERSION
9
+ spec.authors = ["xiajian"]
10
+ spec.email = ["jhqy2011@gmail.com"]
11
+
12
+ spec.summary = %q{countdown(https://github.com/rendro/countdown) 的 rails 封装 }
13
+ spec.description = %q{countdown 是一款倒计时的插件}
14
+ spec.homepage = "https://github.com/xiajian/countdown-rails"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,7 @@
1
+ require "countdown/rails/version"
2
+
3
+ module Countdown
4
+ module Rails
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Countdown
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: countdown-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - xiajian
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-09 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ description: countdown 是一款倒计时的插件
42
+ email:
43
+ - jhqy2011@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - LICENSE
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - app/assets/javascripts/countdown.js
57
+ - app/assets/javascripts/jquery-wrapper.js
58
+ - bin/console
59
+ - bin/setup
60
+ - countdown-rails.gemspec
61
+ - lib/countdown/rails.rb
62
+ - lib/countdown/rails/version.rb
63
+ homepage: https://github.com/xiajian/countdown-rails
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: countdown(https://github.com/rendro/countdown) 的 rails 封装
87
+ test_files: []