Skip to content

Commit

Permalink
Merge pull request marionettejs#744 from marionettejs/v1.2.0
Browse files Browse the repository at this point in the history
V1.2.0 release
  • Loading branch information
samccone committed Oct 22, 2013
2 parents fcb1484 + b8004d7 commit 0b29de7
Show file tree
Hide file tree
Showing 43 changed files with 595 additions and 351 deletions.
17 changes: 13 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### v1.2.0 [view commit logs](https://github.com/marionettejs/backbone.marionette/compare/v1.1.0...v1.2.0)
* Update Backbone to [1.1.0](https://github.com/jashkenas/backbone/compare/1.0.0...1.1.0)

* Views
* added the ability to customize the behavior of `triggers` preventDefault and stopPropagation

* Collection View / CompositeView
* added the ability to specifiy `getEmptyView` for dynamic `emptyView` lookups

### v1.1 [view commit logs](https://github.com/marionettejs/backbone.marionette/compare/v1.0.4...v1.1.0)

* Marionette.View / All Views
Expand Down Expand Up @@ -191,7 +200,7 @@
* Marionette.addEventBinder
* **BREAKING:** This function will mix in Backbone.Events to the target object if it does not exist
* **BREAKING:** This function will alter the `listenTo` method of the target to accept a `context` parameter as the 4th parameter of the method

* All Views, Controller, etc
* **BREAKING:** Backbone.EventBinder is no longer mixed in
* **BREAKING:** See 'EventBinder -> EventAggregator' changes regarding method names to use for binding / unbinding events
Expand Down Expand Up @@ -678,7 +687,7 @@
* Added `Marionette.View` object, to contain a few basic parts of every Marionette view
* Added `Marionette.Renderer` object, to handle template rendering
* Views correctly trigger the "close" events before unbinding event subscribers
* Additional `CollectionView` changes:
* Additional `CollectionView` changes:
* Extracted `getItemView` method to retrieve the `itemView` type, either from `this.itemView` or `this.options.itemView`
* Extracted `buildItemView` method to build each item's view
* Renamed `removeChildView` to `removeItemView` to make the language consistent
Expand Down Expand Up @@ -791,7 +800,7 @@

#### v0.4.5

* CollectionView closes existing child views before re-rendering itself, when "reset"
* CollectionView closes existing child views before re-rendering itself, when "reset"
event of collection is triggered
* CollectionView now has "initialEvents" method which configures it's initial events
* ItemView now has "initialEvents" method which configures it's initial events
Expand Down Expand Up @@ -827,7 +836,7 @@ event of collection is triggered
* **BREAKING:** Rewrote the template manager to be async-template loading friendly
* **BREAKING:** Dropping support for Backbone v0.5.3 and below
* Added `Marionette.Callbacks` to manage a collection of callbacks in an async-friendly way
* Guarantee the execution of app initializer functions, even if they are added after the app
* Guarantee the execution of app initializer functions, even if they are added after the app
has been started.
* App triggers "start" event after initializers and initializer events
* Updated to Backbone v0.9.1
Expand Down
12 changes: 12 additions & 0 deletions docs/marionette.collectionview.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ Backbone.Marionette.CollectionView.extend({
});
```

Or, if you need the `emptyView`'s type chosen dynamically, specify `getEmptyView`:

```js
Backbone.Marionette.CollectionView.extend({
// ...

getEmptyView: function() {
// custom logic
return NoItemsView;
}
```
This will render the `emptyView` and display the message that needs to
be displayed when there are no items.
Expand Down
13 changes: 13 additions & 0 deletions docs/marionette.view.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ view.$(".do-something").trigger("click");

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

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.
```js
Backbone.Marionette.CompositeView.extend({
triggers: {
"click .do-something": {
event: "something:do:it",
preventDefault: true,
stopPropagation: false // this param is optional and will default to false
}
}
});
```

You can also specify the `triggers` as a function that
returns a hash of trigger configurations

Expand Down
33 changes: 25 additions & 8 deletions lib/backbone.marionette.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MarionetteJS (Backbone.Marionette)
// ----------------------------------
// v1.1.0
// v1.2.0
//
// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
// Distributed under MIT license
Expand Down Expand Up @@ -1202,18 +1202,19 @@ Marionette.Renderer = {
// The core view type that other Marionette views extend from.
Marionette.View = Backbone.View.extend({

constructor: function(){
constructor: function(options){
_.bindAll(this, "render");

var args = Array.prototype.slice.apply(arguments);
Backbone.View.prototype.constructor.apply(this, args);
this.options = options;

Marionette.MonitorDOMRefresh(this);
this.listenTo(this, "show", this.onShowCalled, this);
},

// import the "triggerMethod" to trigger events with corresponding
// methods if the method exists
// methods if the method exists
triggerMethod: Marionette.triggerMethod,

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

var hasOptions = _.isObject(value);
var eventName = hasOptions ? value.event : value;

// build the event handler function for the DOM event
triggerEvents[key] = function(e){

// stop the event in its tracks
if (e && e.preventDefault){ e.preventDefault(); }
if (e && e.stopPropagation){ e.stopPropagation(); }
if (e) {
var prevent = e.preventDefault;
var stop = e.stopPropagation;

var shouldPrevent = hasOptions ? value.preventDefault : prevent;
var shouldStop = hasOptions ? value.stopPropagation : stop;

if (shouldPrevent && prevent) { prevent(); }
if (shouldStop && stop) { stop(); }
}

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

// trigger the event
this.triggerMethod(value, args);
this.triggerMethod(eventName, args);
};

}, this);

return triggerEvents;
},

// Overriding Backbone.View's delegateEvents to handle
// Overriding Backbone.View's delegateEvents to handle
// the `triggers`, `modelEvents`, and `collectionEvents` configuration
delegateEvents: function(events){
this._delegateDOMEvents(events);
Expand Down Expand Up @@ -1545,7 +1557,7 @@ Marionette.CollectionView = Marionette.View.extend({
// a collection of item views, when the collection is
// empty
showEmptyView: function(){
var EmptyView = Marionette.getOption(this, "emptyView");
var EmptyView = this.getEmptyView();

if (EmptyView && !this._showingEmptyView){
this._showingEmptyView = true;
Expand All @@ -1564,6 +1576,11 @@ Marionette.CollectionView = Marionette.View.extend({
}
},

// Retrieve the empty view type
getEmptyView: function(){
return Marionette.getOption(this, "emptyView");
},

// Retrieve the itemView type, either from `this.options.itemView`
// or from the `itemView` in the object definition. The "options"
// takes precedence.
Expand Down
2 changes: 1 addition & 1 deletion lib/backbone.marionette.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/backbone.marionette.min.js

Large diffs are not rendered by default.

33 changes: 25 additions & 8 deletions lib/core/amd/backbone.marionette.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MarionetteJS (Backbone.Marionette)
// ----------------------------------
// v1.1.0
// v1.2.0
//
// Copyright (c)2013 Derick Bailey, Muted Solutions, LLC.
// Distributed under MIT license
Expand Down Expand Up @@ -794,18 +794,19 @@ Marionette.Renderer = {
// The core view type that other Marionette views extend from.
Marionette.View = Backbone.View.extend({

constructor: function(){
constructor: function(options){
_.bindAll(this, "render");

var args = Array.prototype.slice.apply(arguments);
Backbone.View.prototype.constructor.apply(this, args);
this.options = options;

Marionette.MonitorDOMRefresh(this);
this.listenTo(this, "show", this.onShowCalled, this);
},

// import the "triggerMethod" to trigger events with corresponding
// methods if the method exists
// methods if the method exists
triggerMethod: Marionette.triggerMethod,

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

var hasOptions = _.isObject(value);
var eventName = hasOptions ? value.event : value;

// build the event handler function for the DOM event
triggerEvents[key] = function(e){

// stop the event in its tracks
if (e && e.preventDefault){ e.preventDefault(); }
if (e && e.stopPropagation){ e.stopPropagation(); }
if (e) {
var prevent = e.preventDefault;
var stop = e.stopPropagation;

var shouldPrevent = hasOptions ? value.preventDefault : prevent;
var shouldStop = hasOptions ? value.stopPropagation : stop;

if (shouldPrevent && prevent) { prevent(); }
if (shouldStop && stop) { stop(); }
}

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

// trigger the event
this.triggerMethod(value, args);
this.triggerMethod(eventName, args);
};

}, this);

return triggerEvents;
},

// Overriding Backbone.View's delegateEvents to handle
// Overriding Backbone.View's delegateEvents to handle
// the `triggers`, `modelEvents`, and `collectionEvents` configuration
delegateEvents: function(events){
this._delegateDOMEvents(events);
Expand Down Expand Up @@ -1137,7 +1149,7 @@ Marionette.CollectionView = Marionette.View.extend({
// a collection of item views, when the collection is
// empty
showEmptyView: function(){
var EmptyView = Marionette.getOption(this, "emptyView");
var EmptyView = this.getEmptyView();

if (EmptyView && !this._showingEmptyView){
this._showingEmptyView = true;
Expand All @@ -1156,6 +1168,11 @@ Marionette.CollectionView = Marionette.View.extend({
}
},

// Retrieve the empty view type
getEmptyView: function(){
return Marionette.getOption(this, "emptyView");
},

// Retrieve the itemView type, either from `this.options.itemView`
// or from the `itemView` in the object definition. The "options"
// takes precedence.
Expand Down
4 changes: 2 additions & 2 deletions lib/core/amd/backbone.marionette.min.js

Large diffs are not rendered by default.

31 changes: 24 additions & 7 deletions lib/core/backbone.marionette.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,18 +758,19 @@ Marionette.Renderer = {
// The core view type that other Marionette views extend from.
Marionette.View = Backbone.View.extend({

constructor: function(){
constructor: function(options){
_.bindAll(this, "render");

var args = Array.prototype.slice.apply(arguments);
Backbone.View.prototype.constructor.apply(this, args);
this.options = options;

Marionette.MonitorDOMRefresh(this);
this.listenTo(this, "show", this.onShowCalled, this);
},

// import the "triggerMethod" to trigger events with corresponding
// methods if the method exists
// methods if the method exists
triggerMethod: Marionette.triggerMethod,

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

var hasOptions = _.isObject(value);
var eventName = hasOptions ? value.event : value;

// build the event handler function for the DOM event
triggerEvents[key] = function(e){

// stop the event in its tracks
if (e && e.preventDefault){ e.preventDefault(); }
if (e && e.stopPropagation){ e.stopPropagation(); }
if (e) {
var prevent = e.preventDefault;
var stop = e.stopPropagation;

var shouldPrevent = hasOptions ? value.preventDefault : prevent;
var shouldStop = hasOptions ? value.stopPropagation : stop;

if (shouldPrevent && prevent) { prevent(); }
if (shouldStop && stop) { stop(); }
}

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

// trigger the event
this.triggerMethod(value, args);
this.triggerMethod(eventName, args);
};

}, this);

return triggerEvents;
},

// Overriding Backbone.View's delegateEvents to handle
// Overriding Backbone.View's delegateEvents to handle
// the `triggers`, `modelEvents`, and `collectionEvents` configuration
delegateEvents: function(events){
this._delegateDOMEvents(events);
Expand Down Expand Up @@ -1101,7 +1113,7 @@ Marionette.CollectionView = Marionette.View.extend({
// a collection of item views, when the collection is
// empty
showEmptyView: function(){
var EmptyView = Marionette.getOption(this, "emptyView");
var EmptyView = this.getEmptyView();

if (EmptyView && !this._showingEmptyView){
this._showingEmptyView = true;
Expand All @@ -1120,6 +1132,11 @@ Marionette.CollectionView = Marionette.View.extend({
}
},

// Retrieve the empty view type
getEmptyView: function(){
return Marionette.getOption(this, "emptyView");
},

// Retrieve the itemView type, either from `this.options.itemView`
// or from the `itemView` in the object definition. The "options"
// takes precedence.
Expand Down
2 changes: 1 addition & 1 deletion lib/core/backbone.marionette.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/core/backbone.marionette.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "backbone.marionette",
"description": "Make your Backbone.js apps dance!",
"version": "1.1.0",
"version": "1.2.0",
"homepage": "https://github.com/marionettejs/backbone.marionette",
"main": "lib/core/amd/backbone.marionette.js",
"keywords": [
Expand Down Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"backbone.babysitter": "~0.0.6",
"backbone.wreqr": "~0.2.0",
"backbone": "~1.0.0"
"backbone": "~1.1.0"
},
"devDependencies": {
"grunt": "~0.4.0",
Expand All @@ -64,7 +64,7 @@
"jam": {
"dependencies": {
"underscore": ">=1.4.4",
"backbone": ">=0.9.9",
"backbone": "~1.1.0",
"backbone.babysitter": ">=0.0.6",
"backbone.wreqr": ">=0.2.0"
},
Expand Down
Loading

0 comments on commit 0b29de7

Please sign in to comment.