timepiece 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/timepiece.js +53 -1
- data/app/helpers/timepiece_helper.rb +25 -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: 074f293bf77574c895a32e9eb6e2ff4f10f5d7b1
|
4
|
+
data.tar.gz: 030b9447686b023fde32e90512a479456b856b20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ff01dcc468866c7b44808ae1221bf8cc0c020752986ceae3216a577220cfef285d4da908d6404cc472885722e370ca0a5601b5a3755cb2b96ba7b7326928ff9
|
7
|
+
data.tar.gz: c0b2e7ff32a3e03085288e0ecd891b95e424e8005aea819bc2b26de33dcf4ea9de06a3420f70885eba1d0b061849316643b9cd3db5b995fbb90e82887347b99d
|
@@ -19,7 +19,7 @@ function get_time(){
|
|
19
19
|
}
|
20
20
|
|
21
21
|
function show_time(){
|
22
|
-
|
22
|
+
clock = setInterval(function(){
|
23
23
|
for(i = 0; i < hours.length; i++){
|
24
24
|
if (seconds[i] < 59){
|
25
25
|
seconds[i] += 1
|
@@ -83,6 +83,55 @@ function show_time(){
|
|
83
83
|
}, 1000)
|
84
84
|
}
|
85
85
|
|
86
|
+
get_timer_days = []
|
87
|
+
get_timer_hours = []
|
88
|
+
get_timer_minutes = []
|
89
|
+
get_timer_seconds = []
|
90
|
+
|
91
|
+
function set_timer(){
|
92
|
+
$(".timepiece-timer").each(function(){
|
93
|
+
get_timer_days.push(parseInt($(this).attr('data-days'),10))
|
94
|
+
get_timer_hours.push(parseInt($(this).attr('data-hours'),10))
|
95
|
+
get_timer_minutes.push(parseInt($(this).attr('data-minutes'),10))
|
96
|
+
get_timer_seconds.push(parseInt($(this).attr('data-seconds'),10))
|
97
|
+
timer_days = get_timer_days
|
98
|
+
timer_hours = get_timer_hours
|
99
|
+
timer_minutes = get_timer_minutes
|
100
|
+
timer_seconds = get_timer_seconds
|
101
|
+
});
|
102
|
+
}
|
103
|
+
|
104
|
+
function show_timer(){
|
105
|
+
timer = setInterval(function(){
|
106
|
+
for(i = 0; i < timer_hours.length; i++){
|
107
|
+
if (timer_seconds[i] < 59){
|
108
|
+
timer_seconds[i] += 1
|
109
|
+
} else {
|
110
|
+
timer_seconds[i] = 0
|
111
|
+
if (timer_minutes[i] < 59){
|
112
|
+
timer_minutes[i] += 1
|
113
|
+
} else {
|
114
|
+
timer_minutes[i] = 0
|
115
|
+
if (timer_hours[i] < 23){
|
116
|
+
timer_hours[i] += 1
|
117
|
+
} else {
|
118
|
+
timer_hours[i] = 0
|
119
|
+
timer_days[i] += 1
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
$(".timepiece-timer").each(function(i, e){
|
125
|
+
$(e).html(function(){
|
126
|
+
$('.timepiece-days', $(e)).html(( timer_days[i] < 10 ? "0" : "" ) + timer_days[i]);
|
127
|
+
$('.timepiece-hours', $(e)).html(( timer_hours[i] < 10 ? "0" : "" ) + timer_hours[i]);
|
128
|
+
$('.timepiece-minutes', $(e)).html(( timer_minutes[i] < 10 ? "0" : "" ) + timer_minutes[i]);
|
129
|
+
$('.timepiece-seconds', $(e)).html(( timer_seconds[i] < 10 ? "0" : "" ) + timer_seconds[i]);
|
130
|
+
})
|
131
|
+
})
|
132
|
+
}, 1000)
|
133
|
+
}
|
134
|
+
|
86
135
|
function reset_time(){
|
87
136
|
get_hours = []
|
88
137
|
get_minutes = []
|
@@ -92,9 +141,12 @@ function reset_time(){
|
|
92
141
|
|
93
142
|
$(document).ready(function(){
|
94
143
|
get_time()
|
144
|
+
set_timer()
|
95
145
|
show_time()
|
146
|
+
show_timer()
|
96
147
|
})
|
97
148
|
$(document).on('page:load', function(){
|
149
|
+
clearInterval(clock);
|
98
150
|
clearInterval(timer);
|
99
151
|
// Quickfix for Turbolinks. We should revisit this.
|
100
152
|
})
|
@@ -38,4 +38,29 @@ module TimepieceHelper
|
|
38
38
|
end
|
39
39
|
content_tag(:span, time.html_safe, class: 'timepiece', 'data-timezone' => location, 'data-tptype' => type, 'data-lead' => lead, 'data-abbr_separator' => abbr_sep)
|
40
40
|
end
|
41
|
+
|
42
|
+
def timer(time_since = Time.now)
|
43
|
+
seconds_diff = (Time.now - time_since).to_i
|
44
|
+
|
45
|
+
days = seconds_diff / 86400
|
46
|
+
seconds_diff -= days * 86400
|
47
|
+
|
48
|
+
hours = seconds_diff / 3600
|
49
|
+
seconds_diff -= hours * 3600
|
50
|
+
|
51
|
+
minutes = seconds_diff / 60
|
52
|
+
seconds_diff -= minutes * 60
|
53
|
+
|
54
|
+
seconds = seconds_diff
|
55
|
+
|
56
|
+
time = "<span class='timepiece-days'>#{days.to_s.rjust(2, '0')}</span>"\
|
57
|
+
"<span class='timepiece-descriptor tp-descriptor-days'> days </span>"\
|
58
|
+
"<span class='timepiece-hours'>#{hours.to_s.rjust(2, '0')}</span>"\
|
59
|
+
"<span class='timepiece-separator tp-separator-1'>:</span>"\
|
60
|
+
"<span class='timepiece-minutes'>#{minutes.to_s.rjust(2, '0')}</span>"\
|
61
|
+
"<span class='timepiece-separator tp-separator-2'>:</span>"\
|
62
|
+
"<span class='timepiece-seconds'>#{seconds.to_s.rjust(2, '0')}</span>"
|
63
|
+
|
64
|
+
content_tag(:span, time.html_safe, class: 'timepiece-timer', 'data-days' => days, 'data-hours' => hours, 'data-minutes' => minutes, 'data-seconds' => seconds)
|
65
|
+
end
|
41
66
|
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.6
|
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-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|