timepiece 0.1.15 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1e584988953124848cdb4cd36198545a6ee41ab
4
- data.tar.gz: 3f0b0d776815b79cca35a3834340909bc790aec9
3
+ metadata.gz: 3dbd55596f758b5e9d673b9ffa962428812d609f
4
+ data.tar.gz: c09ffeb76ebdb0b1ebdc937297b9bae3392dde7b
5
5
  SHA512:
6
- metadata.gz: a5b920ef03111091d44683e3a6cbd4b70b6a4b2e02836e8a03b7ffe1308d4b84daeb56515f478aafdab81eae65e22e5a7cbaba91fb8ddf03864d7e4e21f1cc3c
7
- data.tar.gz: 24c852eed717ec68fbd3e146ba2c48b11e582b5f2b13e0e1b53561fa13d8189ad52e4760ade51f2e43f5ddb186f6c50f3b0aac5f0543303d7285dc683dca419c
6
+ metadata.gz: 56793193eb90f17b3242bd56f3f60425ae523016bf79fbcd500c4a43aa8fd9d168d67f2ce010ce878e3bea8c4f287c716b4efda8c71e969f1835f4804ecc464a
7
+ data.tar.gz: c744cf7a3de20788d3604cd76a3151895b1bc393fa99a7d48b0796932e1bc84f47bad5d34bae0faff8038580f184b385328325c0720ce3ceda753064ee5469b2
@@ -1,3 +1,71 @@
1
+ get_analog_hours = []
2
+ get_analog_minutes = []
3
+ get_analog_seconds = []
4
+
5
+ function get_analog(){
6
+ var zones = []
7
+ $(".timepiece-analog").each(function(){ zones.push($(this).attr('data-timezone')) })
8
+ var timezones = { 'timezones' : zones }
9
+ $.ajax({ type: "POST", url: "/timepiece/clock.json", data: timezones, dataType: "json", cache: false }).success(function(time){
10
+ for(var i = 0; i < time.length; i++){
11
+ get_analog_hours.push(parseInt(time[i].hours,10))
12
+ get_analog_minutes.push(parseInt(time[i].minutes,10))
13
+ get_analog_seconds.push(parseInt(time[i].seconds,10))
14
+ }
15
+ analog_hours = get_analog_hours
16
+ analog_minutes = get_analog_minutes
17
+ analog_seconds = get_analog_seconds
18
+ });
19
+ }
20
+
21
+ function show_analog(){
22
+ analog = setInterval(function(){
23
+ analog_running = true;
24
+ for(i = 0; i < analog_hours.length; i++){
25
+ if (analog_seconds[i] < 59){
26
+ analog_seconds[i] += 1
27
+ } else {
28
+ analog_seconds[i] = 0
29
+ if (analog_minutes[i] < 59){
30
+ analog_minutes[i] += 1
31
+ } else {
32
+ analog_minutes[i] = 0
33
+ if (analog_hours[i] < 23){
34
+ analog_hours[i] += 1
35
+ } else {
36
+ analog_hours[i] = 0
37
+ }
38
+ }
39
+ }
40
+ }
41
+ $(".timepiece-analog").each(function(i, e){
42
+ $(e).html(function(){
43
+ if(analog_hours[i] > 12){
44
+ $(e).data('analog_hours', analog_hours[i] - 12)
45
+ }else if(analog_hours[i] == 0){
46
+ $(e).data('analog_hours', 12)
47
+ }else if(analog_hours[i] == 12){
48
+ $(e).data('analog_hours', 12)
49
+ }else if(analog_hours[i] < 12){
50
+ $(e).data('analog_hours', analog_hours[i])
51
+ }
52
+ $(e).data('hours_angle', ($(e).data('analog_hours') * 30) + (analog_minutes[i] / 2));
53
+ $(e).data('minutes_angle', analog_minutes[i] * 6);
54
+ $(e).data('seconds_angle', analog_seconds[i] * 6);
55
+ $('.timepiece-hours-container', $(e)).css('-ms-transform','rotateZ(' + $(e).data('hours_angle') + 'deg)'); // angle set on each
56
+ $('.timepiece-hours-container', $(e)).css('-webkit-transform','rotateZ(' + $(e).data('hours_angle') + 'deg)');
57
+ $('.timepiece-hours-container', $(e)).css('transform','rotateZ(' + $(e).data('hours_angle') + 'deg)');
58
+ $('.timepiece-minutes-container', $(e)).css('-ms-transform','rotateZ(' + $(e).data('minutes_angle') + 'deg)');
59
+ $('.timepiece-minutes-container', $(e)).css('-webkit-transform','rotateZ(' + $(e).data('minutes_angle') + 'deg)');
60
+ $('.timepiece-minutes-container', $(e)).css('transform','rotateZ(' + $(e).data('minutes_angle') + 'deg)');
61
+ $('.timepiece-seconds-container', $(e)).css('-ms-transform','rotateZ(' + $(e).data('seconds_angle') + 'deg)');
62
+ $('.timepiece-seconds-container', $(e)).css('-webkit-transform','rotateZ(' + $(e).data('seconds_angle') + 'deg)');
63
+ $('.timepiece-seconds-container', $(e)).css('transform','rotateZ(' + $(e).data('seconds_angle') + 'deg)');
64
+ })
65
+ })
66
+ }, 1000)
67
+ }
68
+
1
69
  get_hours = []
