Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding capabilities to allow timer to loop, to run at start (without …

…timer selection) and to run with single interval (rather than multiple with selection)
  • Loading branch information...
commit bdc6fdf7b539b0eea393dd0c54b0cc9cd02caac7 1 parent 29263f4
Luke van der Hoeven plukevdh authored

Showing 1 changed file with 46 additions and 20 deletions. Show diff stats Hide diff stats

  1. +46 20 lib/jquery.timer360.js
66 lib/jquery.timer360.js
@@ -33,7 +33,9 @@
33 33 strokeColor : "#477050", // the color of the stroke
34 34 fillColor : "#8ac575", // the fill color
35 35 intervals : [5,25,30], // the options for the timer
  36 + interval : 10, // allowed to have single timer.
36 37 seconds : false, // if false then interval is considered minutes
  38 + loop : false, // timer will loop if true
37 39 onComplete : new Function
38 40 }, options);
39 41
@@ -44,7 +46,7 @@
44 46
45 47 return this.each(function () {
46 48 var $this = $(this);
47   - var interval = null;
  49 + var interval = settings.interval;
48 50 var start = null;
49 51
50 52 // Create the canvas
@@ -52,24 +54,33 @@
52 54 settings.width + '" height="' +
53 55 settings.height + '"></canvas>');
54 56 var canvas = $canvas[0];
55   - var intervalItems = '';
56   - for (x in settings.intervals)
57   - {
58   - intervalItems += '<li>' + settings.intervals[x] + '</li>'
59   - }
60   - var $timerSelect = $('<div class="timer_select">' +
61   - '<ul>' + intervalItems + '</ul>' + '</div>');
62   -
63   - $this.prepend(canvas).append($timerSelect.hide()).css({position:'relative'}).click(function () {
64   - $timerSelect.toggle();
65   - });
66   -
67   - $timerSelect.find('li').click(function () {
68   - if (interval) { clearInterval(interval) }
69   - start = new Date();
70   - tick(settings.seconds ? $(this).text()/60 : $(this).text());
71   - });
72   -
  57 +
  58 + $this.prepend(canvas);
  59 +
  60 + if(settings.intervals != false) {
  61 + var intervalItems = '';
  62 +
  63 + for (x in settings.intervals) {
  64 + intervalItems += '<li>' + settings.intervals[x] + '</li>'
  65 + }
  66 +
  67 + var $timerSelect = $('<div class="timer_select">' +
  68 + '<ul>' + intervalItems + '</ul>' + '</div>');
  69 +
  70 + $this.append($timerSelect.hide()).css({position:'relative'}).click(function () {
  71 + $timerSelect.toggle();
  72 + });
  73 +
  74 + $timerSelect.find('li').click(function () {
  75 + if (interval) { clearInterval(interval) }
  76 + start = start_clock($(this));
  77 + });
  78 + }
  79 +
  80 + if(settings.intervals == false && start == null) {
  81 + start = start_clock(null);
  82 + }
  83 +
73 84 // get context for the canvas and create the initial circle
74 85 var pen = canvas.getContext('2d');
75 86 pen.lineWidth = settings.strokeWidth;
@@ -91,12 +102,16 @@
91 102
92 103 pen.clearRect(0,0,settings.width, settings.height);
93 104 drawTimer(Math.PI*2, false);
94   - if ((secondsElapsed - 1) < (amount*60)) {
  105 + if ((secondsElapsed) < (amount*60)) {
95 106 drawTimer(incrementAmount*(secondsElapsed*1000), true);
96 107 } else {
97 108 drawTimer(Math.PI*2, true)
98 109 clearInterval(interval);
99 110 settings.onComplete();
  111 + if(settings.loop == true) {
  112 + clearInterval(interval)
  113 + start = start_clock(null);
  114 + }
100 115 }
101 116 }, 1000);
102 117 }
@@ -107,6 +122,17 @@
107 122 pen.fill();
108 123 if (drawStroke) { pen.stroke(); }
109 124 }
  125 +
  126 + function start_clock(clock) {
  127 + var start = new Date();
  128 + if(settings.intervals != false && clock != null) {
  129 + tick(settings.seconds ? clock.text()/60 : clock.text());
  130 + } else {
  131 + tick(settings.seconds ? settings.interval/60 : settings.interval);
  132 + }
  133 + return start;
  134 + }
  135 +
110 136 });
111 137
112 138 };

0 comments on commit bdc6fdf

Please sign in to comment.
Something went wrong with that request. Please try again.