Passed
Push — master ( 506943...0f9777 )
by Plamen
01:27
created

add/table_helper.js   A

Complexity

Total Complexity 16
Complexity/F 3.2

Size

Lines of Code 53
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
cc 0
eloc 39
c 3
b 0
f 1
nc 1
dl 0
loc 53
rs 10
wmc 16
mnd 3
bc 12
fnc 5
bpm 2.4
cpm 3.2
noi 1

5 Functions

Rating   Name   Duplication   Size   Complexity  
A table_helper.RequestToUrl 0 17 5
A table_helper.GetParent 0 6 3
A table_helper.ProcessPaginationLinks 0 9 3
A table_helper.RqObject 0 7 1
A table_helper.IePrior 0 12 4
1
var table_helper = {
2
    IePrior: function(v){
3
        var rv = false;
4
        if(window.navigator.appName === 'Microsoft Internet Explorer'){
5
            var ua = window.navigator.userAgent;
6
            var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
7
            if(re.exec(ua) !== null){
8
                rv = parseFloat(RegExp.$1);
9
            }
10
            rv = rv < v ? true : false;
11
        }
12
        return rv;
13
    },
14
    GetParent: function(obj, objType){
15
        while(obj && obj.tagName !== objType.toUpperCase()){
16
            obj = obj.parentNode;
17
        }
18
        return obj;
19
    },
20
    ProcessPaginationLinks: function(tfoot){
21
        var pLinks = tfoot.querySelectorAll(".paging a");
22
        if(pLinks.length > 0){
23
            for(var j = 0; j < pLinks.length; j++){
24
                pLinks[j].setAttribute("href", "javascript:void(0);");
25
                pLinks[j].setAttribute("onclick", "return table.GoPage(this);");
26
            }
27
        }
28
    },
29
    RequestToUrl: function(rq){
30
        var url = location.pathname + ".json" + location.search;
31
        if(typeof rq === "object"){
32
            var getUrlVarName = {
33
                colNo: "col", colOrd: "ord", filter: "filter",
34
                filterBy: "filter-by", pageNo: "pg", exportType: "export",
35
                tableId: "table-id"
36
            };
37
            var flagFirst = location.search.length < 1 ? true : false;
38
            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...
39
                var clue = flagFirst === true ? "?" : "&";
40
                url += clue + getUrlVarName[r] + "=" + rq[r];
41
                flagFirst = false;
42
            }
43
        }
44
        return url;
45
    },
46
    RqObject: function(tableId){
47
        var rq = {};
48
        rq.tableId = tableId;
49
        rq.strDesc = this.strDesc;
50
        rq.strAsc = this.strAsc;
51
        return rq;
52
    }
53
};
54