//====== // // DeviceAct Application Framework for iPhone & iPad // // ver 0.1.0 // // Copyright 2010, DeviceAct All rights reserved. // //====== //====== DeviceAct Object $da = new Object(); //====== Setup at first of all (must be called form 'index.html' itself) $da.setup = function(){ document.addEventListener( "DOMContentLoaded", $da.onLoad, false ); if (navigator.userAgent.indexOf("iPad", 0) > -1) { document.write(''); document.write(''); } else { document.write(''); document.write(''); } try{ $da.waitForIdle(88, 12, 2); //--- Hack for iPhone Startup delay issue }catch(e){} }; $da.onLoad = function() { //--- Check system at first if (typeof $g == "undefined") { document.getElementById("gcanvas").style.display = "none"; document.getElementsByTagName("body")[0].innerHTML = ''; return false; } //--- Show installation messages if (!$g.isBrowserDebuggable() && ($da.isIPad() || $da.isIPhone())) { if (!window.navigator.standalone) { document.getElementById("gcanvas").style.display = "none"; document.getElementsByTagName("body")[0].innerHTML = ''; return false; } } //--- Init ASAP to prevent flashing on iPhone & iPad (But after InstallMsg) $g.initSystem(); //--- Check application cache if (window.applicationCache) { window.applicationCache.daCheckAndNext(onInit); } else { onInit(); } }; $da.getMetaContent = function(name_str){ var objs = document.getElementsByTagName("meta"); for (var i=0; i -1); }; $da.isIPhone = function () { return (navigator.userAgent.indexOf("iPhone", 0) > -1); }; $da.isIPhone4 = function () { return (navigator.userAgent.indexOf("iPhone OS 4", 0) > -1); }; //--- Orientation $da.isVerticalOrientation = function () { return (window.orientation == 0 || window.orientation == 180); }; $da.verticalWindowWidth = function () { var val = $da.verticalWindowWidth._val; if (!val) { val = (this.isVerticalOrientation()) ? window.innerWidth : window.innerHeight; $da.verticalWindowWidth._val = val; } return val; }; $da.verticalWindowHeight = function () { var val = $da.verticalWindowHeight._val; if (!val) { val = (this.isVerticalOrientation()) ? window.innerHeight : window.innerWidth; $da.verticalWindowHeight._val = val; } return val; }; //--- Time $da.milliseconds = function () { return new Date().getTime(); }; //--- comfirm before link (for tag only) $da.confirmBeforeJump = function(){ var msg = $da.getMetaContent("da_msg_confirmBeforeJump"); if (!msg) msg = "Move to Safari?"; if (confirm(msg)){ return true; }else{ event.preventDefault(); return false; } }; //--- Wait for Cool down $da.waitForIdle = function(workMs, workCnt, loopSec){ if (!workMs) workMs = 90; if (!workCnt) workCnt = 6; if (!loopSec) loopSec = 5; var cnt = 0; var d = new Date(); do { d3 = new Date(); for (var i=0; i<1000000; i++){} if((new Date())-d3 < workMs) cnt++; else cnt = 0; if (cnt > workCnt) break; } while((new Date())-d < loopSec*1000); return (cnt > workCnt); }; //--- Extend applicationCache (not prototype) window.applicationCache.daCheckAndNext = function(next_func){ if (navigator.onLine) { this._daNextFunc = next_func; this.onerror = function(e){this._daErr = e;}; $g.setTimeout("_daCheckAndNext_exec", this, this._daCheckAndNext_exec, 100); }else{ next_func(); } }; window.applicationCache._daCheckAndNext_exec = function(){ var msg = $da.getMetaContent("da_msg_appUpdated"); if (!msg) msg = "Application is updated!\nPlease restart now."; var goNext = false; var c = this; switch(c.status){ case c.UPDATEREADY: try { c.swapCache(); alert(msg); } catch(e) {} goNext = true; break; case c.CHECKING: case c.DOWNLOADING: $g.setTimeout("_daCheckAndNext_exec", this, this._daCheckAndNext_exec, 100); break; default: if (c._daErr) alert("Download file not found."); goNext = true; break; } if (goNext) { var f = this._daNextFunc; this._daNextFunc = null; f(); } }