timepiece 0.1.8 → 0.1.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 +4 -4
- data/README.rdoc +8 -0
- data/app/assets/javascripts/timepiece.js +52 -0
- data/app/helpers/timepiece_helper.rb +27 -0
- data/lib/timepiece/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b9d5e9978c63bb8873088355270e63b10b1ac6b
|
4
|
+
data.tar.gz: 4f0be89204dd83b9535ee6396ab76884f869886e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d7db3d0c517a5ffea111c9434e0aea4dae62744ca4623c6a8589febb65732300a763cd7a4080a7c8ac891af5b1e513a8fb4bae48d53f41a6bc478bdef63cc49
|
7
|
+
data.tar.gz: b9d8538dbd6f08bbaa963fce16c9496e61a6e4231851c061d82c61013cf09a345fee51b5ef9c113f60c6033e16b13fc53584346b64eec4dbade1ff8ebadd3481
|
data/README.rdoc
CHANGED
@@ -63,3 +63,11 @@ It is now also possible to make use of a basic timer. To start a count from `Tim
|
|
63
63
|
* The helper also takes a time object as a parameter, for example:
|
64
64
|
|
65
65
|
<%= timer(User.first.created_at) %>
|
66
|
+
|
67
|
+
== Countdown
|
68
|
+
|
69
|
+
There is also a basic countdown implementation. To start a countdown to 2016, simply include `countdown` in your Rails projects.
|
70
|
+
|
71
|
+
* The helper also takes a time object as a parameter, for example:
|
72
|
+
|
73
|
+
<%= countdown(Time.new(2016, 3, 14)) %> <!-- My birthday and, of course, Pi day -->
|
@@ -132,6 +132,55 @@ function show_timer(){
|
|
132
132
|
}, 1000)
|
133
133
|
}
|
134
134
|
|
135
|
+
get_countdown_days = []
|
136
|
+
get_countdown_hours = []
|
137
|
+
get_countdown_minutes = []
|
138
|
+
get_countdown_seconds = []
|
139
|
+
|
140
|
+
function set_countdown(){
|
141
|
+
$(".timepiece-countdown").each(function(){
|
142
|
+
get_countdown_days.push(parseInt($(this).attr('data-days'),10))
|
143
|
+
get_countdown_hours.push(parseInt($(this).attr('data-hours'),10))
|
144
|
+
get_countdown_minutes.push(parseInt($(this).attr('data-minutes'),10))
|
145
|
+
get_countdown_seconds.push(parseInt($(this).attr('data-seconds'),10))
|
146
|
+
countdown_days = get_countdown_days
|
147
|
+
countdown_hours = get_countdown_hours
|
148
|
+
countdown_minutes = get_countdown_minutes
|
149
|
+
countdown_seconds = get_countdown_seconds
|
150
|
+
});
|
151
|
+
}
|
152
|
+
|
153
|
+
function show_countdown(){
|
154
|
+
countdown = setInterval(function(){
|
155
|
+
for(i = 0; i < countdown_hours.length; i++){
|
156
|
+
if (countdown_seconds[i] > 0){
|
157
|
+
countdown_seconds[i] -= 1
|
158
|
+
} else {
|
159
|
+
countdown_seconds[i] = 59
|
160
|
+
if (countdown_minutes[i] > 0){
|
161
|
+
countdown_minutes[i] -= 1
|
162
|
+
} else {
|
163
|
+
countdown_minutes[i] = 59
|
164
|
+
if (countdown_hours[i] > 0){
|
165
|
+
countdown_hours[i] -= 1
|
166
|
+
} else {
|
167
|
+
countdown_hours[i] = 23
|
168
|
+
countdown_days[i] -= 1
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
$(".timepiece-countdown").each(function(i, e){
|
174
|
+
$(e).html(function(){
|
175
|
+
$('.timepiece-days', $(e)).html(countdown_days[i]);
|
176
|
+
$('.timepiece-hours', $(e)).html(countdown_hours[i]);
|
177
|
+
$('.timepiece-minutes', $(e)).html(countdown_minutes[i]);
|
178
|
+
$('.timepiece-seconds', $(e)).html(countdown_seconds[i]);
|
179
|
+
})
|
180
|
+
})
|
181
|
+
}, 1000)
|
182
|
+
}
|
183
|
+
|
135
184
|
function reset_time(){
|
136
185
|
get_hours = []
|
137
186
|
get_minutes = []
|
@@ -142,13 +191,16 @@ function reset_time(){
|
|
142
191
|
$(document).ready(function(){
|
143
192
|
get_time()
|
144
193
|
set_timer()
|
194
|
+
set_countdown()
|
145
195
|
show_time()
|
146
196
|
show_timer()
|
197
|
+
show_countdown()
|
147
198
|
})
|
148
199
|
$(document).on('page:load', function(){
|
149
200
|
clearInterval(clock);
|
150
201
|
reset_time();
|
151
202
|
clearInterval(timer);
|
203
|
+
clearInterval(countdown);
|
152
204
|
// Quickfix for Turbolinks. We should revisit this.
|
153
205
|
// Note we also need jquery-turbolinks to be installed (should at least make users aware of this)
|
154
206
|
// And currently navigation via browser history buttons will break our clocks. FIXME:
|
@@ -65,4 +65,31 @@ module TimepieceHelper
|
|
65
65
|
|
66
66
|
content_tag(:span, time.html_safe, class: 'timepiece-timer', 'data-days' => days, 'data-hours' => hours, 'data-minutes' => minutes, 'data-seconds' => seconds)
|
67
67
|
end
|
68
|
+
|
69
|
+
def countdown(time_until = Time.new(2016))
|
70
|
+
seconds_diff = (time_until - Time.now).to_i
|
71
|
+
|
72
|
+
days = seconds_diff / 86400
|
73
|
+
seconds_diff -= days * 86400
|
74
|
+
|
75
|
+
hours = seconds_diff / 3600
|
76
|
+
seconds_diff -= hours * 3600
|
77
|
+
|
78
|
+
minutes = seconds_diff / 60
|
79
|
+
seconds_diff -= minutes * 60
|
80
|
+
|
81
|
+
seconds = seconds_diff
|
82
|
+
|
83
|
+
time = "<span class='timepiece-days'>#{days.to_s}</span>"\
|
84
|
+
"<span class='timepiece-descriptor tp-descriptor-days'> days </span>"\
|
85
|
+
"<span class='timepiece-hours'>#{hours.to_s}</span>"\
|
86
|
+
"<span class='timepiece-descriptor tp-descriptor-hours'> hours </span>"\
|
87
|
+
"<span class='timepiece-minutes'>#{minutes.to_s}</span>"\
|
88
|
+
"<span class='timepiece-descriptor tp-descriptor-minutes'> minutes </span>"\
|
89
|
+
"<span class='timepiece-seconds'>#{seconds.to_s}</span>"\
|
90
|
+
"<span class='timepiece-descriptor tp-descriptor-seconds'> seconds </span>"
|
91
|
+
# "<span class='timepiece-seconds'>#{seconds.to_s.rjust(2, '0')}</span>" # Note: rjust; it might be useful.
|
92
|
+
|
93
|
+
content_tag(:span, time.html_safe, class: 'timepiece-countdown', 'data-days' => days, 'data-hours' => hours, 'data-minutes' => minutes, 'data-seconds' => seconds)
|
94
|
+
end
|
68
95
|
end
|
data/lib/timepiece/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timepiece
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thom Bruce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|