|
ট্যাগ: খালি করা পুনর্বহাল |
| (একই ব্যবহারকারী দ্বারা সম্পাদিত একটি মধ্যবর্তী সংশোধন দেখানো হচ্ছে না) |
| ১ নং লাইন: |
১ নং লাইন: |
| // MediaWiki Sticky Header Search Collapse
| | |
| (function() {
| |
| 'use strict';
| |
|
| |
| let isInitialized = false;
| |
|
| |
| function initSearchToggle() {
| |
| // Prevent multiple initializations
| |
| if (isInitialized) return;
| |
|
| |
| // Wait for sticky header to be visible
| |
| if (!document.querySelector('.vector-sticky-header-visible')) {
| |
| return;
| |
| }
| |
|
| |
| // Find the search toggle button
| |
| const searchToggle = document.querySelector('.vector-sticky-header-visible .search-toggle');
| |
| const searchBox = document.querySelector('.vector-sticky-header-visible .vector-search-box');
| |
| const searchContainer = document.querySelector('.vector-sticky-header-visible .vector-typeahead-search-container');
| |
| const searchInput = document.querySelector('.vector-sticky-header-visible .cdx-text-input__input');
| |
|
| |
| if (!searchToggle || !searchBox || !searchContainer) {
| |
| return;
| |
| }
| |
|
| |
| isInitialized = true;
| |
|
| |
| // Toggle search on icon click
| |
| searchToggle.addEventListener('click', function(e) {
| |
| e.preventDefault();
| |
| e.stopPropagation();
| |
|
| |
| console.log('Search toggle clicked');
| |
|
| |
| // Show search container and hide toggle
| |
| searchContainer.classList.add('search-active');
| |
| searchToggle.classList.add('search-hidden');
| |
|
| |
| // Focus the input
| |
| if (searchInput) {
| |
| setTimeout(function() {
| |
| searchInput.focus();
| |
| }, 100);
| |
| }
| |
| });
| |
|
| |
| // Close when clicking outside
| |
| function closeSearch(e) {
| |
| if (searchBox && !searchBox.contains(e.target)) {
| |
| searchContainer.classList.remove('search-active');
| |
| searchToggle.classList.remove('search-hidden');
| |
| }
| |
| }
| |
|
| |
| document.addEventListener('click', closeSearch);
| |
|
| |
| // Prevent closing when clicking inside search
| |
| searchContainer.addEventListener('click', function(e) {
| |
| e.stopPropagation();
| |
| });
| |
|
| |
| console.log('Search toggle initialized');
| |
| }
| |
|
| |
| // Run when page loads
| |
| function init() {
| |
| setTimeout(function() {
| |
| initSearchToggle();
| |
| }, 1000);
| |
| }
| |
|
| |
| if (document.readyState === 'loading') {
| |
| document.addEventListener('DOMContentLoaded', init);
| |
| } else {
| |
| init();
| |
| }
| |
|
| |
| // Re-run when sticky header appears (when scrolling)
| |
| let scrollTimeout;
| |
| window.addEventListener('scroll', function() {
| |
| clearTimeout(scrollTimeout);
| |
| scrollTimeout = setTimeout(function() {
| |
| if (!isInitialized) {
| |
| initSearchToggle();
| |
| }
| |
| }, 300);
| |
| });
| |
|
| |
| // Also observe for class changes on body
| |
| const observer = new MutationObserver(function(mutations) {
| |
| mutations.forEach(function(mutation) {
| |
| if (mutation.attributeName === 'class') {
| |
| const body = mutation.target;
| |
| if (body.classList.contains('vector-sticky-header-visible') && !isInitialized) {
| |
| setTimeout(initSearchToggle, 300);
| |
| }
| |
| }
| |
| });
| |
| });
| |
|
| |
| const body = document.querySelector('body');
| |
| if (body) {
| |
| observer.observe(body, {
| |
| attributes: true,
| |
| attributeFilter: ['class']
| |
| });
| |
| }
| |
| })();
| |