/* This script makes tabs for
. Example code for .md file:
It's a test It's a test It's a test It's a test It's a test It's a test ```bash Test 1! Test 1! Test 1! ```
```bash Test 2! Test 2! Test 2! Test 2! Test 2! Test 2! Test 2! Test 2!Test 2! Test 2! Test 2! ```
*/ function escapeHTML(str) { return str.replace(/[&<>"']/g, function (char) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char]; }); } function openCodeTab(id, event) { const tabObj = document.querySelector(`${'#' + id}`); const anchorObj = document.querySelector(`${'#' + id + '-anchor'}`); // hide all tabs const divs = tabObj.parentNode.querySelectorAll("[data-name]") divs.forEach(div => div.style.display = 'none') // show only selected tab tabObj.style.display = 'block'; // un-activate all const anchors = [...anchorObj.parentNode.children].filter((child) => child !== anchorObj); anchors.forEach(anchor => anchor.classList.remove('active')) // make anchor active anchorObj.classList.add('active'); if (event) { event.preventDefault(); event.stopPropagation(); //window.location.hash = id; } } (function() { const tabs = document.querySelectorAll('.code-tabs'); tabs.forEach(function (codeTab, o1) { var buttons = '
'; const panels = codeTab.querySelectorAll("[data-name]"); panels.forEach(function (tab, o2) { const name = tab.dataset.name; const id = 'code-tab-' + o1 + '-' + o2; tab.setAttribute("id", id); buttons += '' + escapeHTML(name) + ''; }) buttons += '
'; codeTab.insertAdjacentHTML("afterBegin", buttons); openCodeTab('code-tab-' + o1 + '-0', null); }) })();