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.

132 lines
4.9 KiB

  1. /*
  2. * Copyright (c) 2013, 2020, 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. function loadScripts(doc, tag) {
  31. createElem(doc, tag, 'search.js');
  32. createElem(doc, tag, 'module-search-index.js');
  33. createElem(doc, tag, 'package-search-index.js');
  34. createElem(doc, tag, 'type-search-index.js');
  35. createElem(doc, tag, 'member-search-index.js');
  36. createElem(doc, tag, 'tag-search-index.js');
  37. }
  38. function createElem(doc, tag, path) {
  39. var script = doc.createElement(tag);
  40. var scriptElement = doc.getElementsByTagName(tag)[0];
  41. script.src = pathtoroot + path;
  42. scriptElement.parentNode.insertBefore(script, scriptElement);
  43. }
  44. function show(tableId, selected, columns) {
  45. if (tableId !== selected) {
  46. document.querySelectorAll('div.' + tableId + ':not(.' + selected + ')')
  47. .forEach(function(elem) {
  48. elem.style.display = 'none';
  49. });
  50. }
  51. document.querySelectorAll('div.' + selected)
  52. .forEach(function(elem, index) {
  53. elem.style.display = '';
  54. var isEvenRow = index % (columns * 2) < columns;
  55. elem.classList.remove(isEvenRow ? oddRowColor : evenRowColor);
  56. elem.classList.add(isEvenRow ? evenRowColor : oddRowColor);
  57. });
  58. updateTabs(tableId, selected);
  59. }
  60. function updateTabs(tableId, selected) {
  61. document.querySelector('div#' + tableId +' .summary-table')
  62. .setAttribute('aria-labelledby', selected);
  63. document.querySelectorAll('button[id^="' + tableId + '"]')
  64. .forEach(function(tab, index) {
  65. if (selected === tab.id || (tableId === selected && index === 0)) {
  66. tab.className = activeTableTab;
  67. tab.setAttribute('aria-selected', true);
  68. tab.setAttribute('tabindex',0);
  69. } else {
  70. tab.className = tableTab;
  71. tab.setAttribute('aria-selected', false);
  72. tab.setAttribute('tabindex',-1);
  73. }
  74. });
  75. }
  76. function switchTab(e) {
  77. var selected = document.querySelector('[aria-selected=true]');
  78. if (selected) {
  79. if ((e.keyCode === 37 || e.keyCode === 38) && selected.previousSibling) {
  80. // left or up arrow key pressed: move focus to previous tab
  81. selected.previousSibling.click();
  82. selected.previousSibling.focus();
  83. e.preventDefault();
  84. } else if ((e.keyCode === 39 || e.keyCode === 40) && selected.nextSibling) {
  85. // right or down arrow key pressed: move focus to next tab
  86. selected.nextSibling.click();
  87. selected.nextSibling.focus();
  88. e.preventDefault();
  89. }
  90. }
  91. }
  92. var updateSearchResults = function() {};
  93. function indexFilesLoaded() {
  94. return moduleSearchIndex
  95. && packageSearchIndex
  96. && typeSearchIndex
  97. && memberSearchIndex
  98. && tagSearchIndex;
  99. }
  100. // Workaround for scroll position not being included in browser history (8249133)
  101. document.addEventListener("DOMContentLoaded", function(e) {
  102. var contentDiv = document.querySelector("div.flex-content");
  103. window.addEventListener("popstate", function(e) {
  104. if (e.state !== null) {
  105. contentDiv.scrollTop = e.state;
  106. }
  107. });
  108. window.addEventListener("hashchange", function(e) {
  109. history.replaceState(contentDiv.scrollTop, document.title);
  110. });
  111. contentDiv.addEventListener("scroll", function(e) {
  112. var timeoutID;
  113. if (!timeoutID) {
  114. timeoutID = setTimeout(function() {
  115. history.replaceState(contentDiv.scrollTop, document.title);
  116. timeoutID = null;
  117. }, 100);
  118. }
  119. });
  120. if (!location.hash) {
  121. history.replaceState(contentDiv.scrollTop, document.title);
  122. }
  123. });