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
3.9 KiB

3 years ago
  1. /*
  2. * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
  3. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. *
  5. *
  6. *
  7. *
  8. *
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *
  15. *
  16. *
  17. *
  18. *
  19. *
  20. *
  21. *
  22. *
  23. *
  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. });