(function(App,$){
var appLoad = App.load;
var appBack = App.back;
App.load = function(pageInfo, args, options, callback){
var pageName = null;
var url = null;
if(typeof pageInfo ==="string"){
pageName = pageInfo;
}else if(typeof pageInfo === "object"){
pageName = pageInfo.name;
url = pageInfo.url;
}
pushState(pageName); //
// 是否有同名的页面已经加载
if (App._Pages.has(pageName)) {
appLoad(pageName, args, options, callback);
return;
}
// 解析传入的html
function parsePage(html){
return html; // TODO we can enhance this
}
$.get(url,function(res){
var pageHtml = parsePage(res);
var page = $(pageHtml).appendTo("body");
App.add(pageName,page[0]);
appLoad(pageName, args, options, callback);
});
};
var internalBack = false;
App.back = function(pageName, callback){
internalBack = true;
appBack(pageName, callback);
history.back();
};
function pushState(pageName){
window.history.pushState({name:pageName},"","#/"+pageName);
}
window.onpopstate = function(event){
var state = event.state;
if(!internalBack){
appBack();
}
internalBack = false;
}
})(window.App,$);