বিষয়বস্তুতে চলুন
🎉 বইপিডিয়ার ১ বছর পূর্তি! · আমাদের ফেসবুক পেজ অনুসরণ করুন.

মিডিয়াউইকি:Common.js: সংশোধিত সংস্করণের মধ্যে পার্থক্য

বইপিডিয়া থেকে
সম্পাদনা সারাংশ নেই
ট্যাগ: পুনর্বহালকৃত
সম্পাদনা সারাংশ নেই
 
(একই ব্যবহারকারী দ্বারা সম্পাদিত ৪টি মধ্যবর্তী সংশোধন দেখানো হচ্ছে না)
১ নং লাইন: ১ নং লাইন:
// MediaWiki Sticky Header Search Collapse
mw.loader.using(['mediawiki.api']).then(function () {
(function() {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Upload') {
    'use strict';
return;
   
}
    let initialized = false;
 
   
var textarea = document.getElementById('wpUploadDescription');
    function setupSearchToggle() {
if (!textarea || textarea.value.trim() !== '') {
        // Check if already initialized or if sticky header is not visible
return;
        const stickyBody = document.body.classList.contains('vector-sticky-header-visible');
}
        if (!stickyBody || initialized) return;
 
       
new mw.Api().get({
        // Find elements
action: 'query',
        const searchBox = document.querySelector('.vector-sticky-header-visible #p-search');
prop: 'revisions',
        const searchContainer = document.querySelector('.vector-sticky-header-visible .vector-typeahead-search-container');
titles: 'Boipedia:Upload preload',
        const searchToggle = document.querySelector('.vector-sticky-header-visible .search-toggle');
rvslots: 'main',
       
rvprop: 'content',
        if (!searchBox || !searchContainer || !searchToggle) {
formatversion: 2
            console.log('Elements not found yet');
}).then(function (data) {
            return;
var page = data.query.pages[0];
        }
 
       
if (!page.missing && page.revisions) {
        console.log('Initializing search toggle');
textarea.value = page.revisions[0].slots.main.content.trim();
        initialized = true;
}
       
});
        // Create a clickable overlay div
});
        const overlay = document.createElement('div');
        overlay.style.cssText = 'position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 10; cursor: pointer;';
        overlay.className = 'search-icon-overlay';
       
        // Find the button container and add overlay
        const buttonContainer = searchToggle.parentElement;
        if (buttonContainer) {
            buttonContainer.style.position = 'relative';
            buttonContainer.appendChild(overlay);
        }
       
        // Click handler
        function expandSearch(e) {
            e.preventDefault();
            e.stopPropagation();
           
            console.log('Search icon clicked');
           
            searchBox.classList.add('search-expanded');
           
            // Focus input
            const input = searchContainer.querySelector('input[type="search"]');
            if (input) {
                setTimeout(function() {
                    input.focus();
                }, 100);
            }
        }
       
        // Add click to overlay
        overlay.addEventListener('click', expandSearch);
       
        // Also try original button
        searchToggle.addEventListener('click', expandSearch);
       
        // Click outside to close
        document.addEventListener('click', function(e) {
            if (!searchBox.contains(e.target) && !overlay.contains(e.target)) {
                searchBox.classList.remove('search-expanded');
            }
        });
       
        // Prevent clicks inside from closing
        searchBox.addEventListener('click', function(e) {
            e.stopPropagation();
        });
       
        console.log('Search toggle ready with overlay');
    }
   
    // Try to initialize on load
    function tryInit() {
        setTimeout(setupSearchToggle, 500);
        setTimeout(setupSearchToggle, 1000);
        setTimeout(setupSearchToggle, 2000);
    }
   
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', tryInit);
    } else {
        tryInit();
    }
   
    // Watch for scroll to reinitialize if needed
    let lastScroll = 0;
    window.addEventListener('scroll', function() {
        const currentScroll = window.pageYOffset;
        if (currentScroll > 100 && lastScroll <= 100) {
            setTimeout(function() {
                if (!initialized) setupSearchToggle();
            }, 500);
        }
        lastScroll = currentScroll;
    });
   
    // Watch for body class changes
    const observer = new MutationObserver(function(mutations) {
        for (let mutation of mutations) {
            if (mutation.attributeName === 'class') {
                if (document.body.classList.contains('vector-sticky-header-visible') && !initialized) {
                    setTimeout(setupSearchToggle, 500);
                }
                if (!document.body.classList.contains('vector-sticky-header-visible')) {
                    initialized = false;
                }
            }
        }
    });
   
    observer.observe(document.body, { attributes: true, attributeFilter: ['class'] });
   
})();

০৪:১৩, ২৭ জুন ২০২৬ তারিখে সম্পাদিত সর্বশেষ সংস্করণ

mw.loader.using(['mediawiki.api']).then(function () {
	if (mw.config.get('wgCanonicalSpecialPageName') !== 'Upload') {
		return;
	}

	var textarea = document.getElementById('wpUploadDescription');
	if (!textarea || textarea.value.trim() !== '') {
		return;
	}

	new mw.Api().get({
		action: 'query',
		prop: 'revisions',
		titles: 'Boipedia:Upload preload',
		rvslots: 'main',
		rvprop: 'content',
		formatversion: 2
	}).then(function (data) {
		var page = data.query.pages[0];

		if (!page.missing && page.revisions) {
			textarea.value = page.revisions[0].slots.main.content.trim();
		}
	});
});