MediaWiki:Common.js: Difference between revisions

no edit summary
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() {