New layout/design
Two column layout and style tweaks. Templatized conversation views. Generalized list view.
This commit is contained in:
parent
6d5e32bca8
commit
def32f42d4
9 changed files with 203 additions and 91 deletions
36
js/views/list_view.js
Normal file
36
js/views/list_view.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
var Whisper = Whisper || {};
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/*
|
||||
* Generic list view that watches a given collection, wraps its members in
|
||||
* a given child view and adds the child view elements to its own element.
|
||||
*/
|
||||
Whisper.ListView = Backbone.View.extend({
|
||||
tagName: 'ul',
|
||||
initialize: function() {
|
||||
this.listenTo(this.collection, 'change', this.render); // auto update
|
||||
this.listenTo(this.collection, 'add', this.addOne);
|
||||
this.listenTo(this.collection, 'reset', this.addAll);
|
||||
this.listenTo(this.collection, 'all', this.render);
|
||||
this.collection.fetch({reset: true});
|
||||
},
|
||||
|
||||
addOne: function(model) {
|
||||
if (this.itemView) {
|
||||
var view = new this.itemView({model: model});
|
||||
this.$el.append(view.render().el);
|
||||
}
|
||||
},
|
||||
|
||||
addAll: function() {
|
||||
this.$el.html('');
|
||||
this.collection.each(this.addOne, this);
|
||||
},
|
||||
|
||||
last: function() {
|
||||
this.collection.at(this.collection.length - 1);
|
||||
}
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue