-
Notifications
You must be signed in to change notification settings - Fork 4
/
master-controller.js
85 lines (68 loc) · 2.01 KB
/
master-controller.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
var TemplateController = require('./template-controller');
var DetailController = require('./detail-controller');
var util = require('util');
var Famous = require('../shims/famous');
var _ = require('lodash');
var $ = require('jquery');
var Templates = require('../lib/templates');
function MasterController(options) {
TemplateController.call(this, options);
}
util.inherits(MasterController, TemplateController);
MasterController.prototype.prepareDetailController = function () {
var self = this;
if (!self.detailController) {
self.detailController = new DetailController({
templates: self.templates,
titles: self.titles,
titleBar: self.titleBar,
});
self.detailController.on('back', function () {
self.emit('ascend');
});
self.detailController.on('pageFlip', function (page) {
console.log('pageFlip', page.index);
});
}
};
MasterController.prototype.navigateToIndex = function (index) {
var self = this;
self.prepareDetailController();
if (self.viewController) {
self.detailController.navigateToIndex(index, true);
} else {
self.detailController.navigateToIndex(index, false);
self.setNavigationItem(self.detailController);
self.emit('descend', { index: index });
}
};
MasterController.prototype.setUpPage = function (page) {
var self = this;
var links = page.find('a.template-link');
links.on('click', function (evt) {
evt.preventDefault();
});
var templates = [];
var titles = [];
links.each(function (idx, el) {
var $el = $(el);
var href = $el.attr('href');
var template = Templates;
_.each(href.split('/'), function (el) {
template = template[el];
});
templates.push(template);
titles.push($el.data('title'));
$el.on('click', function (evt) {
evt.preventDefault();
});
Famous.FastClick($el, function() {
self.navigateToIndex(idx);
});
});
if (!self.templates) {
self.templates = templates;
self.titles = titles;
}
};
module.exports = MasterController;