(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);
}
})();