Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backbone+require app: Convert to tabs
- Loading branch information
1 parent
ecbd957
commit 5995093
Showing
6 changed files
with
292 additions
and
292 deletions.
There are no files selected for viewing
80 changes: 40 additions & 40 deletions
80
dependency-examples/backbone_require/js/collections/todos.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); |
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
30 changes: 15 additions & 15 deletions
30
dependency-examples/backbone_require/js/templates/stats.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
12
dependency-examples/backbone_require/js/templates/todos.html
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %>" /> |
Oops, something went wrong.