Passed
Push — master ( 91e4ab...1def37 )
by Plamen
01:28
created

table_helper.Init   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 1
dl 0
loc 20
rs 9.7
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 11 3
1
var table_helper = {
2
    Init: function(tableId){
3
        var tContainer = document.getElementById(tableId);
4
        if(!this.IePrior(9)){
5
            SetColumnsHoverEffect(tContainer, tableId);
6
        }
7
        var tfoot = tContainer.getElementsByTagName("tfoot")[0];
8
        this.ProcessPaginationLinks(tfoot);
9
        
10
        function SetColumnsHoverEffect(tContainer, tableId){
11
            var tHcells = tContainer.rows[0].cells;
12
            for(var i = 0; i < tHcells.length; i++){
13
                if(tHcells[i].firstChild.tagName === "A"){
14
                    tHcells[i].firstChild.setAttribute("onmouseover",
15
                            "table.ColumnHover('" + tableId + "'," + i + ");");
16
                    tHcells[i].firstChild.setAttribute("onmouseout",
17
                            "table.ColumnHover('" + tableId + "');");
18
                }
19
            }
20
        }
21
    },
22
    ColumnHover: function(tableContainer, index){
23
        var rows = document.getElementById(tableContainer).rows;
24
        var upto = rows.length - 1;
25
        if(typeof index === "undefined"){
26
            ColumnHoverRelease(rows, upto);
27
        }else{
28
            for(var i = 0; i < upto; i++){
29
                rows[i].cells[index].setAttribute("lang", "col-hover");
30
            }
31
        }
32
        function ColumnHoverRelease(rows, upto){
33
            for(var i = 0; i < upto; i++){
34
                for(var j = 0; j < rows[i].cells.length; j++){
35
                    if(rows[i].cells[j].lang){
36
                        rows[i].cells[j].removeAttribute("lang");
37
                    }
38
                }
39
            }
40
        };
41
    },
42
    IePrior: function(v){
43
        var rv = false;
44
        if(window.navigator.appName === 'Microsoft Internet Explorer'){
45
            var ua = window.navigator.userAgent;
46
            var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
47
            if(re.exec(ua) !== null){
48
                rv = parseFloat(RegExp.$1);
49
            }
50
            rv = rv < v ? true : false;
51
        }
52
        return rv;
53
    },
54
    GetParent: function(obj, objType){
55
        while(obj && obj.tagName !== objType.toUpperCase()){
56
            obj = obj.parentNode;
57
        }
58
        return obj;
59
    },
60
    ProcessPaginationLinks: function(tfoot){
61
        var pLinks = tfoot.querySelectorAll(".paging a");
62
        if(pLinks.length > 0){
63
            for(var j = 0; j < pLinks.length; j++){
64
                pLinks[j].setAttribute("href", "javascript:void(0);");
65
                pLinks[j].setAttribute("onclick", "return table.GoPage(this);");
66
            }
67
        }
68
    },
69
    RequestToUrl: function(rq){
70
        var url = location.pathname + ".json" + location.search;
71
        if(typeof rq === "object"){
72
            var getUrlVarName = {
73
                colNo: "col", colOrd: "ord", filter: "filter",
74
                filterBy: "filter-by", pageNo: "pg", exportType: "export",
75
                tableId: "table-id"
76
            };
77
            var flagFirst = location.search.length < 1 ? true : false;
78
            for(var r in rq){
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
79
                var clue = flagFirst === true ? "?" : "&";
80
                url += clue + getUrlVarName[r] + "=" + rq[r];
81
                flagFirst = false;
82
            }
83
        }
84
        return url;
85
    },
86
    RqObject: function(tableId){
87
        var rq = {};
88
        rq.tableId = tableId;
89
        rq.strDesc = this.strDesc;
90
        rq.strAsc = this.strAsc;
91
        return rq;
92
    }
93
};
94