objectivehtml / FlipClock

http://flipclockjs.com/
MIT License
2.74k stars 954 forks source link

Stop callback not working #110

Closed Riaan-ZA closed 10 years ago

Riaan-ZA commented 10 years ago

Hi there, the stop callback is not working for me, even the example included is not working.

clock = $('.clock').FlipClock(10, { clockFace: 'MinuteCounter', countdown: true, callbacks: { stop: function() { $('.message').html('The clock has stopped!'); } } });

Starts counting down from 10, but that the clock goes haywire, and the stop callback never fires off.

bhgames commented 10 years ago

Having a similar problem. Never fires, only restarts clock at 1:05 or something strange.

objectivehtml commented 10 years ago

Yeah, I am looking into this issue right now. I refactored a bunch of code in the core and this was something else that broke. Once I get all these issues fixed, the core lib will be easier to maintain with a more consistent API.

bhgames commented 10 years ago

If you figure it out, let me know. I'm looking into using the interval callback and the this object to make it do something when the clock finishes.

On Tue, Jun 3, 2014 at 11:28 AM, Justin Kimbrell notifications@github.com wrote:

Yeah, I am looking into this issue right now. I refactored a bunch of code in the core and this was something else that broke. Once I get all these issues fixed, the core lib will be easier to maintain with a more consistent API.

— Reply to this email directly or view it on GitHub https://github.com/objectivehtml/FlipClock/issues/110#issuecomment-44987681 .

Jordan Prince

CTO - boardvitals.com jordanmprince@gmail.com [image: Facebook] http://s.wisestamp.com/links?url=https%3A%2F%2Fwww.facebook.com%2Fboardvitals&sn= [image: Twitter] http://s.wisestamp.com/links?url=http%3A%2F%2Ftwitter.com%2Fboardvitals&sn= [image: LinkedIn] http://s.wisestamp.com/links?url=http%3A%2F%2Fwww.linkedin.com%2Fcompany%2Fboard-vitals-llc%3Ftrk%3Dcompany_name&sn= [image: WordPress] http://s.wisestamp.com/links?url=http%3A%2F%2Fwww.boardvitals.com%2Fboard-review-blog%2F&sn=

bhgames commented 10 years ago

I figured otu a quick fix for this, for my countdown clock. Obviously it needs to be rewritten a bit more nicely for general use but here it is: Replace the increment function in FlipClock.Face with:

    /**
     * Increments the time with each face flip
     */

    increment: function() {
        if (!(this.factory.time.time instanceof Date)) {
            if(!this.factory.countdown) {
                this.factory.time.addSecond();
            }
            else {
                this.factory.time.subSecond();
      if(this.factory.time.time == 0) {
        this.factory.stop()
      }

            }
        }
    },
objectivehtml commented 10 years ago

Actually, this is a pretty good implementation and a decent place to start. I just added that increment method for this exact purpose. That code should work for everything (of the top of my head), as the counter face overrides that method anyway.

bhgames commented 10 years ago

Want me to make a PR?

objectivehtml commented 10 years ago

yeah make a PR, and I will do a merge. this.factory.time.time should be this.factory.time.getTimeSeconds() which is a new method to get the time in seconds.