Skip to content

Commit

Permalink
Backbone+require app: Convert to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 1, 2012
1 parent ecbd957 commit 5995093
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 292 deletions.
80 changes: 40 additions & 40 deletions dependency-examples/backbone_require/js/collections/todos.js
@@ -1,42 +1,42 @@
define([
'underscore',
'backbone',
'libs/backbone/localstorage',
'models/todo'
], function(_, Backbone, Store, Todo){
var TodosCollection = Backbone.Collection.extend({

// Reference to this collection's model.
model: Todo,

// Save all of the todo items under the `"todos"` namespace.
localStorage: new Store("todos-backbone"),

// Filter down the list of all todo items that are finished.
completed: function() {
return this.filter(function(todo){ return todo.get('completed'); });
},

// Filter down the list to only todo items that are still not finished.
remaining: function() {
return this.without.apply(this, this.completed());
},

// We keep the Todos in sequential order, despite being saved by unordered
// GUID in the database. This generates the next order number for new items.
nextOrder: function() {
if ( !this.length ){
return 1;
}
return this.last().get('order') + 1;
},

// Todos are sorted by their original insertion order.
comparator: function(todo) {
return todo.get('order');
}

});
return new TodosCollection;
'underscore',
'backbone',
'lib/backbone/localstorage',
'models/todo'
], function(_, Backbone, Store, Todo){

var TodosCollection = Backbone.Collection.extend({

// Reference to this collection's model.
model: Todo,

// Save all of the todo items under the `"todos"` namespace.
localStorage: new Store("todos-backbone"),

// Filter down the list of all todo items that are finished.
completed: function() {
return this.filter(function(todo){ return todo.get('completed'); });
},

// Filter down the list to only todo items that are still not finished.
remaining: function() {
return this.without.apply(this, this.completed());
},

// We keep the Todos in sequential order, despite being saved by unordered
// GUID in the database. This generates the next order number for new items.
nextOrder: function() {
if ( !this.length ){
return 1;
}
return this.last().get('order') + 1;
},

// Todos are sorted by their original insertion order.
comparator: function(todo) {
return todo.get('order');
}

});
return new TodosCollection;
});
56 changes: 28 additions & 28 deletions dependency-examples/backbone_require/js/models/todo.js
@@ -1,32 +1,32 @@
define(['underscore', 'backbone'], function(_, Backbone) {
var TodoModel = Backbone.Model.extend({

// Default attributes for the todo.
defaults: {
title: "empty todo...",
completed: false
},

// Ensure that each todo created has `title`.
initialize: function() {
if (!this.get("title")) {
this.set({"title": this.defaults.title});
}
},

// Toggle the `completed` state of this todo item.
toggle: function() {
this.save({completed: !this.get("completed")});
},

// Remove this Todo from *localStorage* and delete its view.
clear: function() {
this.destroy();
}

});

return TodoModel;
var TodoModel = Backbone.Model.extend({

// Default attributes for the todo.
defaults: {
title: "empty todo...",
completed: false
},

// Ensure that each todo created has `title`.
initialize: function() {
if (!this.get("title")) {
this.set({"title": this.defaults.title});
}
},

// Toggle the `completed` state of this todo item.
toggle: function() {
this.save({completed: !this.get("completed")});
},

// Remove this Todo from *localStorage* and delete its view.
clear: function() {
this.destroy();
}

});

return TodoModel;
});


Expand Down
30 changes: 15 additions & 15 deletions dependency-examples/backbone_require/js/templates/stats.html
@@ -1,15 +1,15 @@
<span id="todo-count"><strong><%= remaining %></strong> <%= remaining == 1 ? 'item' : 'items' %> left</span>
<ul id="filters">
<li>
<a class="selected" href="#/">All</a>
</li>
<li>
<a href="#/active">Active</a>
</li>
<li>
<a href="#/completed">Completed</a>
</li>
</ul>
<% if (completed) { %>
<button id="clear-completed">Clear completed (<%= completed %>)</button>
<% } %>
<span id="todo-count"><strong><%= remaining %></strong> <%= remaining == 1 ? 'item' : 'items' %> left</span>
<ul id="filters">
<li>
<a class="selected" href="#/">All</a>
</li>
<li>
<a href="#/active">Active</a>
</li>
<li>
<a href="#/completed">Completed</a>
</li>
</ul>
<% if (completed) { %>
<button id="clear-completed">Clear completed (<%= completed %>)</button>
<% } %>
12 changes: 6 additions & 6 deletions dependency-examples/backbone_require/js/templates/todos.html
@@ -1,6 +1,6 @@
<div class="view">
<input class="toggle" type="checkbox" <%= completed ? 'checked="checked"' : '' %> />
<label><%- title %></label>
<button class="destroy"></button>
</div>
<input class="edit" type="text" value="<%- title %>" />
<div class="view">
<input class="toggle" type="checkbox" <%= completed ? 'checked="checked"' : '' %> />
<label><%- title %></label>
<button class="destroy"></button>
</div>
<input class="edit" type="text" value="<%- title %>" />

0 comments on commit 5995093

Please sign in to comment.