You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
9.8 KiB

  1. /*
  2. * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation. Oracle designates this
  8. * particular file as subject to the "Classpath" exception as provided
  9. * by Oracle in the LICENSE file that accompanied this code.
  10. *
  11. * This code is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * version 2 for more details (a copy is included in the LICENSE file that
  15. * accompanied this code).
  16. *
  17. * You should have received a copy of the GNU General Public License version
  18. * 2 along with this work; if not, write to the Free Software Foundation,
  19. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22. * or visit www.oracle.com if you need additional information or have any
  23. * questions.
  24. */
  25. var moduleSearchIndex;
  26. var packageSearchIndex;
  27. var typeSearchIndex;
  28. var memberSearchIndex;
  29. var tagSearchIndex;
  30. var oddRowColor = "odd-row-color";
  31. var evenRowColor = "even-row-color";
  32. var sortAsc = "sort-asc";
  33. var sortDesc = "sort-desc";
  34. var tableTab = "table-tab";
  35. var activeTableTab = "active-table-tab";
  36. function loadScripts(doc, tag) {
  37. createElem(doc, tag, 'search.js');
  38. createElem(doc, tag, 'module-search-index.js');
  39. createElem(doc, tag, 'package-search-index.js');
  40. createElem(doc, tag, 'type-search-index.js');
  41. createElem(doc, tag, 'member-search-index.js');
  42. createElem(doc, tag, 'tag-search-index.js');
  43. }
  44. function createElem(doc, tag, path) {
  45. var script = doc.createElement(tag);
  46. var scriptElement = doc.getElementsByTagName(tag)[0];
  47. script.src = pathtoroot + path;
  48. scriptElement.parentNode.insertBefore(script, scriptElement);
  49. }
  50. // Helper for making content containing release names comparable lexicographically
  51. function makeComparable(s) {
  52. return s.toLowerCase().replace(/(\d+)/g,
  53. function(n, m) {
  54. return ("000" + m).slice(-4);
  55. });
  56. }
  57. // Switches between two styles depending on a condition
  58. function toggleStyle(classList, condition, trueStyle, falseStyle) {
  59. if (condition) {
  60. classList.remove(falseStyle);
  61. classList.add(trueStyle);
  62. } else {
  63. classList.remove(trueStyle);
  64. classList.add(falseStyle);
  65. }
  66. }
  67. // Sorts the rows in a table lexicographically by the content of a specific column
  68. function sortTable(header, columnIndex, columns) {
  69. var container = header.parentElement;
  70. var descending = header.classList.contains(sortAsc);
  71. container.querySelectorAll("div.table-header").forEach(
  72. function(header) {
  73. header.classList.remove(sortAsc);
  74. header.classList.remove(sortDesc);
  75. }
  76. )
  77. var cells = container.children;
  78. var rows = [];
  79. for (var i = columns; i < cells.length; i += columns) {
  80. rows.push(Array.prototype.slice.call(cells, i, i + columns));
  81. }
  82. var comparator = function(a, b) {
  83. var ka = makeComparable(a[columnIndex].textContent);
  84. var kb = makeComparable(b[columnIndex].textContent);
  85. if (ka < kb)
  86. return descending ? 1 : -1;
  87. if (ka > kb)
  88. return descending ? -1 : 1;
  89. return 0;
  90. };
  91. var sorted = rows.sort(comparator);
  92. var visible = 0;
  93. sorted.forEach(function(row) {
  94. if (row[0].style.display !== 'none') {
  95. var isEvenRow = visible++ % 2 === 0;
  96. }
  97. row.forEach(function(cell) {
  98. toggleStyle(cell.classList, isEvenRow, evenRowColor, oddRowColor);
  99. container.appendChild(cell);
  100. })
  101. });
  102. toggleStyle(header.classList, descending, sortDesc, sortAsc);
  103. }
  104. // Toggles the visibility of a table category in all tables in a page
  105. function toggleGlobal(checkbox, selected, columns) {
  106. var display = checkbox.checked ? '' : 'none';
  107. document.querySelectorAll("div.table-tabs").forEach(function(t) {
  108. var id = t.parentElement.getAttribute("id");
  109. var selectedClass = id + "-tab" + selected;
  110. // if selected is empty string it selects all uncategorized entries
  111. var selectUncategorized = !Boolean(selected);
  112. var visible = 0;
  113. document.querySelectorAll('div.' + id)
  114. .forEach(function(elem) {
  115. if (selectUncategorized) {
  116. if (elem.className.indexOf(selectedClass) === -1) {
  117. elem.style.display = display;
  118. }
  119. } else if (elem.classList.contains(selectedClass)) {
  120. elem.style.display = display;
  121. }
  122. if (elem.style.display === '') {
  123. var isEvenRow = visible++ % (columns * 2) < columns;
  124. toggleStyle(elem.classList, isEvenRow, evenRowColor, oddRowColor);
  125. }
  126. });
  127. t.parentElement.style.display = visible === 0 ? 'none' : '';
  128. })
  129. }
  130. // Shows the elements of a table belonging to a specific category
  131. function show(tableId, selected, columns) {
  132. if (tableId !== selected) {
  133. document.querySelectorAll('div.' + tableId + ':not(.' + selected + ')')
  134. .forEach(function(elem) {
  135. elem.style.display = 'none';
  136. });
  137. }
  138. document.querySelectorAll('div.' + selected)
  139. .forEach(function(elem, index) {
  140. elem.style.display = '';
  141. var isEvenRow = index % (columns * 2) < columns;
  142. toggleStyle(elem.classList, isEvenRow, evenRowColor, oddRowColor);
  143. });
  144. updateTabs(tableId, selected);
  145. }
  146. function updateTabs(tableId, selected) {
  147. document.querySelector('div#' + tableId +' .summary-table')
  148. .setAttribute('aria-labelledby', selected);
  149. document.querySelectorAll('button[id^="' + tableId + '"]')
  150. .forEach(function(tab, index) {
  151. if (selected === tab.id || (tableId === selected && index === 0)) {
  152. tab.className = activeTableTab;
  153. tab.setAttribute('aria-selected', true);
  154. tab.setAttribute('tabindex',0);
  155. } else {
  156. tab.className = tableTab;
  157. tab.setAttribute('aria-selected', false);
  158. tab.setAttribute('tabindex',-1);
  159. }
  160. });
  161. }
  162. function switchTab(e) {
  163. var selected = document.querySelector('[aria-selected=true]');
  164. if (selected) {
  165. if ((e.keyCode === 37 || e.keyCode === 38) && selected.previousSibling) {
  166. // left or up arrow key pressed: move focus to previous tab
  167. selected.previousSibling.click();
  168. selected.previousSibling.focus();
  169. e.preventDefault();
  170. } else if ((e.keyCode === 39 || e.keyCode === 40) && selected.nextSibling) {
  171. // right or down arrow key pressed: move focus to next tab
  172. selected.nextSibling.click();
  173. selected.nextSibling.focus();
  174. e.preventDefault();
  175. }
  176. }
  177. }
  178. var updateSearchResults = function() {};
  179. function indexFilesLoaded() {
  180. return moduleSearchIndex
  181. && packageSearchIndex
  182. && typeSearchIndex
  183. && memberSearchIndex
  184. && tagSearchIndex;
  185. }
  186. // Copy the contents of the local snippet to the clipboard
  187. function copySnippet(button) {
  188. copyToClipboard(button.nextElementSibling.innerText);
  189. switchCopyLabel(button.firstElementChild, button.parentElement);
  190. }
  191. // Copy the link to the adjacent header to the clipboard
  192. function copyUrl(button) {
  193. var id;
  194. var header = button.parentElement;
  195. if (header.hasAttribute("id")) {
  196. id = header.getAttribute("id");
  197. } else if (header.parentElement.tagName === 'SECTION' && header.parentElement.hasAttribute("id")) {
  198. id = header.parentElement.getAttribute("id");
  199. } else if (header.firstElementChild && header.firstElementChild.tagName === "A"
  200. && header.firstElementChild.hasAttribute("id")) {
  201. id = header.firstElementChild.getAttribute("id");
  202. }
  203. var url = document.location.href;
  204. if (url.indexOf("#") > -1) {
  205. url = url.substring(0, url.indexOf("#"));
  206. }
  207. copyToClipboard(url + "#" + id);
  208. switchCopyLabel(button.lastElementChild, button.parentElement);
  209. }
  210. function copyToClipboard(content) {
  211. var textarea = document.createElement("textarea");
  212. textarea.style.height = 0;
  213. document.body.appendChild(textarea);
  214. textarea.value = content;
  215. textarea.select();
  216. document.execCommand("copy");
  217. document.body.removeChild(textarea);
  218. }
  219. function switchCopyLabel(span, parent) {
  220. var copied = span.getAttribute("data-copied");
  221. if (span.innerHTML !== copied) {
  222. var initialLabel = span.innerHTML;
  223. span.innerHTML = copied;
  224. parent.onmouseleave = parent.ontouchend = function() {
  225. span.innerHTML = initialLabel;
  226. };
  227. }
  228. }
  229. // Workaround for scroll position not being included in browser history (8249133)
  230. document.addEventListener("DOMContentLoaded", function(e) {
  231. var contentDiv = document.querySelector("div.flex-content");
  232. window.addEventListener("popstate", function(e) {
  233. if (e.state !== null) {
  234. contentDiv.scrollTop = e.state;
  235. }
  236. });
  237. window.addEventListener("hashchange", function(e) {
  238. history.replaceState(contentDiv.scrollTop, document.title);
  239. });
  240. var timeoutId;
  241. contentDiv.addEventListener("scroll", function(e) {
  242. if (timeoutId) {
  243. clearTimeout(timeoutId);
  244. }
  245. timeoutId = setTimeout(function() {
  246. history.replaceState(contentDiv.scrollTop, document.title);
  247. }, 100);
  248. });
  249. if (!location.hash) {
  250. history.replaceState(contentDiv.scrollTop, document.title);
  251. }
  252. });