Skip to content

Commit eccb28e

Browse files
committed
Merge pull request walmik#34 from walmik/develop
Refactored regressive timer. Added test.
2 parents 5d99f34 + f95b239 commit eccb28e

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

dist/timer.jquery.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/timer.jquery.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@
7070
* Render pretty time
7171
*/
7272
function render() {
73+
var sec = totalSeconds;
74+
7375
if (options.countdown && duration > 0) {
74-
$el[display](secondsToTime(duration - totalSeconds));
75-
} else {
76-
$el[display](secondsToTime(totalSeconds));
76+
sec = duration - totalSeconds;
7777
}
78-
$el.data('seconds', totalSeconds);
78+
79+
$el[display](secondsToTime(sec));
80+
$el.data('seconds', sec);
7981
}
8082

8183
function makeEditable() {
@@ -265,7 +267,6 @@
265267
duration = options.duration = timeToSeconds(options.duration);
266268
}
267269

268-
269270
if (options.editable) {
270271
makeEditable();
271272
}

test/timer.jquery.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@
44
scenarios = [],
55
count = 0; // To print 'Done! on completion of tests
66

7+
/*test('timer supports countdown', function() {
8+
$('#timer').timer({
9+
duration: '3s',
10+
countdown: true,
11+
callback: function() {
12+
$('#timer').timer('pause');
13+
}
14+
});
15+
16+
// Pause test momentarily
17+
stop();
18+
19+
// Check value of callbackExecuted in 3 seconds (+ minor offset to run assertion comfortably)
20+
setTimeout(function() {
21+
equal($('#timer').data('seconds'), 0, 'Timer counts down to 0 seconds if countdown was enabled.');
22+
$('#timer').val('').timer('remove');
23+
24+
start();
25+
}, 3500);
26+
});*/
27+
728
// Timer resets to 0 seconds if reset was called
829
test('timer resets to 0 seconds if reset was called', function() {
930
$('#timer').timer({
@@ -142,7 +163,7 @@
142163
equal(callbackExecuted, true, 'Timer translates duration of 5h30m10s correctly.');
143164
$('#timer').val('').timer('remove');
144165

145-
start();
166+
start();
146167
}, 2500);
147168
});
148169

0 commit comments

Comments
 (0)