PageSourceSearch

https://wpamelia.com/wp-content/themes/amelia-theme/amelia-blocks/assets/js/docs-sidebar2.js?ver=1790908102

js wpamelia.com collected 2026-10-02 02:28:57 UTC 6,608 bytes, 152 lines download raw bytes

1// Wait for DOM and ensure jQuery is available
2function initDocsSidebar() {
3    
4    // Category toggle - consistent with working pattern
5    const categories = document.querySelectorAll('.docs-sidebar2__category');
6    categories.forEach((category, index) => {
7        const title = category.querySelector('.docs-sidebar2__category-title');
8        const pages = category.querySelectorAll('.docs-sidebar2__page, .docs-sidebar2__subpage');
9
10        if (!title) return;
11
12        // Remove any existing listeners to prevent duplicates
13        title.replaceWith(title.cloneNode(true));
14        const newTitle = category.querySelector('.docs-sidebar2__category-title');
15
16        // Toggle category dropdown - same pattern that works
17        newTitle.addEventListener('click', function(e) {
18            e.preventDefault();
19            e.stopPropagation();
20            category.classList.toggle('is-open');
21        });
22
23        // Auto-open category if it contains active page/sub-page OR active dropdown item
24        pages.forEach(page => {
25            if (page.classList.contains('is-active')) {
26                category.classList.add('is-open');
27                if (page.classList.contains('docs-sidebar2__subpage')) {
28                    const parentPage = page.closest('.docs-sidebar2__page');
29                    if (parentPage) parentPage.classList.add('is-open');
30                }
31            }
32        });
33
34        // Check if current page is a dropdown item in this category
35        const dropdownItems = category.querySelectorAll('.docs-sidebar2__dropdown-item');
36        dropdownItems.forEach(dropdownItem => {
37            if (dropdownItem.classList.contains('is-active')) {
38                category.classList.add('is-open');
39                // Also open the parent dropdown page
40                const parentDropdownPage = dropdownItem.closest('.docs-sidebar2__page.has-dropdown');
41                if (parentDropdownPage) {
42                    parentDropdownPage.classList.add('is-open');
43                    parentDropdownPage.classList.add('has-active-item');
44                }
45            }
46        });
47
48        // Also check by URL matching for dropdown items
49        dropdownItems.forEach(dropdownItem => {
50            const link = dropdownItem.querySelector('a');
51            if (link && (window.location.href === link.href || window.location.pathname === new URL(link.href, window.location.origin).pathname)) {
52                category.classList.add('is-open');
53                const parentDropdownPage = dropdownItem.closest('.docs-sidebar2__page.has-dropdown');
54                if (parentDropdownPage) {
55                    parentDropdownPage.classList.add('is-open');
56                    parentDropdownPage.classList.add('has-active-item');
57                }
58            }
59        });
60    });
61
62    // Page dropdown toggle - use SAME pattern as categories (include both pages and subpages)
63    const dropdownPages = document.querySelectorAll('.docs-sidebar2__page.has-dropdown, .docs-sidebar2__subpage.has-dropdown');
64    
65    dropdownPages.forEach((page, index) => {
66        const dropdownToggle = page.querySelector('.docs-sidebar2__page-dropdown-toggle');
67        const dropdownItems = page.querySelector('.docs-sidebar2__dropdown-items');
68        const pageLink = page.querySelector('a');
69        
70        if (!dropdownToggle || !dropdownItems) return;
71
72        // Remove existing listeners to prevent conflicts
73        if (dropdownToggle) {
74            dropdownToggle.replaceWith(dropdownToggle.cloneNode(true));
75            const newToggle = page.querySelector('.docs-sidebar2__page-dropdown-toggle');
76            
77            // Use the SAME pattern as categories - click toggle to open/close
78            newToggle.addEventListener('click', function(e) {
79                // If clicking directly on the link (a tag), allow normal navigation
80                if (e.target.tagName === 'A' || e.target.closest('a')) {
81                    // Only prevent dropdown toggle if link has href and isn't just '#'
82                    const link = e.target.tagName === 'A' ? e.target : e.target.closest('a');
83                    if (link && link.href && link.href !== window.location.href + '#' && !link.href.endsWith('#')) {
84                        return; // Let the link work normally
85                    }
86                }
87                
88                // Otherwise toggle the dropdown
89                e.preventDefault();
90                e.stopPropagation();
91                page.classList.toggle('is-open');
92            });
93        }
94
95        // Auto-open logic for page dropdowns
96        const activeDropdownItem = dropdownItems.querySelector('.docs-sidebar2__dropdown-item.is-active');
97        
98        // Auto-open if dropdown item is active
99        if (activeDropdownItem) {
100            page.classList.add('has-active-item');
101            page.classList.add('is-open');
102        }
103
104        // Auto-open if the page itself is active (has is-active class)
105        if (page.classList.contains('is-active')) {
106            page.classList.add('is-open');
107        }
108        
109        // Also check if pageLink has is-active class (backup)
110        if (pageLink && pageLink.classList.contains('is-active')) {
111            page.classList.add('is-open');
112        }
113        
114        // URL matching for main dropdown page
115        if (pageLink && (window.location.href === pageLink.href || window.location.pathname === new URL(pageLink.href, window.location.origin).pathname)) {
116            page.classList.add('is-open');
117        }
118    });
119
120    // Legacy sub-pages support (non-dropdown)
121    const parentPages = document.querySelectorAll('.docs-sidebar2__page:not(.has-dropdown)');
122    parentPages.forEach(page => {
123        const subList = page.querySelector('.docs-sidebar2__subpages');
124        if (!subList) return;
125
126        const link = page.querySelector('a');
127        if (link) {
128            link.addEventListener('click', function(e) {
129                e.preventDefault();
130                page.classList.toggle('is-open');
131            });
132        }
133
134        // Auto-open if sub-page is active
135        const subActive = subList.querySelector('.docs-sidebar2__subpage.is-active');
136        if (subActive) {
137            page.classList.add('is-open');
138        }
139    });
140}
141
142// Initialize when DOM is ready
143if (document.readyState === 'loading') {
144    document.addEventListener('DOMContentLoaded', initDocsSidebar);
145} else {
146    initDocsSidebar();
147}
148
149// Also initialize when page is fully loaded (for dynamic content)
150window.addEventListener('load', function() {
151    setTimeout(initDocsSidebar, 100);
152});

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.