MediaWiki:Common.js: Difference between revisions

From OtherX
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
/* Restrict zooming out beyond the initial page size on mobile */
/* Restrict zooming out beyond the initial page size on mobile */
var initialScale = 1;
var initialScale = 1;
var pinchStartDistance;


document.addEventListener('wheel', function(e) {
document.addEventListener('gesturestart', function(e) {
     if (e.deltaY < 0 && window.innerWidth <= window.screen.width) {
     pinchStartDistance = getPinchDistance(e);
});
 
document.addEventListener('gesturechange', function(e) {
    var pinchDistance = getPinchDistance(e);
 
    if (pinchDistance > pinchStartDistance) {
         /* Zoom in */
         /* Zoom in */
         initialScale *= 1.1;
         initialScale *= 1.1;
     } else if (e.deltaY > 0 && window.innerWidth <= window.screen.width && initialScale > 1) {
     } else if (pinchDistance < pinchStartDistance && initialScale > 1) {
         /* Zoom out */
         /* Zoom out */
         initialScale /= 1.1;
         initialScale /= 1.1;
Line 13: Line 20:
     updateViewport();
     updateViewport();
});
});
function getPinchDistance(e) {
    return Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
}


function updateViewport() {
function updateViewport() {

Revision as of 19:45, 24 December 2023

/* Restrict zooming out beyond the initial page size on mobile */
var initialScale = 1;
var pinchStartDistance;

document.addEventListener('gesturestart', function(e) {
    pinchStartDistance = getPinchDistance(e);
});

document.addEventListener('gesturechange', function(e) {
    var pinchDistance = getPinchDistance(e);

    if (pinchDistance > pinchStartDistance) {
        /* Zoom in */
        initialScale *= 1.1;
    } else if (pinchDistance < pinchStartDistance && initialScale > 1) {
        /* Zoom out */
        initialScale /= 1.1;
    }

    updateViewport();
});

function getPinchDistance(e) {
    return Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
}

function updateViewport() {
    var viewport = document.querySelector("meta[name=viewport]");
    if (viewport) {
        viewport.content = "width=device-width, initial-scale=" + initialScale + ", maximum-scale=1, user-scalable=yes";
    }
}