Commit 93a7b965 authored by Sindre Sorhus's avatar Sindre Sorhus

o_O app: Cleanup

parent 5763d113
......@@ -9,38 +9,36 @@
<section id="todoapp">
<header id="header">
<h1>Todos</h1>
<input id="new-todo" data-bind="value: current; enterKey: add" placeholder="What needs to be done?">
</header>
<input id="new-todo" data-bind="value: current; enterKey: add" placeholder="What needs to be done?">
</header>
<section id="main" data-bind="visible: todos.count">
<div>
<input id="toggle-all" type="checkbox" data-bind="value: allCompleted;">
<label for="toggle-all">Mark all as complete</label>
<input id="toggle-all" type="checkbox" data-bind="value: allCompleted;">
<label for="toggle-all">Mark all as complete</label>
</div>
<ul id="todo-list" data-bind="foreach: todos">
<li data-bind="class: klass; visible; dblclick: startEditing">
<div class="view">
<input class="toggle" type="checkbox" data-bind="value: completed">
<label data-bind="text: title"></label>
<button class="destroy" data-bind="click: remove"></button>
</div>
<input class="edit" data-bind="value: title; enterKey: stopEditing; blur: stopEditing" />
</li>
<li data-bind="class: klass; visible; dblclick: startEditing">
<div class="view">
<input class="toggle" type="checkbox" data-bind="value: completed">
<label data-bind="text: title"></label>
<button class="destroy" data-bind="click: remove"></button>
</div>
<input class="edit" data-bind="value: title; enterKey: stopEditing; blur: stopEditing" />
</li>
</ul>
</section>
<footer id="footer" data-bind="visible: todos.count">
<span id="todo-count">
<strong data-bind="text: remainingCount"></strong>
<span class="word" data-bind="text: pluralize('item', remainingCount())"></span> left
<strong data-bind="text: remainingCount"></strong>
<span class="word" data-bind="text: pluralize('item', remainingCount())"></span> left
</span>
<ul id="filters" >
<li><a href="#/">All</a></li>
<ul id="filters" >
<li><a href="#/">All</a></li>
<li><a href="#/active">Active</a></li>
<li><a href="#/completed">Completed</a></li>
</ul>
<button id="clear-completed" data-bind="click: removeCompleted; visible: completedCount">
Clear completed
(<span data-bind='text: completedCount'></span>)
Clear completed (<span data-bind='text: completedCount'></span>)
</button>
</footer>
</section>
......@@ -48,9 +46,9 @@
<p>Double-click to edit a todo</p>
<p>Created by <a href="http://weepy.github.com">weepy (Jonah Fox)</a></p>
</footer>
<script src="../../../assets/jquery.min.js"></script>
<script src="js/lib/o_O.js" type="text/javascript"></script>
<script src="js/lib/o_O.router.js" type="text/javascript"></script>
<script src="js/app.js"></script>
<script src="../../../assets/jquery.min.js"></script>
<script src="js/lib/o_O.js" ></script>
<script src="js/lib/o_O.router.js"></script>
<script src="js/app.js"></script>
</body>
</html>
</html>
\ No newline at end of file
//a custom binding to handle the enter key
o_O.bindings.enterKey = function( func, $el ) {
var ENTER_KEY = 13;
var context = this
var context = this;
$el.keyup(function(e) {
if( e.keyCode === ENTER_KEY )
func.call(context);
......@@ -20,7 +20,7 @@ var Todo = o_O.model.extend({
this.editing = o_O(false)
},
startEditing: function() {
startEditing: function() {
this.editing( true )
var self = this
setTimeout(function() {
......@@ -32,7 +32,7 @@ var Todo = o_O.model.extend({
var text = $.trim( this.title() )
text
? this.title( text )
? this.title( text )
: this.remove()
this.editing( false )
......@@ -51,7 +51,7 @@ var Todo = o_O.model.extend({
klass: function() {
if(this.editing())
return 'editing'
if(this.completed())
if(this.completed())
return 'completed'
else
return ''
......@@ -61,7 +61,7 @@ var Todo = o_O.model.extend({
// main application
var TodoApp = o_O.model.extend({
current: "",
current: '',
completedCount: 0,
filter: ''
}, {
......@@ -76,15 +76,15 @@ var TodoApp = o_O.model.extend({
self.completedCount( completed.length )
self.persist()
})
this.remainingCount = o_O(function() {
return self.todos.count() - self.completedCount()
})
// writeable computed observable
// writeable computed observable
// handles marking all complete/incomplete
// or retrieving if this is true
this.allCompleted = o_O(function(v) {
this.allCompleted = o_O(function(v) {
if(arguments.length == 0) {
return self.remainingCount() == 0
}
......@@ -102,7 +102,7 @@ var TodoApp = o_O.model.extend({
var text = $.trim( this.current() );
if( text ) {
this.todos.unshift( Todo({title: text}) );
this.current( "" )
this.current( "" )
}
},
......@@ -129,11 +129,11 @@ function main() {
var todos = []
try {
todos = JSON.parse( localStorage['todos-o_O'] );
}
}
catch(e) { }
// create models
for( var i=0; i < todos.length; i++ )
for( var i=0; i < todos.length; i++ )
todos[ i ] = Todo.create( todos[i] )
// create app
......@@ -147,14 +147,14 @@ function main() {
o_O.router()
.add('*filter', function(filt) {
todoapp.filter(filt)
$( '#filters a' )
.removeClass( 'selected' )
.filter( "[href='#/" + filt + "']" )
.addClass( 'selected' )
.addClass( 'selected' )
})
.start()
}
// kick it off
main();
main();
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment