File: Sort.js

package info (click to toggle)
pkgdiff 1.8-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 428 kB
  • sloc: xml: 3,918; perl: 3,794; sh: 705; javascript: 82; makefile: 19
file content (88 lines) | stat: -rw-r--r-- 2,164 bytes parent folder | download | duplicates (3)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function sort(el, status)
{ 
    var col_sort = el.innerHTML;
    var tr = el.parentNode;
    var table = tr.parentNode;
    var td, col_sort_num;
    for (var i=0; (td = tr.getElementsByTagName('th').item(i)); i++)
    {
        if(td.innerHTML == col_sort)
        {
            col_sort_num = i;
            if(td.prevsort == 'y') {
                el.up = Number(!el.up);
            }
            else if(td.prevsort == 'n') {
                td.prevsort = 'y';
                el.up = 0;
            }
            else
            {
                if(col_sort_num==0)
                { // already sorted
                    td.prevsort = 'n';
                    el.up = 1;
                }
                else if(col_sort_num==2)
                { // delta
                    td.prevsort = 'n';
                    el.up = 1;
                }
                else
                {
                    td.prevsort = 'y';
                    el.up = 0;
                }
            }
        }
        else
        {
            if(td.prevsort == 'y') {
                td.prevsort = 'n';
            }
        }
    }
    
    var a = new Array();
    for(var i=1; i < table.rows.length; i++)
    {
        var cols = table.rows[i].getElementsByTagName('td');
        if(cols.item(status)==null)
        { // double status
            a[i-2][2] = table.rows[i];
        }
        else
        {
            a[i-1] = new Array();
            var indent = cols.item(col_sort_num).innerHTML;
            if(indent=='') indent='0';
            if(indent.substr(indent.length-1, 1)=="%")
            { // delta
                indent = indent.substr(0, indent.length-1)*100;
            }
            a[i-1][0] = indent;
            a[i-1][1] = table.rows[i];
            a[i-1][2] = null;
        }
    }
    
    // sort table
    a.sort(sort_array);
    if(el.up) a.reverse();
    
    // draw table
    for(var i in a)
    {
        table.appendChild(a[i][1]);
        if(a[i][2]!=null) {
            table.appendChild(a[i][2]);
        }
    }
}

function sort_array(a,b)
{
    if(a[0] == b[0]) return 0;
    if(a[0] > b[0]) return 1;
    return -1;
}