-
Notifications
You must be signed in to change notification settings - Fork 1
/
spreadsheet.js
86 lines (73 loc) · 2.59 KB
/
spreadsheet.js
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
"use strict";
(function() {
var spreadsheetContainer = document.getElementById("spreadsheet-container");
spreadsheetContainer.addEventListener("click", function() {
if(spreadsheetContainer.classList &&
typeof spreadsheetContainer.classList.add === "function") {
spreadsheetContainer.classList.remove("spreadsheet-container-hide");
spreadsheetContainer.classList.add("spreadsheet-container-show");
} else {
spreadsheetContainer.className = "spreadsheet-container-show";
}
});
spreadsheetContainer.addEventListener("mouseleave", function() {
if(spreadsheetContainer.classList &&
typeof spreadsheetContainer.classList.remove === "function") {
spreadsheetContainer.classList.remove("spreadsheet-container-show");
spreadsheetContainer.classList.add("spreadsheet-container-hide");
} else {
spreadsheetContainer.className = "spreadsheet-container-hide";
}
});
var NUM_OF_COLS = 10;
var NUM_OF_ROWS = 16;
var COLS = "ABCDEFGHIJ";
var table = document.getElementById("spreadsheet");
var tr = document.createElement("tr");
var trResult;
var inputCell;
var td;
var row = 1;
var col = 0;
tr.appendChild(document.createElement("td"));
for(col = 0; col < NUM_OF_COLS; col++) {
td = document.createElement("td");
td.className = "cell-heading";
//td.classList.add("cell-heading");
td.innerText = COLS[col];
tr.appendChild(td);
}
spreadsheet.appendChild(tr);
trResult = document.createElement("tr");
td = document.createElement("td");
//td.classList.add("cell-result-heading");
td.className = "cell-result-heading";
td.innerText = "R";
trResult.appendChild(td);
for(col = 0; col < NUM_OF_COLS; col++) {
td = document.createElement("td");
td.className = "cell-result";
td.id = "R" + COLS[col];
//td.classList.add("cell-result");
td.innerText = "R" + COLS[col];
trResult.appendChild(td);
}
for(var row = 1; row < NUM_OF_ROWS; row++) {
tr = document.createElement("tr");
td = document.createElement("td");
//td.classList.add("cell-heading");
td.className = "cell-heading";
td.innerText = row;
tr.appendChild(td);
for(col = 0; col < NUM_OF_COLS; col++) {
td = document.createElement("td");
inputCell = document.createElement("input");
inputCell.id = COLS[col] + row;
inputCell.addEventListener("change", runCodeAndTestFunctions);
td.appendChild(inputCell);
tr.appendChild(td);
}
spreadsheet.appendChild(tr);
}
spreadsheet.appendChild(trResult);
})();