MediaWiki:Vector.js: Difference between revisions

From Forklift Certified Video Games
Jump to navigation Jump to search
Line 138: Line 138:


$(document).on('pfUploadComplete', function() {
$(document).on('pfUploadComplete', function() {
     // 1. Wait 1 second after the upload finishes
     // 1. Wait exactly 1 second after upload
     setTimeout(function() {
     setTimeout(function() {
         // Target the OOUI field you found in Inspect
         // 2. TARGET ONLY THIS FIELD: The Infobox Game image field
         var $field = $('.oo-ui-inputWidget-input');
        // Note: Page Forms uses underscores for spaces in template names
         var $field = $('input[name="Infobox_Game[image]"]');


         if ($field.length > 0 && $field.val() !== "") {
         if ($field.length > 0 && $field.val() !== "") {
              
             var el = $field[0];
             // 2. Temporarily unbind the Page Forms click event
 
             // This prevents the "Upload" popup from opening again
             // 3. THE CLICK: Simulate the hardware events to make it active
             var oldClick = $field.prop('onclick');
             // We use the raw element to ensure a deep browser click
             $field.prop('onclick', null);
             el.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
            el.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
             el.dispatchEvent(new MouseEvent('click', { bubbles: true }));


             // 3. Perform the ACTUAL CLICK you requested
             // 4. FOCUS: Place the cursor inside
            // This wakes up the field so the form sees the data
            var el = $field[0];
            el.click();
             $field.focus();
             $field.focus();


            // 4. Restore the original behavior after the click is done
             console.log("Surgical Sync: Clicked only the Game Cover field.");
            setTimeout(function() {
                $field.prop('onclick', oldClick);
            }, 100);
 
             console.log("Forced a one-time physical click into the field.");
         }
         }
     }, 1000);
     }, 1000);
});
});

Revision as of 15:50, 25 April 2026

/* All JavaScript here will be loaded for users of the Vector skin */

/* Redirect ALL red links to the "Create Page" page */
$('.new').on('click', function(e) {
    e.preventDefault();
    window.location.href = mw.util.getUrl('Fork:Create_Page');
});

/* Accelerate native Vector collapsible tabs */
( function () {
    var triggerNativeTabs = function () {
        if ( mw.config.get( 'skin' ) === 'vector' ) {
            // Forces the native script to recalculate and move links into the "More" menu
            $( window ).trigger( 'resize' );
        }
    };
    // Run as soon as the basic page structure is ready
    $( triggerNativeTabs );
}() );

// Force immediate check for collapsible tabs in Vector Legacy
mw.loader.using( 'mediawiki.util' ).done( function () {
    $( function () {
        if ( mw.config.get( 'skin' ) === 'vector' ) {
            // Trigger the resize event immediately on load
            $( window ).trigger( 'resize' );
        }
    } );
} );

/* Move subcategories to the top on Category:Forklifts and Category:Video_Games */
if ( mw.config.get( 'wgPageName' ) === 'Category:Forklifts' || mw.config.get( 'wgPageName' ) === 'Category:Video_Games' ) {
    $( function() {
        var subcats = $( '#mw-subcategories' );
        var content = $( '.mw-parser-output' );
        if ( subcats.length && content.length ) {
            subcats.insertBefore( content );
            $( 'body' ).addClass( 'move-subcategories-up-active' );
            $( '#bodyContent' ).css( { 'display': 'flex', 'flex-direction': 'column' } );
            content.css( 'order', '2' );
            subcats.css( 'order', '1' );
        }
    } );
}

/* SHOW ALL BUTTON */
mw.loader.using(['mediawiki.util', 'jquery'], function() {
    $(function() {
        $('.cargo-show-all-btn').on('click', function() {
            var $this = $(this);
            var $grid = $this.siblings('.cargo-hidden-grid');

            // Toggle visibility
            $grid.toggleClass('grid-visible');
            
            // Dynamic text switching
            var isVisible = $grid.hasClass('grid-visible');
            var originalText = $this.text();
            
            if (isVisible) {
                $this.data('original-text', originalText);
                $this.text(originalText.replace('Show All', 'Hide')).addClass('btn-active');
            } else {
                $this.text($this.data('original-text')).removeClass('btn-active');
            }
        });
    });
});


/* NEWS SLIDESHOW */
mw.loader.using('mediawiki.util').then(function () {
    mw.hook('wikipage.content').add(function () {
        document.querySelectorAll('.news-slideshow-container').forEach(function (container) {
            var slides = container.querySelectorAll('.news-slideshow-slide');
            if (slides.length <= 1) return;

            var current = 0;
            var intervalId = null;
            var delay = 8000; // 8 seconds

            function showSlide(index) {
                slides.forEach(function (slide, i) {
                    slide.classList.toggle('active', i === index);
                });
            }

            function startSlideshow() {
                if (intervalId !== null) return;
                intervalId = setInterval(function () {
                    current = (current + 1) % slides.length;
                    showSlide(current);
                }, delay);
            }

            function stopSlideshow() {
                if (intervalId !== null) {
                    clearInterval(intervalId);
                    intervalId = null;
                }
            }

            // Initial state
            showSlide(current);
            startSlideshow();

            // Pause on hover
            container.addEventListener('mouseenter', stopSlideshow);
            container.addEventListener('mouseleave', startSlideshow);
        });
    });
});


/* FORM TABLE */
document.addEventListener('click', function (e) {
	const header = e.target.closest('.pf-collapsible');
	if (!header) return;

	const targetId = header.dataset.target;
	const section = document.getElementById(targetId);
	if (!section) return;

	const isOpen = section.style.display === 'block';
	section.style.display = isOpen ? 'none' : 'block';
});

/* CLICKABLE HOME BUTTON AT THE TOP IN MOBILE VIEW */
$(document).ready(function() {
    $('#left-navigation').on('click', function(e) {
        if (e.target === this || $(e.target).is('::before')) {
            window.location.href = mw.config.get('wgArticlePath').replace('$1', '');
        }
    });
});



$(document).on('pfUploadComplete', function() {
    // 1. Wait exactly 1 second after upload
    setTimeout(function() {
        // 2. TARGET ONLY THIS FIELD: The Infobox Game image field
        // Note: Page Forms uses underscores for spaces in template names
        var $field = $('input[name="Infobox_Game[image]"]');

        if ($field.length > 0 && $field.val() !== "") {
            var el = $field[0];

            // 3. THE CLICK: Simulate the hardware events to make it active
            // We use the raw element to ensure a deep browser click
            el.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }));
            el.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
            el.dispatchEvent(new MouseEvent('click', { bubbles: true }));

            // 4. FOCUS: Place the cursor inside
            $field.focus();

            console.log("Surgical Sync: Clicked only the Game Cover field.");
        }
    }, 1000);
});