2
70
  get_minutes = []
3
71
  get_seconds = []
@@ -231,6 +299,13 @@ function show_countdown(){
231
299
  }, 1000)
232
300
  }
233
301
 
302
+ function reset_analog(){
303
+ get_analog_hours = []
304
+ get_analog_minutes = []
305
+ get_analog_seconds = []
306
+ get_analog()
307
+ }
308
+
234
309
  function reset_time(){
235
310
  get_hours = []
236
311
  get_minutes = []
@@ -258,6 +333,10 @@ function reset_countdown(){
258
333
 
259
334
  $(document).ready(function(){
260
335
  // Might want to reformat to move if-statement : should also be performed before 'reset_time' so as not to make a blank AJAX request.
336
+ if ($(".timepiece-analog").length > 0){
337
+ get_analog()
338
+ show_analog()
339
+ }
261
340
  if ($(".timepiece").length > 0){
262
341
  get_time()
263
342
  show_time()
@@ -272,6 +351,12 @@ $(document).ready(function(){
272
351
  }
273
352
  })
274
353
  $(document).on('page:load', function(){
354
+ if ($(".timepiece-analog").length > 0){
355
+ if (analog_running){
356
+ clearInterval(analog);
357
+ }
358
+ reset_analog();
359
+ }
275
360
  if ($(".timepiece").length > 0){
276
361
  if (clock_running){
277
362
  clearInterval(clock);
@@ -294,6 +379,9 @@ $(document).on('page:load', function(){
294
379
  })
295
380
 
296
381
  $(window).focus(function(){
382
+ if ($(".timepiece-analog").length > 0){
383
+ reset_analog()
384
+ }
297
385
  if ($(".timepiece").length > 0){
298
386
  reset_time()
299
387
  }
@@ -1 +1,88 @@
1
- // CSS for the analogue clock version of timepiece, and maybe some optional styles for the digital.
1
+ // CSS for the analogue clock version of timepiece, and maybe some optional styles for the digital.
2
+
3
+ .timepiece-analog {
4
+ //border:solid 1em;
5
+ //border-color:#222;
6
+ border-radius: 50%;
7
+ background-color: #eee;
8
+ background-size: 88%;
9
+ position: relative;
10
+ }
11
+
12
+ .timepiece-analog:after {
13
+ background: #d00;
14
+ border-radius: 50%;
15
+ content: "";
16
+ position: absolute;
17
+ left: 50%;
18
+ top: 50%;
19
+ -ms-transform: translate(-50%, -50%);
20
+ -webkit-transform: translate(-50%, -50%);
21
+ transform: translate(-50%, -50%);
22
+ width: 5%;
23
+ height: 5%;
24
+ z-index: 10;
25
+ }
26
+
27
+ .timepiece-minutes-container, .timepiece-hours-container, .timepiece-seconds-container {
28
+ position: absolute;
29
+ top: 0;
30
+ right: 0;
31
+ bottom: 0;
32
+ left: 0;
33
+ }
34
+
35
+ .timepiece-analog-hours {
36
+ background: #333;
37
+ height: 25%; //
38
+ left: 48.75%;
39
+ position: absolute;
40
+ top: 25%; //
41
+ -ms-transform-origin: 50% 100%;
42
+ -webkit-transform-origin: 50% 100%;
43
+ transform-origin: 50% 100%;
44
+ width: 2.5%;
45
+ }
46
+
47
+ .timepiece-analog-minutes {
48
+ background: #333;
49
+ height: 40%; //
50
+ left: 49%;
51
+ position: absolute;
52
+ top: 10%; //
53
+ -ms-transform-origin: 50% 100%;
54
+ -webkit-transform-origin: 50% 100%;
55
+ transform-origin: 50% 100%;
56
+ width: 2%;
57
+ }
58
+
59
+ .timepiece-analog-seconds {
60
+ background: #d00;
61
+ height: 45%; //
62
+ left: 49.5%;
63
+ position: absolute;
64
+ top: 14%; //
65
+ -ms-transform-origin: 50% 80%;
66
+ -webkit-transform-origin: 50% 80%;
67
+ transform-origin: 50% 80%;
68
+ width: 1%;
69
+ z-index: 8;
70
+ }
71
+
72
+ // Animation code - unused but kept for reference:
73
+ // We should animate the clocks into correct positions when the clock refreshes on page reentry.
74
+ /*
75
+ @-webkit-keyframes rotate {
76
+ 100% {-webkit-transform: rotateZ(360deg);}
77
+ }
78
+
79
+ .timepiece-hours-container {
80
+ -webkit-animation: rotate 43200s infinite linear;
81
+ }
82
+ .timepiece-minutes-container {
83
+ -webkit-animation: rotate 3600s infinite steps(60);
84
+ }
85
+ .timepiece-seconds-container {
86
+ -webkit-animation: rotate 60s infinite steps(60);
87
+ }
88
+ */
@@ -40,6 +40,20 @@ module TimepieceHelper
40
40
  content_tag(:span, time.html_safe, class: 'timepiece', 'data-timezone' => location, 'data-tptype' => type, 'data-lead' => lead, 'data-abbr_separator' => abbr_sep, 'id' => (id unless id.blank?))
41
41
  end
42
42
 
43
+ def analog(location = 'UTC', id: '', size: '10em')
44
+ Time.zone = location
45
+ hours = Time.now.in_time_zone.strftime('%I')
46
+ minutes = Time.now.in_time_zone.strftime('%M')
47
+ seconds = Time.now.in_time_zone.strftime('%S')
48
+ hours_angle = (hours.to_i * 30) + (minutes.to_i / 2)
49
+ minutes_angle = minutes.to_i * 6
50
+ seconds_angle = seconds.to_i * 6
51
+ time = "<div class='timepiece-hours-container' style='-ms-transform:rotateZ(#{hours_angle}deg);-webkit-transform:rotateZ(#{hours_angle}deg);transform:rotateZ(#{hours_angle}deg);'><div class='timepiece-analog-hours'></div></div>"\
52
+ "<div class='timepiece-minutes-container' style='-ms-transform:rotateZ(#{minutes_angle}deg);-webkit-transform:rotateZ(#{minutes_angle}deg);transform:rotateZ(#{minutes_angle}deg);'><div class='timepiece-analog-minutes'></div></div>"\
53
+ "<div class='timepiece-seconds-container' style='-ms-transform:rotateZ(#{seconds_angle}deg);-webkit-transform:rotateZ(#{seconds_angle}deg);transform:rotateZ(#{seconds_angle}deg);'><div class='timepiece-analog-seconds'></div></div>"
54
+ content_tag(:article, time.html_safe, class: 'timepiece-analog', 'data-timezone' => location, 'id' => (id unless id.blank?), 'style' => 'width:' + size + ';padding-bottom:' + size + ';')
55
+ end
56
+
43
57
  def timer(time_since = Time.now, id: '')
44
58
  seconds_diff = (Time.now - time_since).to_i
45
59
 
@@ -1,3 +1,3 @@
1
1
  module Timepiece
2
- VERSION = "0.1.15"
2
+ VERSION = "0.2.0"
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.15
4
+ version: 0.2.0
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-05-07 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails