timepiece 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0ba2cabc80d9b08269089f5a54f8d562216e250
4
- data.tar.gz: b0e93be345ab5ee53a1d07aed873eb91bf578fb3
3
+ metadata.gz: 3b9d5e9978c63bb8873088355270e63b10b1ac6b
4
+ data.tar.gz: 4f0be89204dd83b9535ee6396ab76884f869886e
5
5
  SHA512:
6
- metadata.gz: 957fa253958318c4329e1446b93f2fd4f38e1ae5dff12ac808b935252a4685dab1e108068d6d784e453975bc051e41b7081e0edc1a99dacf28719bd8015875d8
7
- data.tar.gz: 2f4f20eb1b235dec6796734f6ca8f23f30f9291d4f3d02c92b9ba0fc90af53c0c00dde7bf0c4646b8590aa741c433ea5771e13126128729ad21d3f59c42ee756
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
@@ -1,3 +1,3 @@
1
1
  module Timepiece
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
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.8
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-16 00:00:00.000000000 Z
11
+ date: 2015-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails