Skip to content

Commit 0b29de7

Browse files
committed
Merge pull request #744 from marionettejs/v1.2.0
V1.2.0 release
2 parents fcb1484 + b8004d7 commit 0b29de7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+595
-351
lines changed

changelog.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### v1.2.0 [view commit logs](https://github.com/marionettejs/backbone.marionette/compare/v1.1.0...v1.2.0)
2+
* Update Backbone to [1.1.0](https://github.com/jashkenas/backbone/compare/1.0.0...1.1.0)
3+
4+
* Views
5+
* added the ability to customize the behavior of `triggers` preventDefault and stopPropagation
6+
7+
* Collection View / CompositeView
8+
* added the ability to specifiy `getEmptyView` for dynamic `emptyView` lookups
9+
110
### v1.1 [view commit logs](https://github.com/marionettejs/backbone.marionette/compare/v1.0.4...v1.1.0)
211

312
* Marionette.View / All Views
@@ -191,7 +200,7 @@
191200
* Marionette.addEventBinder
192201
* **BREAKING:** This function will mix in Backbone.Events to the target object if it does not exist
193202
* **BREAKING:** This function will alter the `listenTo` method of the target to accept a `context` parameter as the 4th parameter of the method
194-
203+
195204
* All Views, Controller, etc
196205
* **BREAKING:** Backbone.EventBinder is no longer mixed in
197206
* **BREAKING:** See 'EventBinder -> EventAggregator' changes regarding method names to use for binding / unbinding events
@@ -678,7 +687,7 @@
678687
* Added `Marionette.View` object, to contain a few basic parts of every Marionette view
679688
* Added `Marionette.Renderer` object, to handle template rendering
680689
* Views correctly trigger the "close" events before unbinding event subscribers
681-
* Additional `CollectionView` changes:
690+
* Additional `CollectionView` changes:
682691
* Extracted `getItemView` method to retrieve the `itemView` type, either from `this.itemView` or `this.options.itemView`
683692
* Extracted `buildItemView` method to build each item's view
684693
* Renamed `removeChildView` to `removeItemView` to make the language consistent
@@ -791,7 +800,7 @@
791800

792801
#### v0.4.5
793802

794-
* CollectionView closes existing child views before re-rendering itself, when "reset"
803+
* CollectionView closes existing child views before re-rendering itself, when "reset"
795804
event of collection is triggered
796805
* CollectionView now has "initialEvents" method which configures it's initial events
797806
* ItemView now has "initialEvents" method which configures it's initial events
@@ -827,7 +836,7 @@ event of collection is triggered
827836
* **BREAKING:** Rewrote the template manager to be async-template loading friendly
828837
* **BREAKING:** Dropping support for Backbone v0.5.3 and below
829838
* Added `Marionette.Callbacks` to manage a collection of callbacks in an async-friendly way
830-
* Guarantee the execution of app initializer functions, even if they are added after the app
839+
* Guarantee the execution of app initializer functions, even if they are added after the app
831840
has been started.
832841
* App triggers "start" event after initializers and initializer events
833842
* Updated to Backbone v0.9.1

docs/marionette.collectionview.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ Backbone.Marionette.CollectionView.extend({
143143
});
144144
```
145145

146+
Or, if you need the `emptyView`'s type chosen dynamically, specify `getEmptyView`:
147+
148+
```js
149+
Backbone.Marionette.CollectionView.extend({
150+
// ...
151+
152+
getEmptyView: function() {
153+
// custom logic
154+
return NoItemsView;
155+
}
156+
```
157+
146158
This will render the `emptyView` and display the message that needs to
147159
be displayed when there are no items.
148160

docs/marionette.view.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ view.$(".do-something").trigger("click");
158158

159159
The result of this is an alert box that says, "I DID IT!"
160160

161+
By default all triggers are stopped with `preventDefault` and `stopPropagation` methods. But you can manually configure the triggers using hash instead of event name. Example below triggers an event and prevents default browser behaviour using `preventDefault` method.
162+
```js
163+
Backbone.Marionette.CompositeView.extend({
164+
triggers: {
165+
"click .do-something": {
166+
event: "something:do:it",
167+
preventDefault: true,
168+
stopPropagation: false // this param is optional and will default to false
169+
}
170+
}
171+
});
172+
```
173+
161174
You can also specify the `triggers` as a function that
162175
returns a hash of trigger configurations
163176

lib/backbone.marionette.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MarionetteJS (Backbone.Marionette)
22
// ----------------------------------
3-
// v1.1.0
3+
// v1.2.0
44
//
55
// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
66
// Distributed under MIT license
@@ -1202,18 +1202,19 @@ Marionette.Renderer = {
12021202
// The core view type that other Marionette views extend from.
12031203
Marionette.View = Backbone.View.extend({
12041204

1205-
constructor: function(){
1205+
constructor: function(options){
12061206
_.bindAll(this, "render");
12071207

12081208
var args = Array.prototype.slice.apply(arguments);
12091209
Backbone.View.prototype.constructor.apply(this, args);
1210+
this.options = options;
12101211

12111212
Marionette.MonitorDOMRefresh(this);
12121213
this.listenTo(this, "show", this.onShowCalled, this);
12131214
},
12141215

12151216
// import the "triggerMethod" to trigger events with corresponding
1216-
// methods if the method exists
1217+
// methods if the method exists
12171218
triggerMethod: Marionette.triggerMethod,
12181219

12191220
// Get the template for this view
@@ -1252,12 +1253,23 @@ Marionette.View = Backbone.View.extend({
12521253
// action and stop propagation of DOM events
12531254
_.each(triggers, function(value, key){
12541255

1256+
var hasOptions = _.isObject(value);
1257+
var eventName = hasOptions ? value.event : value;
1258+
12551259
// build the event handler function for the DOM event
12561260
triggerEvents[key] = function(e){
12571261

12581262
// stop the event in its tracks
1259-
if (e && e.preventDefault){ e.preventDefault(); }
1260-
if (e && e.stopPropagation){ e.stopPropagation(); }
1263+
if (e) {
1264+
var prevent = e.preventDefault;
1265+
var stop = e.stopPropagation;
1266+
1267+
var shouldPrevent = hasOptions ? value.preventDefault : prevent;
1268+
var shouldStop = hasOptions ? value.stopPropagation : stop;
1269+
1270+
if (shouldPrevent && prevent) { prevent(); }
1271+
if (shouldStop && stop) { stop(); }
1272+
}
12611273

12621274
// build the args for the event
12631275
var args = {
@@ -1267,15 +1279,15 @@ Marionette.View = Backbone.View.extend({
12671279
};
12681280

12691281
// trigger the event
1270-
this.triggerMethod(value, args);
1282+
this.triggerMethod(eventName, args);
12711283
};
12721284

12731285
}, this);
12741286

12751287
return triggerEvents;
12761288
},
12771289

1278-
// Overriding Backbone.View's delegateEvents to handle
1290+
// Overriding Backbone.View's delegateEvents to handle
12791291
// the `triggers`, `modelEvents`, and `collectionEvents` configuration
12801292
delegateEvents: function(events){
12811293
this._delegateDOMEvents(events);
@@ -1545,7 +1557,7 @@ Marionette.CollectionView = Marionette.View.extend({
15451557
// a collection of item views, when the collection is
15461558
// empty
15471559
showEmptyView: function(){
1548-
var EmptyView = Marionette.getOption(this, "emptyView");
1560+
var EmptyView = this.getEmptyView();
15491561

15501562
if (EmptyView && !this._showingEmptyView){
15511563
this._showingEmptyView = true;
@@ -1564,6 +1576,11 @@ Marionette.CollectionView = Marionette.View.extend({
15641576
}
15651577
},
15661578

1579+
// Retrieve the empty view type
1580+
getEmptyView: function(){
1581+
return Marionette.getOption(this, "emptyView");
1582+
},
1583+
15671584
// Retrieve the itemView type, either from `this.options.itemView`
15681585
// or from the `itemView` in the object definition. The "options"
15691586
// takes precedence.

lib/backbone.marionette.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/backbone.marionette.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/amd/backbone.marionette.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MarionetteJS (Backbone.Marionette)
22
// ----------------------------------
3-
// v1.1.0
3+
// v1.2.0
44
//
55
// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
66
// Distributed under MIT license
@@ -794,18 +794,19 @@ Marionette.Renderer = {
794794
// The core view type that other Marionette views extend from.
795795
Marionette.View = Backbone.View.extend({
796796

797-
constructor: function(){
797+
constructor: function(options){
798798
_.bindAll(this, "render");
799799

800800
var args = Array.prototype.slice.apply(arguments);
801801
Backbone.View.prototype.constructor.apply(this, args);
802+
this.options = options;
802803

803804
Marionette.MonitorDOMRefresh(this);
804805
this.listenTo(this, "show", this.onShowCalled, this);
805806
},
806807

807808
// import the "triggerMethod" to trigger events with corresponding
808-
// methods if the method exists
809+
// methods if the method exists
809810
triggerMethod: Marionette.triggerMethod,
810811

811812
// Get the template for this view
@@ -844,12 +845,23 @@ Marionette.View = Backbone.View.extend({
844845
// action and stop propagation of DOM events
845846
_.each(triggers, function(value, key){
846847

848+
var hasOptions = _.isObject(value);
849+
var eventName = hasOptions ? value.event : value;
850+
847851
// build the event handler function for the DOM event
848852
triggerEvents[key] = function(e){
849853

850854
// stop the event in its tracks
851-
if (e && e.preventDefault){ e.preventDefault(); }
852-
if (e && e.stopPropagation){ e.stopPropagation(); }
855+
if (e) {
856+
var prevent = e.preventDefault;
857+
var stop = e.stopPropagation;
858+
859+
var shouldPrevent = hasOptions ? value.preventDefault : prevent;
860+
var shouldStop = hasOptions ? value.stopPropagation : stop;
861+
862+
if (shouldPrevent && prevent) { prevent(); }
863+
if (shouldStop && stop) { stop(); }
864+
}
853865

854866
// build the args for the event
855867
var args = {
@@ -859,15 +871,15 @@ Marionette.View = Backbone.View.extend({
859871
};
860872

861873
// trigger the event
862-
this.triggerMethod(value, args);
874+
this.triggerMethod(eventName, args);
863875
};
864876

865877
}, this);
866878

867879
return triggerEvents;
868880
},
869881

870-
// Overriding Backbone.View's delegateEvents to handle
882+
// Overriding Backbone.View's delegateEvents to handle
871883
// the `triggers`, `modelEvents`, and `collectionEvents` configuration
872884
delegateEvents: function(events){
873885
this._delegateDOMEvents(events);
@@ -1137,7 +1149,7 @@ Marionette.CollectionView = Marionette.View.extend({
11371149
// a collection of item views, when the collection is
11381150
// empty
11391151
showEmptyView: function(){
1140-
var EmptyView = Marionette.getOption(this, "emptyView");
1152+
var EmptyView = this.getEmptyView();
11411153

11421154
if (EmptyView && !this._showingEmptyView){
11431155
this._showingEmptyView = true;
@@ -1156,6 +1168,11 @@ Marionette.CollectionView = Marionette.View.extend({
11561168
}
11571169
},
11581170

1171+
// Retrieve the empty view type
1172+
getEmptyView: function(){
1173+
return Marionette.getOption(this, "emptyView");
1174+
},
1175+
11591176
// Retrieve the itemView type, either from `this.options.itemView`
11601177
// or from the `itemView` in the object definition. The "options"
11611178
// takes precedence.

lib/core/amd/backbone.marionette.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/backbone.marionette.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,18 +758,19 @@ Marionette.Renderer = {
758758
// The core view type that other Marionette views extend from.
759759
Marionette.View = Backbone.View.extend({
760760

761-
constructor: function(){
761+
constructor: function(options){
762762
_.bindAll(this, "render");
763763

764764
var args = Array.prototype.slice.apply(arguments);
765765
Backbone.View.prototype.constructor.apply(this, args);
766+
this.options = options;
766767

767768
Marionette.MonitorDOMRefresh(this);
768769
this.listenTo(this, "show", this.onShowCalled, this);
769770
},
770771

771772
// import the "triggerMethod" to trigger events with corresponding
772-
// methods if the method exists
773+
// methods if the method exists
773774
triggerMethod: Marionette.triggerMethod,
774775

775776
// Get the template for this view
@@ -808,12 +809,23 @@ Marionette.View = Backbone.View.extend({
808809
// action and stop propagation of DOM events
809810
_.each(triggers, function(value, key){
810811

812+
var hasOptions = _.isObject(value);
813+
var eventName = hasOptions ? value.event : value;
814+
811815
// build the event handler function for the DOM event
812816
triggerEvents[key] = function(e){
813817

814818
// stop the event in its tracks
815-
if (e && e.preventDefault){ e.preventDefault(); }
816-
if (e && e.stopPropagation){ e.stopPropagation(); }
819+
if (e) {
820+
var prevent = e.preventDefault;
821+
var stop = e.stopPropagation;
822+
823+
var shouldPrevent = hasOptions ? value.preventDefault : prevent;
824+
var shouldStop = hasOptions ? value.stopPropagation : stop;
825+
826+
if (shouldPrevent && prevent) { prevent(); }
827+
if (shouldStop && stop) { stop(); }
828+
}
817829

818830
// build the args for the event
819831
var args = {
@@ -823,15 +835,15 @@ Marionette.View = Backbone.View.extend({
823835
};
824836

825837
// trigger the event
826-
this.triggerMethod(value, args);
838+
this.triggerMethod(eventName, args);
827839
};
828840

829841
}, this);
830842

831843
return triggerEvents;
832844
},
833845

834-
// Overriding Backbone.View's delegateEvents to handle
846+
// Overriding Backbone.View's delegateEvents to handle
835847
// the `triggers`, `modelEvents`, and `collectionEvents` configuration
836848
delegateEvents: function(events){
837849
this._delegateDOMEvents(events);
@@ -1101,7 +1113,7 @@ Marionette.CollectionView = Marionette.View.extend({
11011113
// a collection of item views, when the collection is
11021114
// empty
11031115
showEmptyView: function(){
1104-
var EmptyView = Marionette.getOption(this, "emptyView");
1116+
var EmptyView = this.getEmptyView();
11051117

11061118
if (EmptyView && !this._showingEmptyView){
11071119
this._showingEmptyView = true;
@@ -1120,6 +1132,11 @@ Marionette.CollectionView = Marionette.View.extend({
11201132
}
11211133
},
11221134

1135+
// Retrieve the empty view type
1136+
getEmptyView: function(){
1137+
return Marionette.getOption(this, "emptyView");
1138+
},
1139+
11231140
// Retrieve the itemView type, either from `this.options.itemView`
11241141
// or from the `itemView` in the object definition. The "options"
11251142
// takes precedence.

lib/core/backbone.marionette.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/backbone.marionette.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "backbone.marionette",
33
"description": "Make your Backbone.js apps dance!",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"homepage": "https://github.com/marionettejs/backbone.marionette",
66
"main": "lib/core/amd/backbone.marionette.js",
77
"keywords": [
@@ -41,7 +41,7 @@
4141
"dependencies": {
4242
"backbone.babysitter": "~0.0.6",
4343
"backbone.wreqr": "~0.2.0",
44-
"backbone": "~1.0.0"
44+
"backbone": "~1.1.0"
4545
},
4646
"devDependencies": {
4747
"grunt": "~0.4.0",
@@ -64,7 +64,7 @@
6464
"jam": {
6565
"dependencies": {
6666
"underscore": ">=1.4.4",
67-
"backbone": ">=0.9.9",
67+
"backbone": "~1.1.0",
6868
"backbone.babysitter": ">=0.0.6",
6969
"backbone.wreqr": ">=0.2.0"
7070
},

0 commit comments

Comments
 (0)