appMobi で enchant.js 動かす方法

リクエストがあったのでサワリのみご紹介。

enchant.js

最初のあたりは大体以下な記述になってるはず。

enchant();

window.onload = function() {

これを以下な形に修正します。

enchant();

doOnload = function() {
//window.onload = function() {

で、index.html は以下な形。全部引用します。

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no"> 
    <meta name="apple-mobile-web-app-capable" content="yes">
    <script type="text/javascript" src="enchant.js"></script>
    <script type="text/javascript" src="nineleap.enchant.js"></script>
    <script type="text/javascript" src="main.js"></script>
    <script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/appmobi.js"></script> 
    <script type="text/javascript" charset="utf-8" src="http://localhost:58888/_appMobi/xhr.js"></script> 
<script type="text/javascript">
/* This code is used to run as soon as appMobi activates */
var onDeviceReady=function(){
    //Size the display to 768px by 1024px
    AppMobi.display.useViewport(768,1024);
	
	//hide splash screen
    AppMobi.device.hideSplashScreen();

    function sleep(time){
        setTimeout(after, time);
    }

    function after(){
        doOnload();
    }

    sleep(1);
};
document.addEventListener("appMobi.device.ready",onDeviceReady,false);    
</script>

    <style type="text/css">
        body {
            background-color:#fff;
            margin: 0;
        }
    </style>
</head>
<body>
</body>
</html>

after という手続きの中で呼び出している doOnload は encjant.js の window.onload な手続きになってりゃ OK ということらしいです。