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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
function make_collapsible(heading, section)
{
var hidden = false;
var display = section.style.display;
var icon = heading.insertBefore(document.createElement('img'), heading.firstChild);
icon.setAttribute('src', assetsurl + '/disclosedown.svg');
icon.setAttribute('class', 'disclosure');
icon.addEventListener(
'click',
function (event)
{
hidden = !hidden;
if (hidden)
{
icon.setAttribute('src', assetsurl + '/discloseup.svg');
section.style.display = 'none';
}
else
{
icon.setAttribute('src', assetsurl + '/disclosedown.svg');
section.style.display = display;
var headingtop = 0;
for (var element = heading; element !== null; element = element.offsetParent)
headingtop += element.offsetTop;
var sectionbot = section.offsetHeight;
for (var element = section; element !== null; element = element.offsetParent)
sectionbot += element.offsetTop;
if ((window.pageYOffset + window.innerHeight) < sectionbot)
{
if ((sectionbot - headingtop) > window.innerHeight)
heading.scrollIntoView(true);
else
window.scroll(window.pageXOffset, sectionbot - window.innerHeight);
}
}
});
}
function make_table_sortable(tbl)
{
var sorticons = new Array(tbl.tHead.rows[0].cells.length);
function TableSortHelper(i)
{
this.column = i;
this.header = tbl.tHead.rows[0].cells[i];
this.sorted = false;
this.direction = 1;
var container = this.header.appendChild(document.createElement('div'));
container.setAttribute('class', 'sorticon');
this.icon = container.appendChild(document.createElement('img'));
this.icon.setAttribute('src', assetsurl + '/sortind.svg');
this.icon.addEventListener('click', this.icon_click.bind(this));
}
TableSortHelper.prototype = (function ()
{
function set_unsorted(obj)
{
obj.sorted = false;
obj.icon.setAttribute('src', assetsurl + '/sortind.svg');
}
function sort_table(obj)
{
var c = obj.header.cellIndex;
var numeric = obj.header.getAttribute('class') == 'numeric';
var tbody = tbl.tBodies[0];
var trows;
if (numeric)
{
trows = Array.prototype.slice.call(tbody.rows, 0).sort(
function (x, y)
{
return obj.direction * (parseFloat(x.cells[c].textContent) - parseFloat(y.cells[c].textContent));
});
}
else
{
trows = Array.prototype.slice.call(tbody.rows, 0).sort(
function (x, y)
{
return obj.direction * x.cells[c].textContent.localeCompare(y.cells[c].textContent);
});
}
trows.forEach(function (row) { tbody.appendChild(row); });
}
return {
icon_click : function (event)
{
if (this.sorted)
this.direction = -this.direction;
if (this.direction < 0)
this.icon.setAttribute('src', assetsurl + '/sortdesc.svg');
else
this.icon.setAttribute('src', assetsurl + '/sortasc.svg');
this.sorted = true;
for (var i = 0; i < sorticons.length; i++)
{
if (i != this.column)
set_unsorted(sorticons[i]);
}
sort_table(this);
}
};
})();
for (var i = 0; i < sorticons.length; i++)
sorticons[i] = new TableSortHelper(i);
}
function make_restore_default_handler(popup, index)
{
return function (event)
{
if (popup.selectedIndex != index)
{
popup.selectedIndex = index;
popup.dispatchEvent(new Event('change'));
}
}
}
function make_restore_default_button(title, id, popup, index)
{
var btn = document.createElement('button');
btn.setAttribute('id', id);
btn.setAttribute('type', 'button');
btn.disabled = popup.selectedIndex == index;
btn.textContent = title;
btn.onclick = make_restore_default_handler(popup, index);
return btn;
}
|