|
|
| (একই ব্যবহারকারী দ্বারা সম্পাদিত ৬টি মধ্যবর্তী সংশোধন দেখানো হচ্ছে না) |
| ১ নং লাইন: |
১ নং লাইন: |
| // MediaWiki Sticky Header Search Collapse
| | mw.loader.using(['mediawiki.api']).then(function () { |
| (function() { | | if (mw.config.get('wgCanonicalSpecialPageName') !== 'Upload') { |
| 'use strict';
| | return; |
|
| | } |
| function initSearchToggle() {
| | |
| // Find the search toggle button
| | var textarea = document.getElementById('wpUploadDescription'); |
| const searchToggle = document.querySelector('.vector-sticky-header-visible .search-toggle');
| | if (!textarea || textarea.value.trim() !== '') { |
| const searchBox = document.querySelector('.vector-sticky-header-visible .vector-search-box');
| | return; |
| const searchContainer = document.querySelector('.vector-sticky-header-visible .vector-typeahead-search-container');
| | } |
| const searchInput = document.querySelector('.vector-sticky-header-visible .cdx-text-input__input');
| | |
|
| | new mw.Api().get({ |
| if (!searchToggle || !searchBox || !searchContainer) return;
| | action: 'query', |
|
| | prop: 'revisions', |
| // Remove old event listeners by cloning
| | titles: 'Boipedia:Upload preload', |
| const newToggle = searchToggle.cloneNode(true);
| | rvslots: 'main', |
| searchToggle.parentNode.replaceChild(newToggle, searchToggle);
| | rvprop: 'content', |
|
| | formatversion: 2 |
| // Toggle search on icon click
| | }).then(function (data) { |
| newToggle.addEventListener('click', function(e) {
| | var page = data.query.pages[0]; |
| e.preventDefault();
| | |
| e.stopPropagation();
| | if (!page.missing && page.revisions) { |
|
| | textarea.value = page.revisions[0].slots.main.content.trim(); |
| searchContainer.classList.add('search-active');
| | } |
| newToggle.classList.add('search-hidden');
| | }); |
|
| | }); |
| // Focus the input
| |
| if (searchInput) {
| |
| setTimeout(function() {
| |
| searchInput.focus();
| |
| }, 50);
| |
| }
| |
| });
| |
|
| |
| // Close when clicking outside
| |
| document.addEventListener('click', function(e) {
| |
| if (!searchBox.contains(e.target)) {
| |
| searchContainer.classList.remove('search-active');
| |
| newToggle.classList.remove('search-hidden');
| |
| }
| |
| });
| |
|
| |
| // Prevent closing when clicking inside search
| |
| searchContainer.addEventListener('click', function(e) {
| |
| e.stopPropagation();
| |
| });
| |
| }
| |
|
| |
| // Run when page loads
| |
| if (document.readyState === 'loading') {
| |
| document.addEventListener('DOMContentLoaded', function() {
| |
| setTimeout(initSearchToggle, 500);
| |
| });
| |
| } else {
| |
| setTimeout(initSearchToggle, 500);
| |
| }
| |
|
| |
| // Re-run when sticky header appears (when scrolling)
| |
| let scrollTimeout;
| |
| window.addEventListener('scroll', function() {
| |
| clearTimeout(scrollTimeout);
| |
| scrollTimeout = setTimeout(initSearchToggle, 100);
| |
| });
| |
|
| |
| // Also observe for class changes on body
| |
| const observer = new MutationObserver(function() {
| |
| initSearchToggle();
| |
| });
| |
|
| |
| const body = document.querySelector('body');
| |
| if (body) {
| |
| observer.observe(body, {
| |
| attributes: true,
| |
| attributeFilter: ['class']
| |
| });
| |
| }
| |
| })();
| |