marionette-rails 1.8.3 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +2 -2
- data/README.md +1 -7
- data/lib/marionette-rails/version.rb +1 -1
- data/vendor/assets/javascripts/backbone.marionette.js +475 -601
- data/vendor/assets/javascripts/backbone.marionette.map +1 -1
- data/vendor/assets/javascripts/backbone.marionette.min.js +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be549b6a0f617426b6a8586e413cf879d8f01b3c
|
4
|
+
data.tar.gz: e3a5d4f39893ac5b5a3aeff7afad72beba5f9bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8180085f77e67ba11b4d357874307dc210b2cdaa1617657ae528eeb81f77f314a53dd6dbf0169537d5d6537aa7129cdf7f974d998c81832b4d10fb56df59218
|
7
|
+
data.tar.gz: 9dd1db3fc379a2e6aaa23b3208c4640d280ec513385b02504d2d0bc1a675f3e62abf2182c13d7ebe000550ff7317e3c038b7cd1e09987705eac35628c5cdbd06
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Godfrey Chan
|
1
|
+
Copyright (c) 2012-2014 Godfrey Chan & Stafford Brunk
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
THE SOFTWARE.
|
19
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ marionette-rails
|
|
5
5
|
|
6
6
|
This gem is a wrapper for Derick Bailey's [Backbone.Marionette](https://github.com/marionettejs/backbone.marionette) library. It vendors the javascript library code for use with Rails' asset pipeline (Rails 3.1+).
|
7
7
|
|
8
|
-
This gem is currently maintained by [@
|
8
|
+
This gem is currently maintained by [@wingrunr21](https://github.com/wingrunr21).
|
9
9
|
|
10
10
|
## Dependencies
|
11
11
|
|
@@ -44,12 +44,6 @@ For bugs in [Backbone.Marionette](https://github.com/marionettejs/backbone.mario
|
|
44
44
|
|
45
45
|
For bugs in this gem distribution, use the [GitHub issue tracker](https://github.com/chancancode/marionette-rails/issues). If you could submit a pull request - that's even better!
|
46
46
|
|
47
|
-
## Donations
|
48
|
-
|
49
|
-
If you're using Marionette and you're finding that it is saving you time and effort, then please consider donating to the upstream [Backbone.Marionette](https://github.com/marionettejs/backbone.marionette) project.
|
50
|
-
|
51
|
-
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7SJHYWJ487SF4)
|
52
|
-
|
53
47
|
## License
|
54
48
|
|
55
49
|
This library is distributed under the MIT license. Please see the LICENSE file.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
// MarionetteJS (Backbone.Marionette)
|
2
2
|
// ----------------------------------
|
3
|
-
// v1.8.
|
3
|
+
// v1.8.8
|
4
4
|
//
|
5
5
|
// Copyright (c)2014 Derick Bailey, Muted Solutions, LLC.
|
6
6
|
// Distributed under MIT license
|
@@ -17,584 +17,459 @@
|
|
17
17
|
*/
|
18
18
|
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
// v0.1.0
|
23
|
-
//
|
24
|
-
// Copyright (c)2014 Derick Bailey, Muted Solutions, LLC.
|
25
|
-
// Distributed under MIT license
|
26
|
-
//
|
27
|
-
// http://github.com/marionettejs/backbone.babysitter
|
28
|
-
|
29
|
-
// Backbone.ChildViewContainer
|
30
|
-
// ---------------------------
|
31
|
-
//
|
32
|
-
// Provide a container to store, retrieve and
|
33
|
-
// shut down child views.
|
34
|
-
|
35
|
-
Backbone.ChildViewContainer = (function(Backbone, _){
|
36
|
-
|
37
|
-
// Container Constructor
|
38
|
-
// ---------------------
|
39
|
-
|
40
|
-
var Container = function(views){
|
41
|
-
this._views = {};
|
42
|
-
this._indexByModel = {};
|
43
|
-
this._indexByCustom = {};
|
44
|
-
this._updateLength();
|
45
|
-
|
46
|
-
_.each(views, this.add, this);
|
47
|
-
};
|
48
|
-
|
49
|
-
// Container Methods
|
50
|
-
// -----------------
|
51
|
-
|
52
|
-
_.extend(Container.prototype, {
|
53
|
-
|
54
|
-
// Add a view to this container. Stores the view
|
55
|
-
// by `cid` and makes it searchable by the model
|
56
|
-
// cid (and model itself). Optionally specify
|
57
|
-
// a custom key to store an retrieve the view.
|
58
|
-
add: function(view, customIndex){
|
59
|
-
var viewCid = view.cid;
|
60
|
-
|
61
|
-
// store the view
|
62
|
-
this._views[viewCid] = view;
|
63
|
-
|
64
|
-
// index it by model
|
65
|
-
if (view.model){
|
66
|
-
this._indexByModel[view.model.cid] = viewCid;
|
67
|
-
}
|
68
|
-
|
69
|
-
// index by custom
|
70
|
-
if (customIndex){
|
71
|
-
this._indexByCustom[customIndex] = viewCid;
|
72
|
-
}
|
73
|
-
|
74
|
-
this._updateLength();
|
75
|
-
return this;
|
76
|
-
},
|
77
|
-
|
78
|
-
// Find a view by the model that was attached to
|
79
|
-
// it. Uses the model's `cid` to find it.
|
80
|
-
findByModel: function(model){
|
81
|
-
return this.findByModelCid(model.cid);
|
82
|
-
},
|
83
|
-
|
84
|
-
// Find a view by the `cid` of the model that was attached to
|
85
|
-
// it. Uses the model's `cid` to find the view `cid` and
|
86
|
-
// retrieve the view using it.
|
87
|
-
findByModelCid: function(modelCid){
|
88
|
-
var viewCid = this._indexByModel[modelCid];
|
89
|
-
return this.findByCid(viewCid);
|
90
|
-
},
|
91
|
-
|
92
|
-
// Find a view by a custom indexer.
|
93
|
-
findByCustom: function(index){
|
94
|
-
var viewCid = this._indexByCustom[index];
|
95
|
-
return this.findByCid(viewCid);
|
96
|
-
},
|
97
|
-
|
98
|
-
// Find by index. This is not guaranteed to be a
|
99
|
-
// stable index.
|
100
|
-
findByIndex: function(index){
|
101
|
-
return _.values(this._views)[index];
|
102
|
-
},
|
103
|
-
|
104
|
-
// retrieve a view by its `cid` directly
|
105
|
-
findByCid: function(cid){
|
106
|
-
return this._views[cid];
|
107
|
-
},
|
108
|
-
|
109
|
-
// Remove a view
|
110
|
-
remove: function(view){
|
111
|
-
var viewCid = view.cid;
|
112
|
-
|
113
|
-
// delete model index
|
114
|
-
if (view.model){
|
115
|
-
delete this._indexByModel[view.model.cid];
|
116
|
-
}
|
117
|
-
|
118
|
-
// delete custom index
|
119
|
-
_.any(this._indexByCustom, function(cid, key) {
|
120
|
-
if (cid === viewCid) {
|
121
|
-
delete this._indexByCustom[key];
|
122
|
-
return true;
|
123
|
-
}
|
124
|
-
}, this);
|
125
|
-
|
126
|
-
// remove the view from the container
|
127
|
-
delete this._views[viewCid];
|
128
|
-
|
129
|
-
// update the length
|
130
|
-
this._updateLength();
|
131
|
-
return this;
|
132
|
-
},
|
133
|
-
|
134
|
-
// Call a method on every view in the container,
|
135
|
-
// passing parameters to the call method one at a
|
136
|
-
// time, like `function.call`.
|
137
|
-
call: function(method){
|
138
|
-
this.apply(method, _.tail(arguments));
|
139
|
-
},
|
20
|
+
var Marionette = (function(global, Backbone, _){
|
21
|
+
"use strict";
|
140
22
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
23
|
+
// Backbone.BabySitter
|
24
|
+
// -------------------
|
25
|
+
// v0.1.4
|
26
|
+
//
|
27
|
+
// Copyright (c)2014 Derick Bailey, Muted Solutions, LLC.
|
28
|
+
// Distributed under MIT license
|
29
|
+
//
|
30
|
+
// http://github.com/marionettejs/backbone.babysitter
|
31
|
+
(function(Backbone, _) {
|
32
|
+
"use strict";
|
33
|
+
var previousChildViewContainer = Backbone.ChildViewContainer;
|
34
|
+
// BabySitter.ChildViewContainer
|
35
|
+
// -----------------------------
|
36
|
+
//
|
37
|
+
// Provide a container to store, retrieve and
|
38
|
+
// shut down child views.
|
39
|
+
Backbone.ChildViewContainer = function(Backbone, _) {
|
40
|
+
// Container Constructor
|
41
|
+
// ---------------------
|
42
|
+
var Container = function(views) {
|
43
|
+
this._views = {};
|
44
|
+
this._indexByModel = {};
|
45
|
+
this._indexByCustom = {};
|
46
|
+
this._updateLength();
|
47
|
+
_.each(views, this.add, this);
|
48
|
+
};
|
49
|
+
// Container Methods
|
50
|
+
// -----------------
|
51
|
+
_.extend(Container.prototype, {
|
52
|
+
// Add a view to this container. Stores the view
|
53
|
+
// by `cid` and makes it searchable by the model
|
54
|
+
// cid (and model itself). Optionally specify
|
55
|
+
// a custom key to store an retrieve the view.
|
56
|
+
add: function(view, customIndex) {
|
57
|
+
var viewCid = view.cid;
|
58
|
+
// store the view
|
59
|
+
this._views[viewCid] = view;
|
60
|
+
// index it by model
|
61
|
+
if (view.model) {
|
62
|
+
this._indexByModel[view.model.cid] = viewCid;
|
63
|
+
}
|
64
|
+
// index by custom
|
65
|
+
if (customIndex) {
|
66
|
+
this._indexByCustom[customIndex] = viewCid;
|
67
|
+
}
|
68
|
+
this._updateLength();
|
69
|
+
return this;
|
70
|
+
},
|
71
|
+
// Find a view by the model that was attached to
|
72
|
+
// it. Uses the model's `cid` to find it.
|
73
|
+
findByModel: function(model) {
|
74
|
+
return this.findByModelCid(model.cid);
|
75
|
+
},
|
76
|
+
// Find a view by the `cid` of the model that was attached to
|
77
|
+
// it. Uses the model's `cid` to find the view `cid` and
|
78
|
+
// retrieve the view using it.
|
79
|
+
findByModelCid: function(modelCid) {
|
80
|
+
var viewCid = this._indexByModel[modelCid];
|
81
|
+
return this.findByCid(viewCid);
|
82
|
+
},
|
83
|
+
// Find a view by a custom indexer.
|
84
|
+
findByCustom: function(index) {
|
85
|
+
var viewCid = this._indexByCustom[index];
|
86
|
+
return this.findByCid(viewCid);
|
87
|
+
},
|
88
|
+
// Find by index. This is not guaranteed to be a
|
89
|
+
// stable index.
|
90
|
+
findByIndex: function(index) {
|
91
|
+
return _.values(this._views)[index];
|
92
|
+
},
|
93
|
+
// retrieve a view by its `cid` directly
|
94
|
+
findByCid: function(cid) {
|
95
|
+
return this._views[cid];
|
96
|
+
},
|
97
|
+
// Remove a view
|
98
|
+
remove: function(view) {
|
99
|
+
var viewCid = view.cid;
|
100
|
+
// delete model index
|
101
|
+
if (view.model) {
|
102
|
+
delete this._indexByModel[view.model.cid];
|
103
|
+
}
|
104
|
+
// delete custom index
|
105
|
+
_.any(this._indexByCustom, function(cid, key) {
|
106
|
+
if (cid === viewCid) {
|
107
|
+
delete this._indexByCustom[key];
|
108
|
+
return true;
|
109
|
+
}
|
110
|
+
}, this);
|
111
|
+
// remove the view from the container
|
112
|
+
delete this._views[viewCid];
|
113
|
+
// update the length
|
114
|
+
this._updateLength();
|
115
|
+
return this;
|
116
|
+
},
|
117
|
+
// Call a method on every view in the container,
|
118
|
+
// passing parameters to the call method one at a
|
119
|
+
// time, like `function.call`.
|
120
|
+
call: function(method) {
|
121
|
+
this.apply(method, _.tail(arguments));
|
122
|
+
},
|
123
|
+
// Apply a method on every view in the container,
|
124
|
+
// passing parameters to the call method one at a
|
125
|
+
// time, like `function.apply`.
|
126
|
+
apply: function(method, args) {
|
127
|
+
_.each(this._views, function(view) {
|
128
|
+
if (_.isFunction(view[method])) {
|
129
|
+
view[method].apply(view, args || []);
|
130
|
+
}
|
131
|
+
});
|
132
|
+
},
|
133
|
+
// Update the `.length` attribute on this container
|
134
|
+
_updateLength: function() {
|
135
|
+
this.length = _.size(this._views);
|
148
136
|
}
|
149
137
|
});
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
138
|
+
// Borrowing this code from Backbone.Collection:
|
139
|
+
// http://backbonejs.org/docs/backbone.html#section-106
|
140
|
+
//
|
141
|
+
// Mix in methods from Underscore, for iteration, and other
|
142
|
+
// collection related features.
|
143
|
+
var methods = [ "forEach", "each", "map", "find", "detect", "filter", "select", "reject", "every", "all", "some", "any", "include", "contains", "invoke", "toArray", "first", "initial", "rest", "last", "without", "isEmpty", "pluck" ];
|
144
|
+
_.each(methods, function(method) {
|
145
|
+
Container.prototype[method] = function() {
|
146
|
+
var views = _.values(this._views);
|
147
|
+
var args = [ views ].concat(_.toArray(arguments));
|
148
|
+
return _[method].apply(_, args);
|
149
|
+
};
|
150
|
+
});
|
151
|
+
// return the public API
|
152
|
+
return Container;
|
153
|
+
}(Backbone, _);
|
154
|
+
Backbone.ChildViewContainer.VERSION = "0.1.4";
|
155
|
+
Backbone.ChildViewContainer.noConflict = function() {
|
156
|
+
Backbone.ChildViewContainer = previousChildViewContainer;
|
157
|
+
return this;
|
158
|
+
};
|
159
|
+
return Backbone.ChildViewContainer;
|
160
|
+
})(Backbone, _);
|
161
|
+
// Backbone.Wreqr (Backbone.Marionette)
|
162
|
+
// ----------------------------------
|
163
|
+
// v1.3.1
|
160
164
|
//
|
161
|
-
//
|
162
|
-
//
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
return
|
165
|
+
// Copyright (c)2014 Derick Bailey, Muted Solutions, LLC.
|
166
|
+
// Distributed under MIT license
|
167
|
+
//
|
168
|
+
// http://github.com/marionettejs/backbone.wreqr
|
169
|
+
(function(Backbone, _) {
|
170
|
+
"use strict";
|
171
|
+
var previousWreqr = Backbone.Wreqr;
|
172
|
+
var Wreqr = Backbone.Wreqr = {};
|
173
|
+
Backbone.Wreqr.VERSION = "1.3.1";
|
174
|
+
Backbone.Wreqr.noConflict = function() {
|
175
|
+
Backbone.Wreqr = previousWreqr;
|
176
|
+
return this;
|
173
177
|
};
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
//
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
//
|
187
|
-
// http://github.com/marionettejs/backbone.wreqr
|
188
|
-
|
189
|
-
|
190
|
-
Backbone.Wreqr = (function(Backbone, Marionette, _){
|
191
|
-
"use strict";
|
192
|
-
var Wreqr = {};
|
193
|
-
|
194
|
-
// Handlers
|
195
|
-
// --------
|
196
|
-
// A registry of functions to call, given a name
|
197
|
-
|
198
|
-
Wreqr.Handlers = (function(Backbone, _){
|
199
|
-
"use strict";
|
200
|
-
|
201
|
-
// Constructor
|
202
|
-
// -----------
|
203
|
-
|
204
|
-
var Handlers = function(options){
|
205
|
-
this.options = options;
|
206
|
-
this._wreqrHandlers = {};
|
207
|
-
|
208
|
-
if (_.isFunction(this.initialize)){
|
209
|
-
this.initialize(options);
|
210
|
-
}
|
211
|
-
};
|
212
|
-
|
213
|
-
Handlers.extend = Backbone.Model.extend;
|
214
|
-
|
215
|
-
// Instance Members
|
216
|
-
// ----------------
|
217
|
-
|
218
|
-
_.extend(Handlers.prototype, Backbone.Events, {
|
219
|
-
|
220
|
-
// Add multiple handlers using an object literal configuration
|
221
|
-
setHandlers: function(handlers){
|
222
|
-
_.each(handlers, function(handler, name){
|
223
|
-
var context = null;
|
224
|
-
|
225
|
-
if (_.isObject(handler) && !_.isFunction(handler)){
|
226
|
-
context = handler.context;
|
227
|
-
handler = handler.callback;
|
178
|
+
// Handlers
|
179
|
+
// --------
|
180
|
+
// A registry of functions to call, given a name
|
181
|
+
Wreqr.Handlers = function(Backbone, _) {
|
182
|
+
"use strict";
|
183
|
+
// Constructor
|
184
|
+
// -----------
|
185
|
+
var Handlers = function(options) {
|
186
|
+
this.options = options;
|
187
|
+
this._wreqrHandlers = {};
|
188
|
+
if (_.isFunction(this.initialize)) {
|
189
|
+
this.initialize(options);
|
228
190
|
}
|
229
|
-
|
230
|
-
this.setHandler(name, handler, context);
|
231
|
-
}, this);
|
232
|
-
},
|
233
|
-
|
234
|
-
// Add a handler for the given name, with an
|
235
|
-
// optional context to run the handler within
|
236
|
-
setHandler: function(name, handler, context){
|
237
|
-
var config = {
|
238
|
-
callback: handler,
|
239
|
-
context: context
|
240
191
|
};
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
192
|
+
Handlers.extend = Backbone.Model.extend;
|
193
|
+
// Instance Members
|
194
|
+
// ----------------
|
195
|
+
_.extend(Handlers.prototype, Backbone.Events, {
|
196
|
+
// Add multiple handlers using an object literal configuration
|
197
|
+
setHandlers: function(handlers) {
|
198
|
+
_.each(handlers, function(handler, name) {
|
199
|
+
var context = null;
|
200
|
+
if (_.isObject(handler) && !_.isFunction(handler)) {
|
201
|
+
context = handler.context;
|
202
|
+
handler = handler.callback;
|
203
|
+
}
|
204
|
+
this.setHandler(name, handler, context);
|
205
|
+
}, this);
|
206
|
+
},
|
207
|
+
// Add a handler for the given name, with an
|
208
|
+
// optional context to run the handler within
|
209
|
+
setHandler: function(name, handler, context) {
|
210
|
+
var config = {
|
211
|
+
callback: handler,
|
212
|
+
context: context
|
213
|
+
};
|
214
|
+
this._wreqrHandlers[name] = config;
|
215
|
+
this.trigger("handler:add", name, handler, context);
|
216
|
+
},
|
217
|
+
// Determine whether or not a handler is registered
|
218
|
+
hasHandler: function(name) {
|
219
|
+
return !!this._wreqrHandlers[name];
|
220
|
+
},
|
221
|
+
// Get the currently registered handler for
|
222
|
+
// the specified name. Throws an exception if
|
223
|
+
// no handler is found.
|
224
|
+
getHandler: function(name) {
|
225
|
+
var config = this._wreqrHandlers[name];
|
226
|
+
if (!config) {
|
227
|
+
return;
|
228
|
+
}
|
229
|
+
return function() {
|
230
|
+
var args = Array.prototype.slice.apply(arguments);
|
231
|
+
return config.callback.apply(config.context, args);
|
232
|
+
};
|
233
|
+
},
|
234
|
+
// Remove a handler for the specified name
|
235
|
+
removeHandler: function(name) {
|
236
|
+
delete this._wreqrHandlers[name];
|
237
|
+
},
|
238
|
+
// Remove all handlers from this registry
|
239
|
+
removeAllHandlers: function() {
|
240
|
+
this._wreqrHandlers = {};
|
241
|
+
}
|
242
|
+
});
|
243
|
+
return Handlers;
|
244
|
+
}(Backbone, _);
|
245
|
+
// Wreqr.CommandStorage
|
246
|
+
// --------------------
|
247
|
+
//
|
248
|
+
// Store and retrieve commands for execution.
|
249
|
+
Wreqr.CommandStorage = function() {
|
250
|
+
"use strict";
|
251
|
+
// Constructor function
|
252
|
+
var CommandStorage = function(options) {
|
253
|
+
this.options = options;
|
254
|
+
this._commands = {};
|
255
|
+
if (_.isFunction(this.initialize)) {
|
256
|
+
this.initialize(options);
|
257
|
+
}
|
265
258
|
};
|
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
|
-
// Instance methods
|
300
|
-
_.extend(CommandStorage.prototype, Backbone.Events, {
|
301
|
-
|
302
|
-
// Get an object literal by command name, that contains
|
303
|
-
// the `commandName` and the `instances` of all commands
|
304
|
-
// represented as an array of arguments to process
|
305
|
-
getCommands: function(commandName){
|
306
|
-
var commands = this._commands[commandName];
|
307
|
-
|
308
|
-
// we don't have it, so add it
|
309
|
-
if (!commands){
|
310
|
-
|
311
|
-
// build the configuration
|
312
|
-
commands = {
|
313
|
-
command: commandName,
|
314
|
-
instances: []
|
315
|
-
};
|
316
|
-
|
317
|
-
// store it
|
318
|
-
this._commands[commandName] = commands;
|
319
|
-
}
|
320
|
-
|
321
|
-
return commands;
|
322
|
-
},
|
323
|
-
|
324
|
-
// Add a command by name, to the storage and store the
|
325
|
-
// args for the command
|
326
|
-
addCommand: function(commandName, args){
|
327
|
-
var command = this.getCommands(commandName);
|
328
|
-
command.instances.push(args);
|
329
|
-
},
|
330
|
-
|
331
|
-
// Clear all commands for the given `commandName`
|
332
|
-
clearCommands: function(commandName){
|
333
|
-
var command = this.getCommands(commandName);
|
334
|
-
command.instances = [];
|
335
|
-
}
|
336
|
-
});
|
337
|
-
|
338
|
-
return CommandStorage;
|
339
|
-
})();
|
340
|
-
|
341
|
-
// Wreqr.Commands
|
342
|
-
// --------------
|
343
|
-
//
|
344
|
-
// A simple command pattern implementation. Register a command
|
345
|
-
// handler and execute it.
|
346
|
-
Wreqr.Commands = (function(Wreqr){
|
347
|
-
"use strict";
|
348
|
-
|
349
|
-
return Wreqr.Handlers.extend({
|
350
|
-
// default storage type
|
351
|
-
storageType: Wreqr.CommandStorage,
|
352
|
-
|
353
|
-
constructor: function(options){
|
354
|
-
this.options = options || {};
|
355
|
-
|
356
|
-
this._initializeStorage(this.options);
|
357
|
-
this.on("handler:add", this._executeCommands, this);
|
358
|
-
|
359
|
-
var args = Array.prototype.slice.call(arguments);
|
360
|
-
Wreqr.Handlers.prototype.constructor.apply(this, args);
|
361
|
-
},
|
362
|
-
|
363
|
-
// Execute a named command with the supplied args
|
364
|
-
execute: function(name, args){
|
365
|
-
name = arguments[0];
|
366
|
-
args = Array.prototype.slice.call(arguments, 1);
|
367
|
-
|
368
|
-
if (this.hasHandler(name)){
|
369
|
-
this.getHandler(name).apply(this, args);
|
370
|
-
} else {
|
371
|
-
this.storage.addCommand(name, args);
|
372
|
-
}
|
373
|
-
|
374
|
-
},
|
375
|
-
|
376
|
-
// Internal method to handle bulk execution of stored commands
|
377
|
-
_executeCommands: function(name, handler, context){
|
378
|
-
var command = this.storage.getCommands(name);
|
379
|
-
|
380
|
-
// loop through and execute all the stored command instances
|
381
|
-
_.each(command.instances, function(args){
|
382
|
-
handler.apply(context, args);
|
259
|
+
// Instance methods
|
260
|
+
_.extend(CommandStorage.prototype, Backbone.Events, {
|
261
|
+
// Get an object literal by command name, that contains
|
262
|
+
// the `commandName` and the `instances` of all commands
|
263
|
+
// represented as an array of arguments to process
|
264
|
+
getCommands: function(commandName) {
|
265
|
+
var commands = this._commands[commandName];
|
266
|
+
// we don't have it, so add it
|
267
|
+
if (!commands) {
|
268
|
+
// build the configuration
|
269
|
+
commands = {
|
270
|
+
command: commandName,
|
271
|
+
instances: []
|
272
|
+
};
|
273
|
+
// store it
|
274
|
+
this._commands[commandName] = commands;
|
275
|
+
}
|
276
|
+
return commands;
|
277
|
+
},
|
278
|
+
// Add a command by name, to the storage and store the
|
279
|
+
// args for the command
|
280
|
+
addCommand: function(commandName, args) {
|
281
|
+
var command = this.getCommands(commandName);
|
282
|
+
command.instances.push(args);
|
283
|
+
},
|
284
|
+
// Clear all commands for the given `commandName`
|
285
|
+
clearCommands: function(commandName) {
|
286
|
+
var command = this.getCommands(commandName);
|
287
|
+
command.instances = [];
|
288
|
+
}
|
383
289
|
});
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
//
|
389
|
-
//
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
//
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
'removeAllHandlers'
|
568
|
-
],
|
569
|
-
|
570
|
-
reqres: [
|
571
|
-
'request',
|
572
|
-
'setHandler',
|
573
|
-
'setHandlers',
|
574
|
-
'removeHandler',
|
575
|
-
'removeAllHandlers'
|
576
|
-
]
|
577
|
-
};
|
578
|
-
|
579
|
-
var proxyMethod = function(radio, system, method) {
|
580
|
-
return function(channelName) {
|
581
|
-
var messageSystem = radio._getChannel(channelName)[system];
|
582
|
-
var args = Array.prototype.slice.call(arguments, 1);
|
583
|
-
|
584
|
-
messageSystem[method].apply(messageSystem, args);
|
585
|
-
};
|
586
|
-
};
|
587
|
-
|
588
|
-
return new Radio();
|
589
|
-
|
590
|
-
})(Wreqr);
|
591
|
-
|
592
|
-
|
593
|
-
return Wreqr;
|
594
|
-
})(Backbone, Backbone.Marionette, _);
|
595
|
-
|
596
|
-
var Marionette = (function(global, Backbone, _){
|
597
|
-
"use strict";
|
290
|
+
return CommandStorage;
|
291
|
+
}();
|
292
|
+
// Wreqr.Commands
|
293
|
+
// --------------
|
294
|
+
//
|
295
|
+
// A simple command pattern implementation. Register a command
|
296
|
+
// handler and execute it.
|
297
|
+
Wreqr.Commands = function(Wreqr) {
|
298
|
+
"use strict";
|
299
|
+
return Wreqr.Handlers.extend({
|
300
|
+
// default storage type
|
301
|
+
storageType: Wreqr.CommandStorage,
|
302
|
+
constructor: function(options) {
|
303
|
+
this.options = options || {};
|
304
|
+
this._initializeStorage(this.options);
|
305
|
+
this.on("handler:add", this._executeCommands, this);
|
306
|
+
var args = Array.prototype.slice.call(arguments);
|
307
|
+
Wreqr.Handlers.prototype.constructor.apply(this, args);
|
308
|
+
},
|
309
|
+
// Execute a named command with the supplied args
|
310
|
+
execute: function(name, args) {
|
311
|
+
name = arguments[0];
|
312
|
+
args = Array.prototype.slice.call(arguments, 1);
|
313
|
+
if (this.hasHandler(name)) {
|
314
|
+
this.getHandler(name).apply(this, args);
|
315
|
+
} else {
|
316
|
+
this.storage.addCommand(name, args);
|
317
|
+
}
|
318
|
+
},
|
319
|
+
// Internal method to handle bulk execution of stored commands
|
320
|
+
_executeCommands: function(name, handler, context) {
|
321
|
+
var command = this.storage.getCommands(name);
|
322
|
+
// loop through and execute all the stored command instances
|
323
|
+
_.each(command.instances, function(args) {
|
324
|
+
handler.apply(context, args);
|
325
|
+
});
|
326
|
+
this.storage.clearCommands(name);
|
327
|
+
},
|
328
|
+
// Internal method to initialize storage either from the type's
|
329
|
+
// `storageType` or the instance `options.storageType`.
|
330
|
+
_initializeStorage: function(options) {
|
331
|
+
var storage;
|
332
|
+
var StorageType = options.storageType || this.storageType;
|
333
|
+
if (_.isFunction(StorageType)) {
|
334
|
+
storage = new StorageType();
|
335
|
+
} else {
|
336
|
+
storage = StorageType;
|
337
|
+
}
|
338
|
+
this.storage = storage;
|
339
|
+
}
|
340
|
+
});
|
341
|
+
}(Wreqr);
|
342
|
+
// Wreqr.RequestResponse
|
343
|
+
// ---------------------
|
344
|
+
//
|
345
|
+
// A simple request/response implementation. Register a
|
346
|
+
// request handler, and return a response from it
|
347
|
+
Wreqr.RequestResponse = function(Wreqr) {
|
348
|
+
"use strict";
|
349
|
+
return Wreqr.Handlers.extend({
|
350
|
+
request: function() {
|
351
|
+
var name = arguments[0];
|
352
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
353
|
+
if (this.hasHandler(name)) {
|
354
|
+
return this.getHandler(name).apply(this, args);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
});
|
358
|
+
}(Wreqr);
|
359
|
+
// Event Aggregator
|
360
|
+
// ----------------
|
361
|
+
// A pub-sub object that can be used to decouple various parts
|
362
|
+
// of an application through event-driven architecture.
|
363
|
+
Wreqr.EventAggregator = function(Backbone, _) {
|
364
|
+
"use strict";
|
365
|
+
var EA = function() {};
|
366
|
+
// Copy the `extend` function used by Backbone's classes
|
367
|
+
EA.extend = Backbone.Model.extend;
|
368
|
+
// Copy the basic Backbone.Events on to the event aggregator
|
369
|
+
_.extend(EA.prototype, Backbone.Events);
|
370
|
+
return EA;
|
371
|
+
}(Backbone, _);
|
372
|
+
// Wreqr.Channel
|
373
|
+
// --------------
|
374
|
+
//
|
375
|
+
// An object that wraps the three messaging systems:
|
376
|
+
// EventAggregator, RequestResponse, Commands
|
377
|
+
Wreqr.Channel = function(Wreqr) {
|
378
|
+
"use strict";
|
379
|
+
var Channel = function(channelName) {
|
380
|
+
this.vent = new Backbone.Wreqr.EventAggregator();
|
381
|
+
this.reqres = new Backbone.Wreqr.RequestResponse();
|
382
|
+
this.commands = new Backbone.Wreqr.Commands();
|
383
|
+
this.channelName = channelName;
|
384
|
+
};
|
385
|
+
_.extend(Channel.prototype, {
|
386
|
+
// Remove all handlers from the messaging systems of this channel
|
387
|
+
reset: function() {
|
388
|
+
this.vent.off();
|
389
|
+
this.vent.stopListening();
|
390
|
+
this.reqres.removeAllHandlers();
|
391
|
+
this.commands.removeAllHandlers();
|
392
|
+
return this;
|
393
|
+
},
|
394
|
+
// Connect a hash of events; one for each messaging system
|
395
|
+
connectEvents: function(hash, context) {
|
396
|
+
this._connect("vent", hash, context);
|
397
|
+
return this;
|
398
|
+
},
|
399
|
+
connectCommands: function(hash, context) {
|
400
|
+
this._connect("commands", hash, context);
|
401
|
+
return this;
|
402
|
+
},
|
403
|
+
connectRequests: function(hash, context) {
|
404
|
+
this._connect("reqres", hash, context);
|
405
|
+
return this;
|
406
|
+
},
|
407
|
+
// Attach the handlers to a given message system `type`
|
408
|
+
_connect: function(type, hash, context) {
|
409
|
+
if (!hash) {
|
410
|
+
return;
|
411
|
+
}
|
412
|
+
context = context || this;
|
413
|
+
var method = type === "vent" ? "on" : "setHandler";
|
414
|
+
_.each(hash, function(fn, eventName) {
|
415
|
+
this[type][method](eventName, _.bind(fn, context));
|
416
|
+
}, this);
|
417
|
+
}
|
418
|
+
});
|
419
|
+
return Channel;
|
420
|
+
}(Wreqr);
|
421
|
+
// Wreqr.Radio
|
422
|
+
// --------------
|
423
|
+
//
|
424
|
+
// An object that lets you communicate with many channels.
|
425
|
+
Wreqr.radio = function(Wreqr) {
|
426
|
+
"use strict";
|
427
|
+
var Radio = function() {
|
428
|
+
this._channels = {};
|
429
|
+
this.vent = {};
|
430
|
+
this.commands = {};
|
431
|
+
this.reqres = {};
|
432
|
+
this._proxyMethods();
|
433
|
+
};
|
434
|
+
_.extend(Radio.prototype, {
|
435
|
+
channel: function(channelName) {
|
436
|
+
if (!channelName) {
|
437
|
+
throw new Error("Channel must receive a name");
|
438
|
+
}
|
439
|
+
return this._getChannel(channelName);
|
440
|
+
},
|
441
|
+
_getChannel: function(channelName) {
|
442
|
+
var channel = this._channels[channelName];
|
443
|
+
if (!channel) {
|
444
|
+
channel = new Wreqr.Channel(channelName);
|
445
|
+
this._channels[channelName] = channel;
|
446
|
+
}
|
447
|
+
return channel;
|
448
|
+
},
|
449
|
+
_proxyMethods: function() {
|
450
|
+
_.each([ "vent", "commands", "reqres" ], function(system) {
|
451
|
+
_.each(messageSystems[system], function(method) {
|
452
|
+
this[system][method] = proxyMethod(this, system, method);
|
453
|
+
}, this);
|
454
|
+
}, this);
|
455
|
+
}
|
456
|
+
});
|
457
|
+
var messageSystems = {
|
458
|
+
vent: [ "on", "off", "trigger", "once", "stopListening", "listenTo", "listenToOnce" ],
|
459
|
+
commands: [ "execute", "setHandler", "setHandlers", "removeHandler", "removeAllHandlers" ],
|
460
|
+
reqres: [ "request", "setHandler", "setHandlers", "removeHandler", "removeAllHandlers" ]
|
461
|
+
};
|
462
|
+
var proxyMethod = function(radio, system, method) {
|
463
|
+
return function(channelName) {
|
464
|
+
var messageSystem = radio._getChannel(channelName)[system];
|
465
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
466
|
+
return messageSystem[method].apply(messageSystem, args);
|
467
|
+
};
|
468
|
+
};
|
469
|
+
return new Radio();
|
470
|
+
}(Wreqr);
|
471
|
+
return Backbone.Wreqr;
|
472
|
+
})(Backbone, _);
|
598
473
|
|
599
474
|
// Define and export the Marionette namespace
|
600
475
|
var Marionette = {};
|
@@ -1089,7 +964,12 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
|
|
1089
964
|
|
1090
965
|
view.render();
|
1091
966
|
Marionette.triggerMethod.call(this, "before:show", view);
|
1092
|
-
|
967
|
+
|
968
|
+
if (_.isFunction(view.triggerMethod)) {
|
969
|
+
view.triggerMethod("before:show");
|
970
|
+
} else {
|
971
|
+
Marionette.triggerMethod.call(view, "before:show");
|
972
|
+
}
|
1093
973
|
|
1094
974
|
if (isDifferentView || isViewClosed) {
|
1095
975
|
this.open(view);
|
@@ -1098,7 +978,14 @@ _.extend(Marionette.Region.prototype, Backbone.Events, {
|
|
1098
978
|
this.currentView = view;
|
1099
979
|
|
1100
980
|
Marionette.triggerMethod.call(this, "show", view);
|
1101
|
-
|
981
|
+
|
982
|
+
if (_.isFunction(view.triggerMethod)) {
|
983
|
+
view.triggerMethod("show");
|
984
|
+
} else {
|
985
|
+
Marionette.triggerMethod.call(view, "show");
|
986
|
+
}
|
987
|
+
|
988
|
+
return this;
|
1102
989
|
},
|
1103
990
|
|
1104
991
|
ensureEl: function(){
|
@@ -1729,7 +1616,11 @@ Marionette.CollectionView = Marionette.View.extend({
|
|
1729
1616
|
_triggerShowBufferedChildren: function () {
|
1730
1617
|
if (this._isShown) {
|
1731
1618
|
_.each(this._bufferedChildren, function (child) {
|
1732
|
-
|
1619
|
+
if (_.isFunction(child.triggerMethod)) {
|
1620
|
+
child.triggerMethod('show');
|
1621
|
+
} else {
|
1622
|
+
Marionette.triggerMethod.call(child, 'show');
|
1623
|
+
}
|
1733
1624
|
});
|
1734
1625
|
this._bufferedChildren = [];
|
1735
1626
|
}
|
@@ -1757,7 +1648,11 @@ Marionette.CollectionView = Marionette.View.extend({
|
|
1757
1648
|
// of child views is called.
|
1758
1649
|
onShowCalled: function(){
|
1759
1650
|
this.children.each(function(child){
|
1760
|
-
|
1651
|
+
if (_.isFunction(child.triggerMethod)) {
|
1652
|
+
child.triggerMethod('show');
|
1653
|
+
} else {
|
1654
|
+
Marionette.triggerMethod.call(child, 'show');
|
1655
|
+
}
|
1761
1656
|
});
|
1762
1657
|
},
|
1763
1658
|
|
@@ -1883,7 +1778,11 @@ Marionette.CollectionView = Marionette.View.extend({
|
|
1883
1778
|
// call the "show" method if the collection view
|
1884
1779
|
// has already been shown
|
1885
1780
|
if (this._isShown && !this.isBuffering){
|
1886
|
-
|
1781
|
+
if (_.isFunction(view.triggerMethod)) {
|
1782
|
+
view.triggerMethod('show');
|
1783
|
+
} else {
|
1784
|
+
Marionette.triggerMethod.call(view, 'show');
|
1785
|
+
}
|
1887
1786
|
}
|
1888
1787
|
|
1889
1788
|
// this view was added
|
@@ -2397,7 +2296,6 @@ Marionette.Behaviors = (function(Marionette, _) {
|
|
2397
2296
|
Behaviors.wrap(view, this.behaviors, [
|
2398
2297
|
'bindUIElements', 'unbindUIElements',
|
2399
2298
|
'delegateEvents', 'undelegateEvents',
|
2400
|
-
'onShow', 'onClose',
|
2401
2299
|
'behaviorEvents', 'triggerMethod',
|
2402
2300
|
'setElement', 'close'
|
2403
2301
|
]);
|
@@ -2426,30 +2324,6 @@ Marionette.Behaviors = (function(Marionette, _) {
|
|
2426
2324
|
_.invoke(behaviors, 'close', args);
|
2427
2325
|
},
|
2428
2326
|
|
2429
|
-
onShow: function(onShow, behaviors) {
|
2430
|
-
var args = _.tail(arguments, 2);
|
2431
|
-
|
2432
|
-
_.each(behaviors, function(b) {
|
2433
|
-
Marionette.triggerMethod.apply(b, ["show"].concat(args));
|
2434
|
-
});
|
2435
|
-
|
2436
|
-
if (_.isFunction(onShow)) {
|
2437
|
-
onShow.apply(this, args);
|
2438
|
-
}
|
2439
|
-
},
|
2440
|
-
|
2441
|
-
onClose: function(onClose, behaviors){
|
2442
|
-
var args = _.tail(arguments, 2);
|
2443
|
-
|
2444
|
-
_.each(behaviors, function(b) {
|
2445
|
-
Marionette.triggerMethod.apply(b, ["close"].concat(args));
|
2446
|
-
});
|
2447
|
-
|
2448
|
-
if (_.isFunction(onClose)) {
|
2449
|
-
onClose.apply(this, args);
|
2450
|
-
}
|
2451
|
-
},
|
2452
|
-
|
2453
2327
|
bindUIElements: function(bindUIElements, behaviors) {
|
2454
2328
|
bindUIElements.apply(this);
|
2455
2329
|
_.invoke(behaviors, bindUIElements);
|
@@ -2495,7 +2369,7 @@ Marionette.Behaviors = (function(Marionette, _) {
|
|
2495
2369
|
|
2496
2370
|
_.each(behaviors, function(b, i) {
|
2497
2371
|
var _events = {};
|
2498
|
-
var behaviorEvents = _.result(b, 'events') || {};
|
2372
|
+
var behaviorEvents = _.clone(_.result(b, 'events')) || {};
|
2499
2373
|
var behaviorUI = _.result(b, 'ui');
|
2500
2374
|
|
2501
2375
|
// Construct an internal UI hash first using
|