مقالات

لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است و ...
لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ و با استفاده از طراحان گرافیک است. چاپگرها و متون بلکه روزنامه و مجله در ستون و سطرآنچنان که لازم است و...
/* Accordion for headings inside .post-content - targets h2 and h3 (adjust selector if لازم باشه) - wraps all nodes between this heading and next heading (H1-H6) - supports keyboard (Enter/Space) - supports dynamic loaded content via MutationObserver */ (function(){ console.log("26 kir"); function slideDown(el, duration = 280) { el.style.removeProperty('display'); let display = window.getComputedStyle(el).display; if (display === 'none') display = 'block'; el.style.display = display; const height = el.scrollHeight; el.style.overflow = 'hidden'; el.style.height = '0px'; el.style.transition = `height ${duration}ms ease`; // force reflow el.getBoundingClientRect(); el.style.height = height + 'px'; window.setTimeout(function() { el.style.removeProperty('height'); el.style.removeProperty('overflow'); el.style.removeProperty('transition'); }, duration); } function slideUp(el, duration = 280) { el.style.height = el.scrollHeight + 'px'; el.style.overflow = 'hidden'; el.style.transition = `height ${duration}ms ease`; el.getBoundingClientRect(); el.style.height = '0px'; window.setTimeout(function() { el.style.display = 'none'; el.style.removeProperty('height'); el.style.removeProperty('overflow'); el.style.removeProperty('transition'); }, duration); } // get nodes between heading and next heading (stop on any H1-H6) function getSectionNodes(startHeading) { const nodes = []; let next = startHeading.nextElementSibling; while (next && !/^H[1-6]$/i.test(next.tagName)) { nodes.push(next); next = next.nextElementSibling; } return nodes; } // wrap nodes into a div.heading-section-wrapper function wrapNodes(nodes) { if (!nodes.length) return null; const wrapper = document.createElement('div'); wrapper.className = 'heading-section-wrapper'; wrapper.style.display = 'none'; // hidden by default nodes[0].parentNode.insertBefore(wrapper, nodes[0]); nodes.forEach(n => wrapper.appendChild(n)); return wrapper; } // initialize a single .post-content container function initContainer(container) { if (!container || container.dataset.accordionInit === '1') return; container.dataset.accordionInit = '1'; // select headings you want (here h2 and h3). اگر نیاز به h4/h5 داری اضافه کن const headings = Array.from(container.querySelectorAll('h2, h3')); headings.forEach(h => { // make heading focusable and accessible h.setAttribute('tabindex', '0'); h.setAttribute('role', 'button'); h.setAttribute('aria-expanded', 'false'); // if the next element is already a wrapper, skip (prevents double-wrap) const nextEl = h.nextElementSibling; if (nextEl && nextEl.classList && nextEl.classList.contains('heading-section-wrapper')) { return; } // collect and wrap nodes between this heading and the next heading const nodes = getSectionNodes(h); const wrapper = wrapNodes(nodes); // may be null if no nodes between headings // attach handlers only if wrapper exists (if no content between headings nothing to toggle) if (wrapper) { h.addEventListener('click', function() { const isOpen = h.classList.contains('active'); if (isOpen) { h.classList.remove('active'); h.setAttribute('aria-expanded', 'false'); slideUp(wrapper); } else { h.classList.add('active'); h.setAttribute('aria-expanded', 'true'); slideDown(wrapper); } }); // keyboard support h.addEventListener('keydown', function(e){ if (e.key === 'Enter' || e.key === ' ' || e.key === 'Spacebar') { e.preventDefault(); h.click(); } }); } }); } // init all containers on the page function initAll() { const containers = document.querySelectorAll('.post-content'); containers.forEach(initContainer); } // run on DOM ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initAll); } else { initAll(); } // observe DOM changes (useful for infinite scroll / AJAX loading) const observer = new MutationObserver(function(mutations) { for (const m of mutations) { if (m.addedNodes && m.addedNodes.length) { // small timeout to allow Elementor to render inserted nodes setTimeout(initAll, 120); break; } } }); observer.observe(document.body, { childList: true, subtree: true }); })();