Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
created directory for part 4
  • Loading branch information
jstrimpel committed Mar 24, 2012
1 parent 7de6ce1 commit d00e07c
Show file tree
Hide file tree
Showing 15 changed files with 765 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/todos-requirejs-4/app.js
@@ -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;
});
45 changes: 45 additions & 0 deletions examples/todos-requirejs-4/collections/todos.js
@@ -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;
});
Binary file added examples/todos-requirejs-4/destroy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions examples/todos-requirejs-4/index.html
@@ -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&eacute;r&ocirc;me Gravel-Niquet</a>
</div>

<script data-main="main" src="require.js"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/todos-requirejs-4/main.js
@@ -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();
});
});
}());
34 changes: 34 additions & 0 deletions examples/todos-requirejs-4/models/todo.js
@@ -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;
});
8 changes: 8 additions & 0 deletions examples/todos-requirejs-4/order.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions examples/todos-requirejs-4/require.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions examples/todos-requirejs-4/templates/app/stats.tmp
@@ -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>
<% } %>
10 changes: 10 additions & 0 deletions examples/todos-requirejs-4/templates/todo/list.tmp
@@ -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>

0 comments on commit d00e07c

Please sign in to comment.