JSFiddle - React, Tailwind, and code Playground
by Rusln
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<div id="container">
<nav class="menu">
<ul class="footer">
<li><a href="#about">About</a></li>
<li><a href="#privacy">Privacy</a></li>
<li><a href="#terms">Terms</a></li>
</ul>
</nav>
<section class="feed">
</section>
<script id="bookTemplate" type="text/template">
<img src="<%= image %>"/>
<h2 class="bookTitle"><%= title %><h2>
</script>
<script id="termsTemplate" type="text/template">
Terms
</script>
<script id="privacyTemplate" type="text/template">
Privacy
</script>
<script id="aboutTemplate" type="text/template">
About
</script>
</div>
JavaScript
app = {};
var books = [
{title:'Imperial Bedrooms',
image:'http://upload.wikimedia.org/wikipedia/en/thumb/e/e8/Imperial_bedrooms_cover.JPG/200px-Imperial_bedrooms_cover.JPG'
},
{title:'Less than zero',
image:'http://d.gr-assets.com/books/1282271923l/9915.jpg'
},
];
app.Router = Backbone.Router.extend({
routes: {
'' : 'home',
'about' : 'about',
'privacy' : 'privacy',
'terms' : 'terms'
},
home: function () {
if(!this.bookListView){
this.bookListView = new app.BookListView(books);
}else{
this.bookListView.render();
}
},
about: function () {
if (!this.aboutView) {
this.aboutView = new app.AboutView();
}
$('.feed').html(this.aboutView.render().el);
},
privacy: function () {
if (!this.privacyView) {
this.privacyView = new app.PrivacyView();
};
$('.feed').html(this.privacyView.render().el);
},
terms: function () {
if (!this.termsView) {
this.termsView = new app.TermsView();
};
$('.feed').html(this.termsView.render().el);
}
});
app.Book = Backbone.Model.extend({
defaults: {
title:'',
image:'',
}
});
app.BookList = Backbone.Collection.extend ({
model: app.Book
});
app.BookView = Backbone.View.extend ({
tagName: 'div',
className: 'book',
template: _.template( $( '#bookTemplate' ).html()),
render: function() {
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
app.BookListView = Backbone.View.extend({
el: '.feed',
initialize: function ( initialBooks ) {
this.collection = new app.BookList (initialBooks);
this.render();
},
render: function() {
this.collection.each(function( item ){
this.renderBook( item );
}, this);
},
renderBook: function ( item ) {
var bookview = new app.BookView ({
model: item
});
this.$el.append( bookview.render().el );
}
});
app.PrivacyView = Backbone.View.extend ({
tagName: 'div',
className: 'privacy',
template:...