-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp.js
More file actions
164 lines (147 loc) · 5.38 KB
/
Copy pathapp.js
File metadata and controls
164 lines (147 loc) · 5.38 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
new Ext.Application({
name: 'mondrian',
launch: function() {
var app = this;
// construct UI
var viewport = this.viewport = new Ext.Panel({
fullscreen: true,
layout: 'card',
showingPage: false,
showingSplash: true
});
// the page that displays each chapter
var page = viewport.page = new Ext.Panel({
cls: 'page',
styleHtmlContent: true,
tpl: '<h2>{title}</h2>{content}',
scroll: 'vertical'
});
// the data-bound menu list
var menuList = viewport.menuList = new Ext.List({
store: this.stores.pages,
itemTpl: '{title}',
allowDeselect: false,
singleSelect: true
});
// a wrapper around the menu list
var menu = viewport.menu = new Ext.Panel({
items: [menuList],
layout: 'fit',
width: 150,
dock: 'left'
});
// a button that toggles the menu when it is floating
var menuButton = viewport.menuButton = new Ext.Button({
iconCls: 'list',
iconMask: true
});
// a button that slides page back to list (portrait phone only)
var backButton = viewport.backButton = new Ext.Button({
ui: 'back',
text: 'Back'
});
// a button that pops up a Wikipedia attribution
var infoButton = viewport.infoButton = new Ext.Button({
iconCls: 'info',
iconMask: true
});
// the toolbar across the top of the app, containing the buttons
var toolbar = this.toolbar = new Ext.Toolbar({
ui: 'light',
title: 'Piet Mondrian',
items: [backButton, menuButton, {xtype: 'spacer'}, infoButton]
});
// stitch the UI together and create an entry page
viewport.addDocked(toolbar);
viewport.setActiveItem(page);
page.update('<img class="photo" src="head.jpg">');
// add profile behaviors for relevant controls
viewport.setProfile = function (profile) {
if (profile=='portraitPhone') {
this.setActiveItem(this.menu);
if (!this.showingSplash) {
this.setActiveItem(this.page);
}
} else if (profile=='landscapePhone') {
this.remove(this.menu, false);
this.setActiveItem(this.page);
} else if (profile=='portraitTablet') {
this.removeDocked(this.menu, false);
} else if (profile=='landscapeTablet') {
this.addDocked(this.menu);
}
};
menu.setProfile = function (profile) {
if (profile=="landscapePhone" || profile=="portraitTablet") {
this.hide();
if (this.rendered) {
this.el.appendTo(document.body);
}
this.setFloating(true);
this.setSize(150, 200);
} else {
this.setFloating(false);
this.show();
}
};
menuButton.setProfile = function (profile) {
if (profile=="landscapePhone" || profile=="portraitTablet") {
this.show();
} else {
this.hide();
}
};
backButton.setProfile = function (profile) {
if (profile=='portraitPhone' && viewport.showingPage) {
this.show();
} else {
this.hide();
}
};
// menu button toggles (floating) menu
menuButton.addListener('tap', function () {
menu.showBy(this);
});
// menu list (slides and) updates page with new content
menuList.addListener('selectionchange', function (model, records) {
if (records[0]) {
viewport.setActiveItem(page, {type: 'slide', direction: 'left'});
page.update(records[0].data);
viewport.doLayout();
viewport.showingPage = true;
viewport.showingSplash = false;
if (app.getProfile()=='portraitPhone') {
backButton.show();
}
}
});
// back button slides back to (card) menu
backButton.addListener('tap', function () {
viewport.setActiveItem(menu, {type: 'slide', direction: 'right'});
viewport.showingPage = false;
this.hide();
});
// info button provides attribution
infoButton.addListener('tap', function () {
Ext.Msg.alert('',
'Information made available under ' +
'<a href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA</a> ' +
'from <a href="http://en.wikipedia.org/wiki/Piet_Mondrian">Wikipedia</a>.'
);
});
},
profiles: {
portraitPhone: function() {
return Ext.is.Phone && Ext.orientation == 'portrait';
},
landscapePhone: function() {
return Ext.is.Phone && Ext.orientation == 'landscape';
},
portraitTablet: function() {
return !Ext.is.Phone && Ext.orientation == 'portrait';
},
landscapeTablet: function() {
return !Ext.is.Phone && Ext.orientation == 'landscape';
}
}
});