zoomDetector.js 2.27 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
/**
 *  ABook Viewer for WEB
 *  ZoomDetector Library
 *  Copyright (C) Agentec Co, Ltd. All rights reserved.
*/

//グローバルの名前空間用のオブジェクトを用意する
var ZOOM_DETECTOR = {};

ZOOM_DETECTOR.zoom_ratioPre = 1;
ZOOM_DETECTOR.zoom_ratio = 1;
ZOOM_DETECTOR.zoom_timer;
ZOOM_DETECTOR.zoom_continue = false;
ZOOM_DETECTOR.zoom_callbackFunction;
ZOOM_DETECTOR.zoom_miliSeconds = 1000;  // Default is 1 second
ZOOM_DETECTOR.zoom_oldW = -1;
ZOOM_DETECTOR.zoom_oldH = -1;

ZOOM_DETECTOR.calculateZoomLevel = function() {
    ZOOM_DETECTOR.zoom_ratioPre = ClientData.zoom_ratioPre();
    if (ZOOM_DETECTOR.zoom_timer) {
        clearTimeout(ZOOM_DETECTOR.zoom_timer);
        ZOOM_DETECTOR.zoom_timer = null;
24 25
    }
    
26 27 28 29
    ZOOM_DETECTOR.zoom_ratio = document.documentElement.clientWidth / window.innerWidth;
    if (ZOOM_DETECTOR.zoom_ratioPre != ZOOM_DETECTOR.zoom_ratio) {
        if (ZOOM_DETECTOR.zoom_oldW == -1) {
            ZOOM_DETECTOR.zoom_oldW = document.documentElement.clientWidth;
30
        }
31 32
        if (ZOOM_DETECTOR.zoom_oldH == -1) {
            ZOOM_DETECTOR.zoom_oldH = document.documentElement.clientWidth;
33
        }
34 35
        if (ZOOM_DETECTOR.zoom_callbackFunction) {
            ZOOM_DETECTOR.zoom_callbackFunction(ZOOM_DETECTOR.zoom_ratioPre, ZOOM_DETECTOR.zoom_ratio, ZOOM_DETECTOR.zoom_oldW, ZOOM_DETECTOR.zoom_oldH, window.innerWidth, window.innerHeight);
36
        }
37 38 39 40
        ZOOM_DETECTOR.zoom_ratioPre = ZOOM_DETECTOR.zoom_ratio;
        ClientData.zoom_ratioPre(ZOOM_DETECTOR.zoom_ratioPre);
        ZOOM_DETECTOR.zoom_oldW = window.innerWidth;
        ZOOM_DETECTOR.zoom_oldH = window.innerHeight;
41
    }
42 43
    if (ZOOM_DETECTOR.zoom_continue == true) {
        ZOOM_DETECTOR.zoom_timer = setTimeout("ZOOM_DETECTOR.calculateZoomLevel();", ZOOM_DETECTOR.zoom_miliSeconds);
44 45
    }
};
46 47 48

ZOOM_DETECTOR.stopDetectZoom = function() {
    ZOOM_DETECTOR.zoom_continue = false;
49
};
50 51 52

ZOOM_DETECTOR.startDetectZoom = function(params) {
    ZOOM_DETECTOR.zoom_continue = true;
53
    if (params.callbackFunction) {
54
        ZOOM_DETECTOR.zoom_callbackFunction = params.callbackFunction;
55 56
    }
    if (params.time) {
57
        ZOOM_DETECTOR.zoom_miliSeconds = params.time;
58
    }
59 60
    ZOOM_DETECTOR.zoom_timer = setTimeout("ZOOM_DETECTOR.calculateZoomLevel();", ZOOM_DETECTOR.zoom_miliSeconds);
};