Created
July 8, 2011 16:54
-
-
Save jeremys/1072258 to your computer and use it in GitHub Desktop.
Date Header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Grid Date Header | |
joli.ui.GridDateView = Backbone.View.extend({ | |
tagName: 'li', | |
className: 'joli-grid-date', | |
template: 'joli-template-grid-date', | |
initialize: function() { | |
_.bindAll(this, 'render'); | |
this.model.bind('change', this.render); | |
}, | |
render: function() { | |
var attributes = this.model.toJSON(); | |
$(this.el).html(ich[this.template]({ | |
date: attributes.date.slice(0, 10) | |
})); | |
return this; | |
} | |
}); | |
addItem: function(item) { | |
if (this._previousItemDate != undefined) { | |
if (this._previousItemDate != item.attributes.date.slice(0, 10)) { | |
var view = new joli.ui.GridDateView({ model: item }); | |
$('.joli-grid-list').append(view.render().el); | |
} | |
} | |
var view = new joli.ui.GridItemView({ model: item }); | |
$('.joli-grid-list').append(view.render().el); | |
this._previousItemDate = item.attributes.date.slice(0, 10); | |
}, | |
<script id="joli-template-grid-date" type="text/html"> | |
<h2>{{ date }} <span><strong>{{ total }}</strong> items</span></h2> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment