Created page with "Any JavaScript here will be loaded for all users on every page load.: // Prevent Leaflet maps from auto-scrolling on load // (Needed for Main Page repair services map) (function() { var initialScrollY = window.scrollY; setTimeout(function() { if (initialScrollY < 100 && window.scrollY > 200) { window.scrollTo(0, initialScrollY); } }, 200); })();"
 
No edit summary
Line 2: Line 2:




// Prevent Leaflet maps from auto-scrolling on load
/**
// (Needed for Main Page repair services map)
* Prevent Leaflet maps from auto-scrolling page on load
* This intercepts scroll attempts during map initialization
*/
(function() {
(function() {
     var initialScrollY = window.scrollY;
    'use strict';
   
    // Only apply fix if we're near the top of the page
    if (window.scrollY > 100) return;
   
     var savedPosition = window.scrollY;
    var scrollLocked = true;
   
    // Temporarily override scrollIntoView to prevent map from scrolling page
    var originalScrollIntoView = Element.prototype.scrollIntoView;
    Element.prototype.scrollIntoView = function(options) {
        // Allow scrollIntoView for non-map elements after unlock
        if (!scrollLocked || !this.closest('.leaflet-container, .smw-format-leaflet')) {
            originalScrollIntoView.call(this, options);
        }
    };
   
    // Also intercept any direct scroll attempts
    var originalScrollTo = window.scrollTo.bind(window);
    window.scrollTo = function(x, y) {
        if (scrollLocked && savedPosition < 100) {
            return; // Block scroll during initialization
        }
        originalScrollTo(x, y);
    };
   
    // Restore normal behavior after maps have initialized
     setTimeout(function() {
     setTimeout(function() {
         if (initialScrollY < 100 && window.scrollY > 200) {
         scrollLocked = false;
            window.scrollTo(0, initialScrollY);
        Element.prototype.scrollIntoView = originalScrollIntoView;
        }
        window.scrollTo = originalScrollTo;
     }, 200);
     }, 1000);
})();
})();

Revision as of 19:24, 14 January 2026

/* Any JavaScript here will be loaded for all users on every page load. */


/**
 * Prevent Leaflet maps from auto-scrolling page on load
 * This intercepts scroll attempts during map initialization
 */
(function() {
    'use strict';
    
    // Only apply fix if we're near the top of the page
    if (window.scrollY > 100) return;
    
    var savedPosition = window.scrollY;
    var scrollLocked = true;
    
    // Temporarily override scrollIntoView to prevent map from scrolling page
    var originalScrollIntoView = Element.prototype.scrollIntoView;
    Element.prototype.scrollIntoView = function(options) {
        // Allow scrollIntoView for non-map elements after unlock
        if (!scrollLocked || !this.closest('.leaflet-container, .smw-format-leaflet')) {
            originalScrollIntoView.call(this, options);
        }
    };
    
    // Also intercept any direct scroll attempts
    var originalScrollTo = window.scrollTo.bind(window);
    window.scrollTo = function(x, y) {
        if (scrollLocked && savedPosition < 100) {
            return; // Block scroll during initialization
        }
        originalScrollTo(x, y);
    };
    
    // Restore normal behavior after maps have initialized
    setTimeout(function() {
        scrollLocked = false;
        Element.prototype.scrollIntoView = originalScrollIntoView;
        window.scrollTo = originalScrollTo;
    }, 1000);
})();
MediaWiki Appliance - Powered by TurnKey Linux