Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
created directory for part 4
- Loading branch information
Showing
15 changed files
with
765 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
define (['collections/todos', 'views/app', 'models/todo'], function (todosColl, appView, todosModel) { | ||
'use strict'; | ||
|
||
var module = {}; | ||
|
||
module.init = function () { | ||
var collection = todosColl.create(), | ||
model = todosModel.create({ 'collection' : collection }); | ||
|
||
collection.model = model; | ||
return appView.create({ 'collection' : collection }); | ||
}; | ||
|
||
return module; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Todo Collection | ||
// --------------- | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
var module = {}, TodoList; | ||
|
||
// The collection of todos is backed by *localStorage* instead of a remote | ||
// server. | ||
TodoList = Backbone.Collection.extend({ | ||
|
||
// Save all of the todo items under the 'todos' namespace. | ||
localStorage: new Store('todos'), | ||
|
||
// Filter down the list of all todo items that are finished. | ||
done: function () { | ||
return this.filter(function (todo) { return todo.get('done'); }); | ||
}, | ||
|
||
// Filter down the list to only todo items that are still not finished. | ||
remaining: function () { | ||
return this.without.apply(this, this.done()); | ||
}, | ||
|
||
// 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'); | ||
} | ||
|
||
}); | ||
|
||
module.create = function (properties) { | ||
return new TodoList(properties); | ||
} | ||
|
||
return module; | ||
}); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Backbone Demo: Todos</title> | ||
<link href="todos.css" media="all" rel="stylesheet" type="text/css"/> | ||
</head> | ||
|
||
<body> | ||
|
||
<!-- Todo App Interface --> | ||
|
||
<div id="todoapp"> | ||
|
||
<div class="title"> | ||
<h1>Todos</h1> | ||
</div> | ||
|
||
<div class="content"> | ||
|
||
<div id="create-todo"> | ||
<input id="new-todo" placeholder="What needs to be done?" type="text" /> | ||
<span class="ui-tooltip-top" style="display:none;">Press Enter to save this task</span> | ||
</div> | ||
|
||
<div id="todos"> | ||
<ul id="todo-list"></ul> | ||
</div> | ||
|
||
<div id="todo-stats"></div> | ||
|
||
</div> | ||
|
||
</div> | ||
|
||
<ul id="instructions"> | ||
<li>Double-click to edit a todo.</li> | ||
<li><a href="../../docs/todos.html">View the annotated source.</a></li> | ||
</ul> | ||
|
||
<div id="credits"> | ||
Created by | ||
<br /> | ||
<a href="http://jgn.me/">Jérôme Gravel-Niquet</a> | ||
</div> | ||
|
||
<script data-main="main" src="require.js"></script> | ||
</body> | ||
</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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
var config = {}, underscore, bootstrap; | ||
// config.baseUrl = '../../test/vendor'; | ||
config.paths = { | ||
'vendor' : '../../test/vendor', | ||
'root' : '../..', | ||
'examples' : '..' | ||
}; | ||
|
||
underscore = require({ context : 'underscore' }); | ||
bootstrap = require({ context : 'bootstrap', paths : config.paths }); | ||
underscore(['underscore'], function (_) { | ||
window._ = _; // move underscore to global namespace for backbone | ||
bootstrap(['vendor/json2', 'order!vendor/jquery-1.6.4', 'order!root/backbone', 'order!examples/backbone-localstorage', 'order!app.js'], function (a, b, c, d, app) { | ||
app.init(); | ||
}); | ||
}); | ||
}()); |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Todo Model | ||
// ---------- | ||
|
||
define(function () { | ||
'use strict'; | ||
|
||
var module = {}; | ||
|
||
module.create = function (properties) { | ||
|
||
|
||
// Our basic **Todo** model has 'text', 'order', and 'done' attributes. | ||
var Todo = Backbone.Model.extend({ | ||
|
||
// Default attributes for a todo item. | ||
defaults: function () { | ||
return { | ||
done: false, | ||
order: properties.collection.nextOrder() | ||
}; | ||
}, | ||
|
||
// Toggle the 'done' state of this todo item. | ||
toggle: function () { | ||
this.save({done: !this.get("done")}); | ||
} | ||
|
||
}); | ||
|
||
return Todo; | ||
}; | ||
|
||
return module; | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<% if (total) { %> | ||
<span class="todo-count"> | ||
<span class="number"><%= remaining %></span> | ||
<span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left. | ||
</span> | ||
<% } %> | ||
<% if (done) { %> | ||
<span class="todo-clear"> | ||
<a href="#"> | ||
Clear <span class="number-done"><%= done %></span> | ||
completed <span class="word-done"><%= done == 1 ? 'item' : 'items' %></span> | ||
</a> | ||
</span> | ||
<% } %> |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="todo <%= done ? 'done' : '' %>"> | ||
<div class="display"> | ||
<input class="check" type="checkbox" <%= done ? 'checked="checked"' : '' %> /> | ||
<div class="todo-text"></div> | ||
<span class="todo-destroy"></span> | ||
</div> | ||
<div class="edit"> | ||
<input class="todo-input" type="text" value="" /> | ||
</div> | ||
</div> |
Oops, something went wrong.