1/** 2 * Turns the <h3> sections inside the product Description tab into an accordion. 3 * Intro content (before the first <h3>) stays visible; each <h3> + the content 4 * that follows it (until the next <h3>) becomes a collapsible item. 5 */ 6(function () { 7 'use strict'; 8 9 function buildAccordion(panel) { 10 var headings = Array.prototype.slice.call(panel.children).filter(function (el) { 11 return el.tagName === 'H3'; 12 }); 13 if (!headings.length) return; 14 15 headings.forEach(function (h3) { 16 var item = document.createElement('div'); 17 item.className = 'pb-acc-item'; 18 19 var body = document.createElement('div'); 20 body.className = 'pb-acc-body'; 21 22 // Move everything after this h3 (until the next h3) into the body. 23 var node = h3.nextSibling; 24 while (node && !(node.nodeType === 1 && node.tagName === 'H3')) { 25 var next = node.nextSibling; 26 body.appendChild(node); 27 node = next; 28 } 29 30 var btn = document.createElement('button'); 31 btn.type = 'button'; 32 btn.className = 'pb-acc-header'; 33 btn.setAttribute('aria-expanded', 'false'); 34 btn.innerHTML = '<span class="pb-acc-title">' + h3.innerHTML + '</span><span class="pb-acc-icon" aria-hidden="true"></span>'; 35 36 h3.parentNode.insertBefore(item, h3); 37 item.appendChild(btn); 38 item.appendChild(body); 39 h3.parentNode.removeChild(h3); 40 41 btn.addEventListener('click', function () { 42 var open = item.classList.toggle('open'); 43 btn.setAttribute('aria-expanded', open ? 'true' : 'false'); 44 }); 45 }); 46 47 panel.classList.add('pb-acc-ready'); 48 } 49 50 function init() { 51 var panel = document.querySelector('#tab-description, .woocommerce-Tabs-panel--description'); 52 if (panel && !panel.classList.contains('pb-acc-ready')) { 53 buildAccordion(panel); 54 } 55 } 56 57 if (document.readyState === 'loading') { 58 document.addEventListener('DOMContentLoaded', init); 59 } else { 60 init(); 61 } 62})();
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.