Commit cc95a08a by Masaru Abe

ZoomDetector.jsリファクタリング

parent 1ff1a86a
var zoom_ratioPre = 1; /**
var zoom_ratio = 1; * ABook Viewer for WEB
var zoom_timer; * ZoomDetector Library
var zoom_continue = false; * Copyright (C) Agentec Co, Ltd. All rights reserved.
var zoom_callbackFunction; */
var zoom_miliSeconds = 1000; // Default is 1 second
var zoom_oldW = -1; //グローバルの名前空間用のオブジェクトを用意する
var zoom_oldH = -1; var ZOOM_DETECTOR = {};
function calculateZoomLevel() {
zoom_ratioPre = ClientData.zoom_ratioPre(); ZOOM_DETECTOR.zoom_ratioPre = 1;
if (zoom_timer) { ZOOM_DETECTOR.zoom_ratio = 1;
clearTimeout(zoom_timer); ZOOM_DETECTOR.zoom_timer;
zoom_timer = null; 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;
} }
zoom_ratio = document.documentElement.clientWidth / window.innerWidth; ZOOM_DETECTOR.zoom_ratio = document.documentElement.clientWidth / window.innerWidth;
if (zoom_ratioPre != zoom_ratio) { if (ZOOM_DETECTOR.zoom_ratioPre != ZOOM_DETECTOR.zoom_ratio) {
if (zoom_oldW == -1) { if (ZOOM_DETECTOR.zoom_oldW == -1) {
zoom_oldW = document.documentElement.clientWidth; ZOOM_DETECTOR.zoom_oldW = document.documentElement.clientWidth;
} }
if (zoom_oldH == -1) { if (ZOOM_DETECTOR.zoom_oldH == -1) {
zoom_oldH = document.documentElement.clientWidth; ZOOM_DETECTOR.zoom_oldH = document.documentElement.clientWidth;
} }
if (zoom_callbackFunction) { if (ZOOM_DETECTOR.zoom_callbackFunction) {
zoom_callbackFunction(zoom_ratioPre, zoom_ratio, zoom_oldW, zoom_oldH, window.innerWidth, window.innerHeight); ZOOM_DETECTOR.zoom_callbackFunction(ZOOM_DETECTOR.zoom_ratioPre, ZOOM_DETECTOR.zoom_ratio, ZOOM_DETECTOR.zoom_oldW, ZOOM_DETECTOR.zoom_oldH, window.innerWidth, window.innerHeight);
} }
zoom_ratioPre = zoom_ratio; ZOOM_DETECTOR.zoom_ratioPre = ZOOM_DETECTOR.zoom_ratio;
ClientData.zoom_ratioPre(zoom_ratioPre); ClientData.zoom_ratioPre(ZOOM_DETECTOR.zoom_ratioPre);
zoom_oldW = window.innerWidth; ZOOM_DETECTOR.zoom_oldW = window.innerWidth;
zoom_oldH = window.innerHeight; ZOOM_DETECTOR.zoom_oldH = window.innerHeight;
} }
if (zoom_continue == true) { if (ZOOM_DETECTOR.zoom_continue == true) {
zoom_timer = setTimeout("calculateZoomLevel();", zoom_miliSeconds); ZOOM_DETECTOR.zoom_timer = setTimeout("ZOOM_DETECTOR.calculateZoomLevel();", ZOOM_DETECTOR.zoom_miliSeconds);
} }
}; };
function stopDetectZoom() {
zoom_continue = false; ZOOM_DETECTOR.stopDetectZoom = function() {
ZOOM_DETECTOR.zoom_continue = false;
}; };
function startDetectZoom(params) {
zoom_continue = true; ZOOM_DETECTOR.startDetectZoom = function(params) {
ZOOM_DETECTOR.zoom_continue = true;
if (params.callbackFunction) { if (params.callbackFunction) {
zoom_callbackFunction = params.callbackFunction; ZOOM_DETECTOR.zoom_callbackFunction = params.callbackFunction;
} }
if (params.time) { if (params.time) {
zoom_miliSeconds = params.time; ZOOM_DETECTOR.zoom_miliSeconds = params.time;
} }
zoom_timer = setTimeout("calculateZoomLevel();", zoom_miliSeconds); ZOOM_DETECTOR.zoom_timer = setTimeout("ZOOM_DETECTOR.calculateZoomLevel();", ZOOM_DETECTOR.zoom_miliSeconds);
}; };
\ No newline at end of file
...@@ -2188,7 +2188,7 @@ function displayOverlayForSpecifyContentType(){ ...@@ -2188,7 +2188,7 @@ function displayOverlayForSpecifyContentType(){
if (COMMON.isTouchDevice() == true) { if (COMMON.isTouchDevice() == true) {
if (avwUserEnvObj.os == "android") { if (avwUserEnvObj.os == "android") {
standardRatio = document.documentElement.clientWidth / window.innerWidth; standardRatio = document.documentElement.clientWidth / window.innerWidth;
startDetectZoom({ time: 500, ZOOM_DETECTOR.startDetectZoom({ time: 500,
callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) { callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) {
currentRatio = newRatio; currentRatio = newRatio;
......
...@@ -1135,7 +1135,7 @@ function getContentInfoTypeImage(){ ...@@ -1135,7 +1135,7 @@ function getContentInfoTypeImage(){
if (COMMON.isTouchDevice() == true) { if (COMMON.isTouchDevice() == true) {
if (avwUserEnvObj.os == "android") { if (avwUserEnvObj.os == "android") {
standardRatio = document.documentElement.clientWidth / window.innerWidth; standardRatio = document.documentElement.clientWidth / window.innerWidth;
startDetectZoom({ time: 500, ZOOM_DETECTOR.startDetectZoom({ time: 500,
callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) { callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) {
currentRatio = newRatio; currentRatio = newRatio;
......
...@@ -391,7 +391,7 @@ function initPage() { ...@@ -391,7 +391,7 @@ function initPage() {
if (COMMON.isTouchDevice() == true) { if (COMMON.isTouchDevice() == true) {
if (avwUserEnvObj.os == "android") { if (avwUserEnvObj.os == "android") {
standardRatio = document.documentElement.clientWidth / window.innerWidth; standardRatio = document.documentElement.clientWidth / window.innerWidth;
startDetectZoom({ time: 500, ZOOM_DETECTOR.startDetectZoom({ time: 500,
callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) { callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) {
currentRatio = newRatio; currentRatio = newRatio;
...@@ -531,7 +531,7 @@ function initPage() { ...@@ -531,7 +531,7 @@ function initPage() {
if (COMMON.isTouchDevice() == true) { if (COMMON.isTouchDevice() == true) {
if (avwUserEnvObj.os == "android") { if (avwUserEnvObj.os == "android") {
standardRatio = document.documentElement.clientWidth / window.innerWidth; standardRatio = document.documentElement.clientWidth / window.innerWidth;
startDetectZoom({ time: 500, ZOOM_DETECTOR.startDetectZoom({ time: 500,
callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) { callbackFunction: function (oldRatio, newRatio, oldW, oldH, newW, newH) {
currentRatio = newRatio; currentRatio = newRatio;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment