ampersand-view
Advanced tools
Comparing version 6.0.9 to 6.0.10
{ | ||
"name": "ampersand-view", | ||
"description": "A smart base view for Backbone apps, to make it easy to bind collections and properties to the DOM.", | ||
"version": "6.0.9", | ||
"version": "6.0.10", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "browser": "./ampersand-view.js", |
@@ -101,3 +101,3 @@ # ampersand-view | ||
The events hash allows you to specify declarative callbacks for DOM events within the view. This is much clearer and less complex than calling `$('selector').on('click', ...)` or `el.addEventListener('click', ...)` everywhere. | ||
The events hash allows you to specify declarative callbacks for DOM events within the view. This is much clearer and less complex than calling `el.addEventListener('click', ...)` everywhere. | ||
@@ -270,3 +270,3 @@ * Events are written in the format `{"event selector": "callback"}`. | ||
* `collection` {Backbone Collection} The instantiated collection we wish to render. | ||
* `itemViewClass` {View Constructor} The view constructor that will be instantiated for each model in the collection. This view will be instantiated with a reference to the model and collection and the item view's `render` method will be called with an object containing a reference to the containerElement as follows: `.render({containerEl: << element >>})`. | ||
* `ItemView` {View Constructor | Function} The view constructor that will be instantiated for each model in the collection or a function that will return an instance of a given constructor. `options` object is passed as a first argument to a function, which can be used to access `options.model` and determine which view should be instantiated. This view will be used with a reference to the model and collection and the item view's `render` method will be called with an object containing a reference to the containerElement as follows: `.render({containerEl: << element >>})`. | ||
* `containerEl` {Element} The element that should hold the collection of views. | ||
@@ -287,4 +287,5 @@ * `viewOptions` {Object} [optional] Additional options | ||
```javascript | ||
// some view for individual items in the collection | ||
// some views for individual items in the collection | ||
var ItemView = AmpersandView.extend({ ... }); | ||
var AlternativeItemView = AmpersandView.extend({ ... }); | ||
@@ -311,6 +312,22 @@ // the main view | ||
// } | ||
this.renderCollection(this.collection, ItemView, this.$('.itemContainer')[0], opts); | ||
this.renderCollection(this.collection, ItemView, this.el.querySelector('.itemContainer'), opts); | ||
return this; | ||
} | ||
}) | ||
}); | ||
// alternative main view | ||
var AlternativeMainView = AmpersandView.extend({ | ||
template: '<section class="sidebar"><ul class="itemContainer"></ul></section>', | ||
render: function (opts) { | ||
this.renderWithTemplate(this); | ||
this.renderCollection(this.collection, function (options) { | ||
if (options.model.isAlternative) { | ||
return new AlternativeMainView(options); | ||
} | ||
return new MainView(options); | ||
}, this.el.querySelector('.itemContainer'), opts); | ||
return this; | ||
} | ||
}); | ||
``` | ||
@@ -430,3 +447,3 @@ | ||
* viewInstance {Object} Any object with a `.remove()`, `.render()` and an `.el` property that is the DOM element for that view. Typically this is just an instantiated view. | ||
* containerEl {Element | String | jQueryElement} This can either be an actual DOM element or a CSS selector string such as `.container`. If a string is passed human view runs `this.$("YOUR STRING")` to try to grab the element that should contain the sub view. | ||
* containerEl {Element | String} This can either be an actual DOM element or a CSS selector string such as `.container`. If a string is passed human view runs `this.get('YOUR STRING')` to try to grab the element that should contain the sub view. | ||
@@ -433,0 +450,0 @@ This method is just sugar for the common use case of instantiating a view and putting in an element within the parent. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
60298
569
0