1/** 2 * Change active tab of tabs. 3 * 4 * @param {Element} container 5 * @param {string} name 6 */ 7const changeTab = (container, name) => { 8 for (const child of container.children) { 9 if (!(child instanceof HTMLElement)) { 10 continue; 11 } 12 13 if (child.classList.contains('mdbook-tabs')) { 14 for (const tab of child.children) { 15 if (!(tab instanceof HTMLElement)) { 16 continue; 17 } 18 19 if (tab.dataset.tabname === name) { 20 tab.classList.add('active'); 21 } else { 22 tab.classList.remove('active'); 23 } 24 } 25 } else if (child.classList.contains('mdbook-tab-content')) { 26 if (child.dataset.tabname === name) { 27 child.classList.remove('hidden'); 28 } else { 29 child.classList.add('hidden'); 30 } 31 } 32 } 33}; 34 35document.addEventListener('DOMContentLoaded', () => { 36 const tabs = document.querySelectorAll('.mdbook-tab'); 37 for (const tab of tabs) { 38 tab.addEventListener('click', () => { 39 if (!(tab instanceof HTMLElement)) { 40 return; 41 } 42 43 if (!tab.parentElement || !tab.parentElement.parentElement) { 44 return; 45 } 46 47 const container = tab.parentElement.parentElement; 48 const name = tab.dataset.tabname; 49 const global = container.dataset.tabglobal; 50 51 changeTab(container, name); 52 53 if (global) { 54 localStorage.setItem(`mdbook-tabs-${global}`, name); 55 56 const globalContainers = document.querySelectorAll( 57 `.mdbook-tabs-container[data-tabglobal="${global}"]` 58 ); 59 for (const globalContainer of globalContainers) { 60 changeTab(globalContainer, name); 61 } 62 } 63 }); 64 } 65 66 const containers = document.querySelectorAll('.mdbook-tabs-container[data-tabglobal]'); 67 for (const container of containers) { 68 const global = container.dataset.tabglobal; 69 70 const name = localStorage.getItem(`mdbook-tabs-${global}`); 71 if (name && document.querySelector(`.mdbook-tab[data-tabname=${name}]`)) { 72 changeTab(container, name); 73 } 74 } 75});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.