-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
266 lines (252 loc) · 8.84 KB
/
script.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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
var moduleSearchIndex;
var packageSearchIndex;
var typeSearchIndex;
var memberSearchIndex;
var tagSearchIndex;
var oddRowColor = "odd-row-color";
var evenRowColor = "even-row-color";
var sortAsc = "sort-asc";
var sortDesc = "sort-desc";
var tableTab = "table-tab";
var activeTableTab = "active-table-tab";
function loadScripts(doc, tag) {
createElem(doc, tag, 'search.js');
createElem(doc, tag, 'module-search-index.js');
createElem(doc, tag, 'package-search-index.js');
createElem(doc, tag, 'type-search-index.js');
createElem(doc, tag, 'member-search-index.js');
createElem(doc, tag, 'tag-search-index.js');
}
function createElem(doc, tag, path) {
var script = doc.createElement(tag);
var scriptElement = doc.getElementsByTagName(tag)[0];
script.src = pathtoroot + path;
scriptElement.parentNode.insertBefore(script, scriptElement);
}
// Helper for making content containing release names comparable lexicographically
function makeComparable(s) {
return s.toLowerCase().replace(/(\d+)/g,
function(n, m) {
return ("000" + m).slice(-4);
});
}
// Switches between two styles depending on a condition
function toggleStyle(classList, condition, trueStyle, falseStyle) {
if (condition) {
classList.remove(falseStyle);
classList.add(trueStyle);
} else {
classList.remove(trueStyle);
classList.add(falseStyle);
}
}
// Sorts the rows in a table lexicographically by the content of a specific column
function sortTable(header, columnIndex, columns) {
var container = header.parentElement;
var descending = header.classList.contains(sortAsc);
container.querySelectorAll("div.table-header").forEach(
function(header) {
header.classList.remove(sortAsc);
header.classList.remove(sortDesc);
}
)
var cells = container.children;
var rows = [];
for (var i = columns; i < cells.length; i += columns) {
rows.push(Array.prototype.slice.call(cells, i, i + columns));
}
var comparator = function(a, b) {
var ka = makeComparable(a[columnIndex].textContent);
var kb = makeComparable(b[columnIndex].textContent);
if (ka < kb)
return descending ? 1 : -1;
if (ka > kb)
return descending ? -1 : 1;
return 0;
};
var sorted = rows.sort(comparator);
var visible = 0;
sorted.forEach(function(row) {
if (row[0].style.display !== 'none') {
var isEvenRow = visible++ % 2 === 0;
}
row.forEach(function(cell) {
toggleStyle(cell.classList, isEvenRow, evenRowColor, oddRowColor);
container.appendChild(cell);
})
});
toggleStyle(header.classList, descending, sortDesc, sortAsc);
}
// Toggles the visibility of a table category in all tables in a page
function toggleGlobal(checkbox, selected, columns) {
var display = checkbox.checked ? '' : 'none';
document.querySelectorAll("div.table-tabs").forEach(function(t) {
var id = t.parentElement.getAttribute("id");
var selectedClass = id + "-tab" + selected;
// if selected is empty string it selects all uncategorized entries
var selectUncategorized = !Boolean(selected);
var visible = 0;
document.querySelectorAll('div.' + id)
.forEach(function(elem) {
if (selectUncategorized) {
if (elem.className.indexOf(selectedClass) === -1) {
elem.style.display = display;
}
} else if (elem.classList.contains(selectedClass)) {
elem.style.display = display;
}
if (elem.style.display === '') {
var isEvenRow = visible++ % (columns * 2) < columns;
toggleStyle(elem.classList, isEvenRow, evenRowColor, oddRowColor);
}
});
t.parentElement.style.display = visible === 0 ? 'none' : '';
})
}
// Shows the elements of a table belonging to a specific category
function show(tableId, selected, columns) {
if (tableId !== selected) {
document.querySelectorAll('div.' + tableId + ':not(.' + selected + ')')
.forEach(function(elem) {
elem.style.display = 'none';
});
}
document.querySelectorAll('div.' + selected)
.forEach(function(elem, index) {
elem.style.display = '';
var isEvenRow = index % (columns * 2) < columns;
toggleStyle(elem.classList, isEvenRow, evenRowColor, oddRowColor);
});
updateTabs(tableId, selected);
}
function updateTabs(tableId, selected) {
document.querySelector('div#' + tableId +' .summary-table')
.setAttribute('aria-labelledby', selected);
document.querySelectorAll('button[id^="' + tableId + '"]')
.forEach(function(tab, index) {
if (selected === tab.id || (tableId === selected && index === 0)) {
tab.className = activeTableTab;
tab.setAttribute('aria-selected', true);
tab.setAttribute('tabindex',0);
} else {
tab.className = tableTab;
tab.setAttribute('aria-selected', false);
tab.setAttribute('tabindex',-1);
}
});
}
function switchTab(e) {
var selected = document.querySelector('[aria-selected=true]');
if (selected) {
if ((e.keyCode === 37 || e.keyCode === 38) && selected.previousSibling) {
// left or up arrow key pressed: move focus to previous tab
selected.previousSibling.click();
selected.previousSibling.focus();
e.preventDefault();
} else if ((e.keyCode === 39 || e.keyCode === 40) && selected.nextSibling) {
// right or down arrow key pressed: move focus to next tab
selected.nextSibling.click();
selected.nextSibling.focus();
e.preventDefault();
}
}
}
var updateSearchResults = function() {};
function indexFilesLoaded() {
return moduleSearchIndex
&& packageSearchIndex
&& typeSearchIndex
&& memberSearchIndex
&& tagSearchIndex;
}
// Copy the contents of the local snippet to the clipboard
function copySnippet(button) {
copyToClipboard(button.nextElementSibling.innerText);
switchCopyLabel(button.firstElementChild, button.parentElement);
}
// Copy the link to the adjacent header to the clipboard
function copyUrl(button) {
var id;
var header = button.parentElement;
if (header.hasAttribute("id")) {
id = header.getAttribute("id");
} else if (header.parentElement.tagName === 'SECTION' && header.parentElement.hasAttribute("id")) {
id = header.parentElement.getAttribute("id");
} else if (header.firstElementChild && header.firstElementChild.tagName === "A"
&& header.firstElementChild.hasAttribute("id")) {
id = header.firstElementChild.getAttribute("id");
}
var url = document.location.href;
if (url.indexOf("#") > -1) {
url = url.substring(0, url.indexOf("#"));
}
copyToClipboard(url + "#" + id);
switchCopyLabel(button.lastElementChild, button.parentElement);
}
function copyToClipboard(content) {
var textarea = document.createElement("textarea");
textarea.style.height = 0;
document.body.appendChild(textarea);
textarea.value = content;
textarea.select();
document.execCommand("copy");
document.body.removeChild(textarea);
}
function switchCopyLabel(span, parent) {
var copied = span.getAttribute("data-copied");
if (span.innerHTML !== copied) {
var initialLabel = span.innerHTML;
span.innerHTML = copied;
parent.onmouseleave = parent.ontouchend = function() {
span.innerHTML = initialLabel;
};
}
}
// Workaround for scroll position not being included in browser history (8249133)
document.addEventListener("DOMContentLoaded", function(e) {
var contentDiv = document.querySelector("div.flex-content");
window.addEventListener("popstate", function(e) {
if (e.state !== null) {
contentDiv.scrollTop = e.state;
}
});
window.addEventListener("hashchange", function(e) {
history.replaceState(contentDiv.scrollTop, document.title);
});
var timeoutId;
contentDiv.addEventListener("scroll", function(e) {
if (timeoutId) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(function() {
history.replaceState(contentDiv.scrollTop, document.title);
}, 100);
});
if (!location.hash) {
history.replaceState(contentDiv.scrollTop, document.title);
}
});