# All files / src/helpers DOM.js

15.79% Statements 3/19
10% Branches 1/10
16.67% Functions 1/6
15.79% Lines 3/19

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
    511x

    1x

    1x

     let currentDir: "ltr" | "rtl" | "auto"  = "auto";
    // let currentDir = "auto";

    function hasDocument(){
        return (typeof document !== "undefined");
    }

    function hasWindow(){
        return (typeof window !== "undefined");
    }

    export function getDocumentDir(){
        if(!hasDocument()){
            return currentDir;
        }
        const direction = (typeof document.dir !== "undefined") ?
            document.dir :
            document.getElementsByTagName("html")[0].getAttribute("dir");
        return direction;
    }

    export function setDocumentDir(dir: "ltr" | "rtl" | "auto"){
    // export function setDocumentDir(dir){
        if(!hasDocument){
            currentDir = dir;
            return;
        }

        const html = document.getElementsByTagName("html")[0];
        html.setAttribute("dir", dir);
    }

    export function addWindowEventListener(event:string, callback: () => mixed){
        Iif(!hasWindow){

            callback();
            return;
        }
        window.addEventListener(event, callback);
    }

    export function removeWindowEventListener(event:string, callback: () => mixed){
        if(!hasWindow){
            return;
        }
        window.removeEventListener(event, callback);
    }