-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
384 lines (363 loc) · 11.8 KB
/
main.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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/**
* This Source Code is licensed under the MIT license. If a copy of the
* MIT-license was not distributed with this file, You can obtain one at:
* http://opensource.org/licenses/mit-license.html.
*
* @author: Hein Rutjes (IjzerenHein)
* @license MIT
* @copyright Gloey Apps, 2015
*/
/*global define, moment, console*/
/*eslint no-use-before-define:0, no-console:0*/
define(function(require) {
//<webpack>
require('famous-polyfills');
require('famous/core/famous.css');
require('famous-flex/widgets/styles.css');
require('../bower_components/ionicons/css/ionicons.min.css');
require('./styles.css');
require('./index.html');
//</webpack>
// Fast-click
var FastClick = require('fastclick/lib/fastclick');
FastClick.attach(document.body);
// import dependencies
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var Transform = require('famous/core/Transform');
var Easing = require('famous/transitions/Easing');
var StateModifier = require('famous/modifiers/StateModifier');
var RenderNode = require('famous/core/RenderNode');
var LayoutController = require('famous-flex/LayoutController');
var FlexScrollView = require('famous-flex/FlexScrollView');
var TabBar = require('famous-flex/widgets/TabBar');
// create the main context
var mainContext = Engine.createContext();
// create main scrollview
var scrollView = new FlexScrollView({
mouseMove: true,
useContainer: true,
container: {},
layoutAll: true,
layoutOptions: {
margins: [10, 20],
itemSize: true
}
});
mainContext.add(scrollView);
///////////////////////////////////////////////////////////////////
//
// Basic example
//
///////////////////////////////////////////////////////////////////
var tabBar = new TabBar({
classes: ['white'],
createRenderables: {
background: true,
selectedItemOverlay: true
}
});
tabBar.setItems([
'one',
'two',
'lorum ipsum'
]);
_addTabBar(tabBar, '<b>Equal width</b> (itemSize: undefined)');
///////////////////////////////////////////////////////////////////
//
// itemSize: 80
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
tabBarLayout: {
itemSize: 100
},
classes: ['white'],
createRenderables: {
background: true,
selectedItemOverlay: true
}
});
tabBar.setItems([
'one',
'two',
'lorum ipsum'
]);
_addTabBar(tabBar, '<b>Fixed width</b> (itemSize: 80)');
///////////////////////////////////////////////////////////////////
//
// itemSize: true
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
tabBarLayout: {
itemSize: true,
margins: [0, 10],
spacing: 10
},
classes: ['black'],
createRenderables: {
background: true,
selectedItemOverlay: true
}
});
tabBar.setItems([
'one',
'two',
'lorum ipsum'
]);
_addTabBar(tabBar, '<b>True-size width</b> (itemSize: true)');
///////////////////////////////////////////////////////////////////
//
// itemSize: true, size: [true, undefined]
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
layoutController: {
size: [true, undefined]
},
tabBarLayout: {
itemSize: true,
margins: [0, 10],
spacing: 10
},
classes: ['black'],
createRenderables: {
background: true,
selectedItemOverlay: true
}
});
tabBar.setItems([
'one',
'two',
'lorum ipsum'
]);
_addTabBar(tabBar, '<b>Calculate width based on items</b> (size: [true, undefined], itemSize: true)');
///////////////////////////////////////////////////////////////////
//
// slow motion
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
layoutController: {
nodeSpring: {
dampingRatio: 0.8,
period: 1000
}
},
classes: ['black'],
createRenderables: {
background: true,
selectedItemOverlay: true
}
});
tabBar.setItems([
'one',
'two',
'lorum ipsum'
]);
_addTabBar(tabBar, '<b>Sloooow motion</b>, nodeSpring: {dampingRatio: 0.8, period: 1000}');
///////////////////////////////////////////////////////////////////
//
// bouncy
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
layoutController: {
nodeSpring: {
dampingRatio: 0.4,
period: 400
}
},
classes: ['blue'],
createRenderables: {
background: true,
selectedItemOverlay: true
}
});
tabBar.setItems([
'one',
'two',
'lorum ipsum'
]);
_addTabBar(tabBar, '<b>Bouncy</b>, nodeSpring: {dampingRatio: 0.4, period: 400}');
///////////////////////////////////////////////////////////////////
//
// images
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
classes: ['orange'],
createRenderables: {
background: true
}
});
tabBar.setItems([
'<div class="icon ion-flag"></div> ',
'<div class="icon ion-map"></div>',
'<div class="icon ion-gear-a"></div>',
'<div class="icon ion-star"></div>',
'<div class="icon ion-refresh"></div>'
]);
_addTabBar(tabBar, '<b>Images</b> (<div class="icon ion-flag"></div>)');
///////////////////////////////////////////////////////////////////
//
// images + text
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
classes: ['images', 'small', 'orange'],
createRenderables: {
background: true
}
});
tabBar.setItems([
'<div class="icon ion-flag"></div>Flag',
'<div class="icon ion-map"></div>Map',
'<div class="icon ion-gear-a"></div>Settings',
'<div class="icon ion-star"></div>Favorites',
'<div class="icon ion-refresh"></div>Refresh'
]);
_addTabBar(tabBar, '<b>Image + Text</b> (<div class="icon ion-flag"></div>Flag)', 110);
///////////////////////////////////////////////////////////////////
//
// spacers
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
classes: ['black'],
tabBarLayout: {
spacing: 1
},
createRenderables: {
background: true,
spacer: true,
selectedItemOverlay: true
}
});
tabBar.setItems([
'one',
'two',
'lorum ipsum'
]);
_addTabBar(tabBar, '<b>Spacers</b>, renderables: {spacer: true}');
///////////////////////////////////////////////////////////////////
//
// custom renderables
//
///////////////////////////////////////////////////////////////////
tabBar = new TabBar({
classes: ['images', 'small', 'white'],
createRenderables: {
background: function() {
return new Surface({
properties: {
backgroundImage: 'url(' + require('./images/back.png') + ')'
}
});
},
selectedItemOverlay: function() {
return new Surface({
properties: {
backgroundColor: 'rgba(255, 255, 255, 0.3)'
}
});
},
item: function(id, data) {
return new Surface({
classes: ['ff-widget', 'ff-tabbar', 'images', 'item', 'small'],
content: '<div><div class="icon ion-' + data.icon + '"></div>' + data.text + '</div>',
properties: {
color: 'white'
}
});
}
}
});
tabBar.setItems([
{icon: 'flag', text: 'Flag'},
{icon: 'map', text: 'Map'},
{icon: 'gear-a', text: 'Settings'},
{icon: 'star', text: 'Favorites'},
{icon: 'refresh', text: 'Refresh'}
]);
_addTabBar(tabBar, '<b>Custom renderables</b> (see the code)', 110);
///////////////////////////////////////////////////////////////////
//
// bouncy custom renderables
//
///////////////////////////////////////////////////////////////////
var bouncyCustomRenderables = [];
function _createBouncyCustomRenderable(id, data) {
var mod = new StateModifier();
var node = new RenderNode(mod);
var surface = new Surface({
classes: ['ff-widget', 'ff-tabbar', 'images', 'item', 'small', 'orange'],
content: '<div><div class="icon ion-' + data.icon + '"></div>' + data.text + '</div>'
});
if (bouncyCustomRenderables.length === 0) {
surface.addClass('selected');
}
// since the render-node that is added to the TabBar cannot handle events,
// install a handler which switches selection on the surface.
surface.on('click', this.setSelectedItemIndex.bind(this, bouncyCustomRenderables.length));
node.add(surface);
bouncyCustomRenderables.push({
mod: mod,
surface: surface,
node: node
});
return node;
}
tabBar = new TabBar({
classes: ['images', 'small', 'orange'],
createRenderables: {
background: true,
item: _createBouncyCustomRenderable
}
});
tabBar.setItems([
{icon: 'flag', text: 'Flag'},
{icon: 'map', text: 'Map'},
{icon: 'gear-a"', text: 'Settings'},
{icon: 'star', text: 'Favorites'},
{icon: 'refresh', text: 'Refresh'}
]);
tabBar.on('tabchange', function(event) {
// On tab-change, toggle the selection class on the old and new surface
bouncyCustomRenderables[event.oldIndex].surface.removeClass('selected');
bouncyCustomRenderables[event.index].surface.addClass('selected');
// Bounce up when an item is selected
bouncyCustomRenderables[event.index].mod.halt();
bouncyCustomRenderables[event.index].mod.setTransform(Transform.translate(0, 60, 0), {duration: 0});
bouncyCustomRenderables[event.index].mod.setTransform(Transform.rotate(0, 0, 0), {duration: 140, curve: Easing.outBack});
});
_addTabBar(tabBar, '<b>Bouncy custom renderables</b> (also see the code)', 110);
//
// Adds a tab-bar to the scrollview
//
function _addTabBar(tabBar2, title, height) {
scrollView.push(new LayoutController({
size: [undefined, height || 100],
layout: {dock: [
['top', 'header', 30],
['bottom', 'footer', 20],
['left', 'content']
]},
alwaysLayout: true,
dataSource: {
header: new Surface({
classes: ['header'],
content: title
}),
footer: new Surface({
classes: ['footer']
}),
content: tabBar2
}
}));
tabBar2.on('tabchange', function(event) {
console.log('tabchange: ' + event.index + ' (oldIndex: ' + event.oldIndex + ')');
});
}
});