-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
131 lines (124 loc) · 3.45 KB
/
scripts.js
File metadata and controls
131 lines (124 loc) · 3.45 KB
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
const cableData = {
USB: [
{
name: "USB 2.0",
connectors: ["Type-A", "Type-B", "Mini-USB", "Micro-USB"],
"Max Speed": "480 Mbps",
"Release Year": 2000,
"Alternate Names": ["Hi-Speed USB"],
},
{
name: "USB 3.0",
connectors: ["Type-A", "Type-B", "Micro-B"],
"Max Speed": "5 Gbps",
"Release Year": 2008,
"Alternate Names": ["SuperSpeed USB, USB 5Gbps"],
},
{
name: "USB 3.1",
"Max Speed": "10 Gbps",
"Release Year": 2013,
},
{
name: "USB 3.2",
"Max Speed": "20 Gbps",
"Release Year": 2017,
},
{
name: "USB4",
"Max Speed": "40 Gbps",
"Release Year": 2019,
},
],
Display: [
{
name: "HDMI 1.4",
max_resolution: "4K at 30Hz",
"Release Year": 2009,
},
{
name: "HDMI 2.0",
max_resolution: "4K at 60Hz",
"Release Year": 2013,
},
{
name: "HDMI 2.1",
max_resolution: "10K at 120Hz",
"Release Year": 2017,
},
{
name: "DisplayPort 1.2",
max_resolution: "4K at 60Hz",
"Release Year": 2010,
},
{
name: "DisplayPort 1.4",
max_resolution: "8K at 60Hz",
"Release Year": 2016,
},
],
};
const select = document.createElement("select");
function createCableSelect(colIndex) {
const select = document.createElement("select");
const defaultOption = document.createElement("option");
defaultOption.textContent = "Select a Cable";
defaultOption.selected = defaultOption.disabled = true;
select.appendChild(defaultOption);
for (var i = 0; i < Object.keys(cableData).length; i++) {
const optgroup = document.createElement("optgroup");
optgroup.label = Object.keys(cableData)[i];
cableData[Object.keys(cableData)[i]].forEach((item) => {
const option = document.createElement("option");
option.value = item.name;
option.textContent = item.name;
optgroup.appendChild(option);
});
select.appendChild(document.createElement("hr"));
select.appendChild(optgroup);
}
select.addEventListener("change", (event) => {
if (select.firstChild.textContent === "Select a Cable") {
select.removeChild(select.firstChild);
}
updateColumn(colIndex, event.target.value);
});
return select;
}
function addColumn() {
const table = document.getElementById("myTable");
const colIndex = table.rows[0].cells.length;
for (let i = 0; i < table.rows.length; i++) {
const row = table.rows[i];
const cell = row.insertCell(-1);
if (i === 0) {
cell.appendChild(createCableSelect(colIndex));
} else {
cell.textContent = "-";
}
}
}
function removeColumn() {
const table = document.getElementById("myTable");
const colIndex = table.rows[0].cells.length - 1;
for (let row of table.rows) {
if (row.cells.length > 1) row.deleteCell(colIndex);
}
}
function updateColumn(colIndex, value) {
const table = document.getElementById("myTable");
const item =
cableData.Display.find((d) => d.name === value) ||
cableData.USB.find((d) => d.name === value);
for (let i = 0; i < table.rows.length; i++) {
const category = table.rows[i].cells[0];
const row = table.rows[i];
const cell = row.cells[colIndex];
for (let j = 0; j < Object.keys(item).length; j++) {
if (category.textContent === Object.keys(item)[j]) {
const text = item[Object.keys(item)[j]];
cell.textContent = item[Object.keys(item)[j]];
}
}
}
}