forked from zellotec/Mba.ux.Viewport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Navigation.js
83 lines (69 loc) · 2.08 KB
/
Navigation.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
Ext.define('Mba.ux.Viewport.Navigation', {
singleton: true,
alternateClassName: 'viewport.navigation',
config: {
confirmCloseApp: true,
backOverride: null,
navigationStack: []
},
constructor : function (config) {
this.initConfig(config);
this.callParent([config]);
},
activateView: function(viewXtype, options, animation) {
var view;
if(!(view = Ext.Viewport.child(viewXtype))) {
view = Ext.Viewport.add({xtype: viewXtype});
}
if(!animation && view.getAnimation) {
animation = view.getAnimation();
animation.direction = 'left';
}
for(var o in options) {
view['set' + Ext.String.capitalize(o)](options[o]);
}
if (view.isInnerItem()) {
if(animation) {
Ext.Viewport.animateActiveItem(view, animation);
} else {
Ext.Viewport.setActiveItem(view);
}
} else {
view.show();
}
this.orderHistory(viewXtype);
return view;
},
clear: function() {
this.setNavigationStack([]);
},
orderHistory: function(viewXtype) {
var stack = this.getNavigationStack(),
pos;
if((pos = stack.indexOf(viewXtype)) >= 0) {
stack.splice(pos, 1);
}
stack.push(viewXtype);
this.setNavigationStack(stack);
},
back: function() {
var stack = this.getNavigationStack();
if(stack.length <= 1) {return false;}
var animation = this.getAnimation(stack.pop());
if(animation) {
animation.direction = 'right';
}
this.activateView(stack.pop(), null, animation);
return true;
},
getAnimation: function(viewXtype) {
var view = Ext.Viewport.child(viewXtype);
return view.getAnimation ? view.getAnimation() : null;
},
clearNavitaionStack: function() {
this.setNavigationStack([]);
},
clearBackOverride: function() {
this.setBackOverride(null);
}
});