-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoutliner.js
More file actions
229 lines (207 loc) · 7.63 KB
/
outliner.js
File metadata and controls
229 lines (207 loc) · 7.63 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
var IMG_EXPANDED = 'Expanded.png';
var IMG_COLLAPSED = 'Collapsed.png';
var IMG_BLANK = 'blank.png';
var IMG_LEAF = 'LeafRowHandle.png';
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}
function isVisible(obj)
{
if (obj == document)
return true;
if (!obj)
return false;
if (!obj.parentNode)
return false;
if (obj.style) {
if (obj.style.display == 'none')
return false;
if (obj.style.visibility == 'hidden')
return false;
}
//Try the computed style in a standard way
if (window.getComputedStyle) {
var style = window.getComputedStyle(obj, "");
if (style.display == 'none')
return false;
if (style.visibility == 'hidden')
return false;
}
//Or get the computed style using IE's silly proprietary way
var style = obj.currentStyle
if (style) {
if (style['display'] == 'none')
return false;
if (style['visibility'] == 'hidden')
return false;
}
return isVisible(obj.parentNode);
}
function updateRowBackgroundColors() {
// do not update row colors unless alternate row colors has been specified.
if (!(hasClass(document.body, "alt-row-colors")))
return;
var possibleRows = document.getElementsByClassName("whole-row");
var rowCount = 1;
for(var i = 0; i < possibleRows.length; i++) {
var element = possibleRows[i];
var elementNote = null;
if ((element.nextElementSibling != null) && (hasClass(element.nextElementSibling, "whole-note"))) {
elementNote = element.nextElementSibling;
}
if (rowCount % 2 == 0) {
addClass(element, "alt-row");
if (elementNote != null) {
addClass(elementNote, "alt-row");
}
}
rowCount++;
}
}
function setLastChildClass(rowSet) {
// This is used for setting "Below children" padding
var rows = [];
if (rowSet == null) {
rows = document.querySelectorAll("tr.outline-row, tr.note-row");
} else {
rows = rowSet;
}
$(rows).each(function() {
var element = $(this);
var siblingCount = $(element).siblings().length;
for (var i = 0; i < siblingCount; i++) {
// Get next visible sibling in the whole DOM
if ($(element).next()[0] != null) {
if ($(element).next().hasClass("visible")) {
// See if the next visible sibling is of a numerically lower data-level
if ($(element).next().attr("data-level") < $(this).attr("data-level")) {
$(this).addClass("last-child");
}
break;
} else {
element = $(element).next();
}
} else {
break;
}
}
});
}
function setWidths() {
var everyRow = document.querySelectorAll("table.whole-row, table.whole-note");
var previousLevel = 1;
var everyCellToModify = [];
for (var i = 0; i < everyRow.length; i++) {
// Set level 1 row widths
if (i == 0) {
everyCellToModify.pushArray(setWidthsForSectionLevel(everyRow[0]));
} else {
var nextRow = everyRow[i].nextElementSibling;
var thisDataLevel = everyRow[i].getAttribute("data-level");
// Set widths for all other row levels
if (thisDataLevel > previousLevel) {
everyCellToModify.pushArray(setWidthsForSectionLevel(everyRow[i]));
previousLevel = thisDataLevel;
} else if ((nextRow !== null) && (thisDataLevel < previousLevel)) {
// Should have already adjust this row but we need to check for children
previousLevel = thisDataLevel;
}
}
}
for (var i = 0; i < everyCellToModify.length; i++) {
everyCellToModify[i][0].style.width = (everyCellToModify[i][1] + "px");
if (everyCellToModify[i][1] > 1) {
removeClass(everyCellToModify[i][0], "empty");
}
}
}
function setWidthsForSectionLevel(startRow) {
var currentLevel = startRow.getAttribute("data-level");
var everyRowOfLevelInSection = [];
var everyLabelTdInSection = [];
var stillInSection = true;
var labelTd = startRow.querySelector("td.label");
everyLabelTdInSection.push(labelTd);
var styleOfLabelTd = window.getComputedStyle(labelTd, null);
everyRowOfLevelInSection.push(startRow);
var maxWidth = parseInt(styleOfLabelTd.getPropertyValue("width"));
var currentRow = startRow;
while (stillInSection == true) {
var nextRow = currentRow.nextElementSibling;
var thisDataLevel = (nextRow != null) ? Number(currentRow.nextElementSibling.getAttribute("data-level")) : null;
if (thisDataLevel == currentLevel) {
everyRowOfLevelInSection.push(nextRow);
labelTd = nextRow.querySelector("td.label");
everyLabelTdInSection.push(labelTd);
styleOfLabelTd = window.getComputedStyle(labelTd, null);
var width = parseInt(styleOfLabelTd.getPropertyValue("width"));
if (width > maxWidth) {
maxWidth = width;
}
} else if ((nextRow == null) || (thisDataLevel < currentLevel)) {
stillInSection = false;
}
currentRow = nextRow;
}
var cellsToModify = [];
for (var i = 0; i < everyLabelTdInSection.length; i++) {
cellsToModify.push([everyLabelTdInSection[i], maxWidth]);
}
return cellsToModify;
}
function setOutlineTitleInset() {
var headerRow = document.getElementById("header");
var firstRow = document.querySelector("table.whole-row");
var outlineTitleDiv = document.getElementById("outlineInset");
if (outlineTitleDiv != null) {
var firstRowOutlineCells = firstRow.querySelector("table.outline-column").getElementsByTagName("td");
var insetWidth = 0;
for (var i = 0; i < (firstRowOutlineCells.length - 1); i++) {
var width = parseInt(firstRowOutlineCells[i].offsetWidth);
insetWidth = insetWidth + width;
}
outlineTitleDiv.style.paddingLeft = (insetWidth + "px");
}
}
function ieScript() {
if ((!!navigator.userAgent.match(/Edge\/\d+/i)) || (!!navigator.userAgent.match(/Trident\/\d+/i))){
//Set the height of table rows for IE and Edge
var everyRow = document.querySelectorAll("table#outline > tbody > tr");
var everyRowHeight = [];
for (var i = 0; i < everyRow.length; i++) {
everyRowHeight.push(everyRow[i].offsetHeight);
}
for (var i = 0; i< everyRow.length; i++) {
everyRow[i].style.height = everyRowHeight[i] + "px";
}
}
}
function getNum(val) {
if (isNaN(val)) {
return 0;
}
return Number(val);
}
Array.prototype.pushArray = function() {
var toPush = this.concat.apply([], arguments);
for (var i = 0, len = toPush.length; i < len; ++i) {
this.push(toPush[i]);
}
};
function setup() {
setWidths(); // Run this before setting visiblity so all rows are visible at time of calculation
ieScript(); // This too
setOutlineTitleInset();
//setLastChildClass();
updateRowBackgroundColors();
}
window.onload = setup;