Page 1 of 1

pe:timer with milliseconds [Solved]

Posted: 29 Jan 2019, 18:39
by marcoszamparo
Is there a way to run pe:timer with milliseconds than seconds?
I need to run a timer each 100 milliseconds.
Thanks

Re: pe:timer with milliseconds

Posted: 30 Jan 2019, 14:41
by Melloware
Yes. Add the below JavaScript to your page to override the "start" method of the widget to set the interval to 100 instead of 1000.

Code: Select all

PrimeFaces.widget.ExtTimer.prototype.start = function() {
    var that = this;
    var end;
    this.prevTime = this.currentTimeInSecs();

    if(!this.interval){
        this.interval = setInterval(function(){
            that.doStep();

            end = that.forward ? that.currentTimeout >= that.originalTimeout : that.currentTimeout <= 0;

            if(end){
                if(that.cfg.listener){
                    that.cfg.listener();
                }
                if(that.cfg.ontimercomplete){
                    that.cfg.ontimercomplete();
                }
                if(that.cfg.singleRun){
                    clearInterval(that.interval);
                    this.interval = null;
                }else{
                    that.currentTimeout = that.forward ? 0 : that.originalTimeout;
                    that.print();
                }
            }
        }, 100);
    }
}

Re: pe:timer with milliseconds

Posted: 30 Jan 2019, 19:46
by marcoszamparo
Thanks! It worked! :D

Re: pe:timer with milliseconds [Solved]

Posted: 30 Jan 2019, 19:48
by Melloware
Nice!!!

Re: pe:timer with milliseconds [Solved]

Posted: 31 Jan 2019, 14:29
by Melloware
Just an FYI I added an "interval" attribute to pe:timer for 7.0 so you can configure this as an attribute.

See ticket: https://github.com/primefaces-extension ... issues/645