zoomDetector.js 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
var zoom_ratioPre = 1;
var zoom_ratio = 1;
var zoom_timer;
var zoom_continue = false;
var zoom_callbackFunction;
var zoom_miliSeconds = 1000;  // Default is 1 second
var zoom_oldW = -1;
var zoom_oldH = -1;
function calculateZoomLevel() {
    zoom_ratioPre = ClientData.zoom_ratioPre();
    if (zoom_timer) {
        clearTimeout(zoom_timer);
        zoom_timer = null;
    }
    
    zoom_ratio = document.documentElement.clientWidth / window.innerWidth;
    if (zoom_ratioPre != zoom_ratio) {
        if (zoom_oldW == -1) {
            zoom_oldW = document.documentElement.clientWidth;
        }
        if (zoom_oldH == -1) {
            zoom_oldH = document.documentElement.clientWidth;
        }
        if (zoom_callbackFunction) {
            zoom_callbackFunction(zoom_ratioPre, zoom_ratio, zoom_oldW, zoom_oldH, window.innerWidth, window.innerHeight);
        }
        zoom_ratioPre = zoom_ratio;
        ClientData.zoom_ratioPre(zoom_ratioPre);
        zoom_oldW = window.innerWidth;
        zoom_oldH = window.innerHeight;
    }
    if (zoom_continue == true) {
        zoom_timer = setTimeout("calculateZoomLevel();", zoom_miliSeconds);
    }
};
function stopDetectZoom() {
    zoom_continue = false;
};
function startDetectZoom(params) {
    zoom_continue = true;
    if (params.callbackFunction) {
        zoom_callbackFunction = params.callbackFunction;
    }
    if (params.time) {
        zoom_miliSeconds = params.time;
    }
    zoom_timer = setTimeout("calculateZoomLevel();", zoom_miliSeconds);
};