|
|
| (একই ব্যবহারকারী দ্বারা সম্পাদিত ৫টি মধ্যবর্তী সংশোধন দেখানো হচ্ছে না) |
| ১ নং লাইন: |
১ নং লাইন: |
| // MediaWiki Sticky Header Search Collapse
| | mw.loader.using(['mediawiki.api']).then(function () { |
| (function() { | | if (mw.config.get('wgCanonicalSpecialPageName') !== 'Upload') { |
| 'use strict';
| | return; |
|
| | } |
| let isInitialized = false;
| | |
|
| | var textarea = document.getElementById('wpUploadDescription'); |
| function initSearchToggle() {
| | if (!textarea || textarea.value.trim() !== '') { |
| // Prevent multiple initializations
| | return; |
| if (isInitialized) return;
| | } |
|
| | |
| // Wait for sticky header to be visible
| | new mw.Api().get({ |
| if (!document.querySelector('.vector-sticky-header-visible')) {
| | action: 'query', |
| return;
| | prop: 'revisions', |
| }
| | titles: 'Boipedia:Upload preload', |
|
| | rvslots: 'main', |
| // Find the search toggle button
| | rvprop: 'content', |
| const searchToggle = document.querySelector('.vector-sticky-header-visible .search-toggle');
| | formatversion: 2 |
| const searchBox = document.querySelector('.vector-sticky-header-visible .vector-search-box');
| | }).then(function (data) { |
| const searchContainer = document.querySelector('.vector-sticky-header-visible .vector-typeahead-search-container');
| | var page = data.query.pages[0]; |
| const searchInput = document.querySelector('.vector-sticky-header-visible .cdx-text-input__input');
| | |
|
| | if (!page.missing && page.revisions) { |
| if (!searchToggle || !searchBox || !searchContainer) {
| | textarea.value = page.revisions[0].slots.main.content.trim(); |
| 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']
| |
| });
| |
| }
| |
| })();
| |