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