pleasewait.ts 1.18 KB
Newer Older
Tomas Pettersson's avatar
Tomas Pettersson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/// <reference path="../def/uikit.d.ts" />

class PleaseWait {
    public StartMilliseconds: number;
    public ElapsedMilliseconds: number;
    private wait: boolean;
    private modal: any;

    constructor() {
        this.StartMilliseconds = 0;
        this.ElapsedMilliseconds = 0;
    }
    public start() {
        var self = this;
        self.StartMilliseconds = new Date().getTime();
        self.wait = true;
        setTimeout(function () {
            if (self.wait) self.modal = self.pleaseWaitModal();
        }, 500);
    }
    public stop() {
        var self = this;
        this.ElapsedMilliseconds = new Date().getTime() - this.StartMilliseconds;
        self.wait = false;
        if (self.modal) {
            var timeLeft = 2000 - self.ElapsedMilliseconds; // wait minimum 2 sec
            if (timeLeft > 0) {
                setTimeout(function () {
                    self.modal.hide();
                }, timeLeft);
            } else {
                self.modal.hide();
            }
        }
    } 

    private pleaseWaitModal() {
        return UIkit.modal.blockUI('<div class="uk-modal-spinner"></div><div class="uk-margin-botttom"><b>Please wait...</b></div>');
    }
}