-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
85 lines (76 loc) · 2.84 KB
/
script.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*pageChanger é usado para determinar
qual a página para o qual devemos transitar*/
var PageHandler = function(){
var currentPage = "#page1";
this.getCurrentPage = function(){
return currentPage;
};
this.getNextPage = function(){
return updatePage();
};
var updatePage = function(){
if (currentPage == "#page1"){
currentPage = "#page2";
} else {
currentPage = "#page1";
}
return currentPage;
};
};
var pageChanger = new PageHandler();
var myRoutes = [
{ "#x": { handler: function(){ console.log("x router");}, events: "bC", argsre: true }},
{ "#page": { handler: "pageBc", events: "bC", argsre: true }},
//views will be toggled between this 2 pages
{ "#page1": { handler: "dynamicView", events: "bC", argsre: true }},
{ "#page2": { handler: "dynamicView", events: "bC", argsre: true }}
];
var myHandlers = {
pageBc: function(type,match,ui,page,e){
console.log("#page router")
e.preventDefault();
ui.toPage = pageChanger.getNextPage();
console.log("redirected to view" + ui.toPage);
ui.bCDeferred.resolve();
},
dynamicView: function(type,match,ui,page,e){
console.log(pageChanger.getCurrentPage() + " router")
e.preventDefault();
console.log(ui.options.dataUrl);
var params = approuter.getParams( ui.options.dataUrl);
var p = params.id;
console.log(p);
switch (p)
{
case "dogs":
console.log("rendering dogs in 1000 seconds");
setTimeout(function(){
$( pageChanger.getCurrentPage() + " .content").html("Dogs at " + pageChanger.getCurrentPage());
ui.bCDeferred.resolve();
},1000);
break;
case "cats":
console.log("rendering cats in 4000 seconds");
setTimeout(function(){
$( pageChanger.getCurrentPage() + " .content").html("cats at " + pageChanger.getCurrentPage());
ui.bCDeferred.resolve();
},4000);
break;
case "profile":
console.log("rendering profile in 1000 seconds");
setTimeout(function(){
$( pageChanger.getCurrentPage() + " .content").html("profile at " + pageChanger.getCurrentPage());
ui.bCDeferred.resolve();
},1000);
break;
}
}
};
var approuter = new $.mobile.Router(myRoutes, myHandlers, {
// defaultHandler: function(type, ui, page) {
// console.log("Default handler called due to unknown route ("+ type + ", " + ui + ", " + page + ")"
// );
// },
defaultHandlerEvents: "s",
defaultArgsRe: true
});