wimbarelds / TimeCircles

jQuery plugin to show time since or time until a specific time
295 stars 149 forks source link

addListener not fired if Seconds are not shown #70

Closed brainbolt closed 10 years ago

brainbolt commented 10 years ago

Using the following code, I see 'fired' logged to the console every second:

$timer.data('timer', 60).TimeCircles({
    time: {
        Days: { show: false },
        Hours: { show: false },
        Minutes: { show: false },
        Seconds: { show: true }
    },
    total_duration: 60,
    count_past_zero: false
});
$timer.TimeCircles().addListener(function (unit, value, total) {
    console.log('fired');
});

However, if I switch the visibility of Minutes and Seconds, like the following, the addListener function is never fired:

$timer.data('timer', 60).TimeCircles({
    time: {
        Days: { show: false },
        Hours: { show: false },
        Minutes: { show: true },
        Seconds: { show: false }
    },
    total_duration: 60,
    count_past_zero: false
});
$timer.TimeCircles().addListener(function (unit, value, total) {
    console.log('fired');
});
wimbarelds commented 10 years ago

The addListener function has a second parameter which determines whether the events should also trigger for time-units that are hidden. If you change your code as follows, the events should work:

$timer.data('timer', 60).TimeCircles({
    time: {
        Days: { show: false },
        Hours: { show: false },
        Minutes: { show: true },
        Seconds: { show: false }
    },
    total_duration: 60,
    count_past_zero: false
});
$timer.TimeCircles().addListener(function (unit, value, total) {
    console.log('fired');
}, "all");
brainbolt commented 10 years ago

Great, thank you.