app.js http://code.kik.com/app/2/index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
(
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,$);
|
本文转自 antlove 51CTO博客,原文链接:http://blog.51cto.com/antlove/1894052