網路城邦
上一篇 回創作列表 下一篇   字體:
WinJS
2014/10/19 19:29:15瀏覽149|回應0|推薦0

(function () {
    "use strict";
    var Application=WinJS.Application;
    var Activation=Windows.ApplicationModel.Activation;
    var ActivationKind=Activation.ActivationKind;
    var ApplicationExecutionState=Activation.ApplicationExecutionState;
    var Navigation=WinJS.Navigation;
    var Pages=WinJS.UI.Pages;
    var Utilities=WinJS.Utilities;
    WinJS.strictProcessing();

    //在應用程式啟動與重新啟動時被呼叫
    Application.onactivated=function(args) {
        if (args.detail.kind===ActivationKind.launch) {
            if (args.detail.previousExecutionState!==
                ApplicationExecutionState.terminated) {
                Application.onlaunched(args);
            }
            args.setPromise(WinJS.UI.processAll().then(function() {//(6)
                //回復工作階段狀態(5)
                var url=Application.sessionState.lastUrl ||
                    "/html/page0.html";
                return Navigation.navigate(url);//(1)
            }));
        }
    };

    //在應用程式啟動時被呼叫
    Application.onlaunched=function(args) {
    };

    //應用程式開始
    Application.start();

    //在頁面移動時被呼叫(2)
    Navigation.addEventListener("navigated",function(ev) {
        //取得URL與宿主
        var url=ev.detail.location;
        var host=$("contentHost");
       
        //清除頁面(4)
        if (host.winControl && host.winControl.unload) {
            host.winControl.unload();
        }
        Utilities.empty(host);

        //描繪頁面(3)
        ev.detail.setPromise(Pages.render(
            url,host,ev.detail.state).then(function() {
            //儲存工作階段狀態(5)
            Application.sessionState.lastUrl=url;
        }));
    });

    //取得元素
    function $(id) {
        return document.getElementById(id);
    }
})();

( 知識學習隨堂筆記 )
回應 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=ezkang3245&aid=18312213