Repository navigation
Expand file tree
/
Copy pathmanager.js
More file actions
171 lines (139 loc) · 4.49 KB
/
Copy pathmanager.js
File metadata and controls
171 lines (139 loc) · 4.49 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
165
166
167
168
169
170
171
// Generated by CoffeeScript 1.6.2
(function() {
var $, Spine,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice;
Spine = this.Spine || require('spine');
$ = Spine.$;
Spine.Manager = (function(_super) {
__extends(Manager, _super);
Manager.include(Spine.Events);
function Manager() {
this.controllers = [];
this.bind('change', this.change);
this.add.apply(this, arguments);
}
Manager.prototype.add = function() {
var cont, controllers, _i, _len, _results;
controllers = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
_results = [];
for (_i = 0, _len = controllers.length; _i < _len; _i++) {
cont = controllers[_i];
_results.push(this.addOne(cont));
}
return _results;
};
Manager.prototype.addOne = function(controller) {
var _this = this;
controller.bind('active', function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return _this.trigger.apply(_this, ['change', controller].concat(__slice.call(args)));
});
controller.bind('release', function() {
return _this.controllers.splice(_this.controllers.indexOf(controller), 1);
});
return this.controllers.push(controller);
};
Manager.prototype.deactivate = function() {
return this.trigger.apply(this, ['change', false].concat(__slice.call(arguments)));
};
Manager.prototype.change = function() {
var args, cont, current, _i, _len, _ref, _results;
current = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
_ref = this.controllers;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
cont = _ref[_i];
if (cont === current) {
_results.push(cont.activate.apply(cont, args));
} else {
_results.push(cont.deactivate.apply(cont, args));
}
}
return _results;
};
return Manager;
})(Spine.Module);
Spine.Controller.include({
active: function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (typeof args[0] === 'function') {
this.bind('active', args[0]);
} else {
args.unshift('active');
this.trigger.apply(this, args);
}
return this;
},
isActive: function() {
return this.el.hasClass('active');
},
activate: function() {
this.el.addClass('active');
return this;
},
deactivate: function() {
this.el.removeClass('active');
return this;
}
});
Spine.Stack = (function(_super) {
__extends(Stack, _super);
Stack.prototype.controllers = {};
Stack.prototype.routes = {};
Stack.prototype.className = 'spine stack';
function Stack() {
var key, value, _fn, _ref, _ref1,
_this = this;
Stack.__super__.constructor.apply(this, arguments);
this.manager = new Spine.Manager;
_ref = this.controllers;
for (key in _ref) {
value = _ref[key];
if (this[key] != null) {
throw Error("'@" + key + "' already assigned - choose a different name");
}
this[key] = new value({
stack: this
});
this.add(this[key]);
}
_ref1 = this.routes;
_fn = function(key, value) {
var callback;
if (typeof value === 'function') {
callback = value;
}
callback || (callback = function() {
var _ref2;
return (_ref2 = _this[value]).active.apply(_ref2, arguments);
});
return _this.route(key, callback);
};
for (key in _ref1) {
value = _ref1[key];
_fn(key, value);
}
if (this["default"]) {
this[this["default"]].active();
}
}
Stack.prototype.add = function(controller) {
this.manager.add(controller);
return this.append(controller);
};
return Stack;
})(Spine.Controller);
if (typeof module !== "undefined" && module !== null) {
module.exports = Spine.Manager;
}
if (typeof module !== "undefined" && module !== null) {
module.exports.Stack = Spine.Stack;
}
}).call(this);
/*
//@ sourceMappingURL=manager.map
*/