All files / mframejs/utils dom.ts

64.71% Statements 11/17
50% Branches 1/2
87.5% Functions 7/8
64.71% Lines 11/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                                  29x     1988x       67x               31x 31x       108x 108x 108x 108x   108x               108x            
let DOCUMENT: any;
let WINDOW: any;
let NODE_FILTER: any = {
    SHOW_ALL: -1,
    FILTER_ACCEPT: 1,
    FILTER_REJECT: 2
};
{
    try {
        if (document) {
            DOCUMENT = document;
        }
 
        if (window) {
            WINDOW = window;
        }
 
        if (NodeFilter) {
            NODE_FILTER = NodeFilter;
        }
    } catch (e) {
        // todo
    }
}
 
export class DOM {
 
    public static get document(): Document {
        return DOCUMENT;
    }
 
    public static get window(): Window {
        return WINDOW;
    }
 
    public static get nodeFilter(): NodeFilter | any {
        return <any>NODE_FILTER;
    }
 
    public static setConfig(win: Window, doc: Document) {
        DOCUMENT = doc;
        WINDOW = win;
    }
 
    public static waitFor(time = 30, intervals = 0): Promise<void> {
        return new Promise((resolve: Function) => {
            let no = 0;
            const waiter = () => {
                setTimeout(() => {
                    if (no === intervals) {
                        resolve();
                    } else {
                        no++;
                        waiter();
                    }
 
                }, time);
            };
            waiter();
        });
 
    }
 
}