Commit 1abb3cc2 authored by Sindre Sorhus's avatar Sindre Sorhus

Funnyface.js: Indentation

parent 158848fb
...@@ -2,68 +2,68 @@ ...@@ -2,68 +2,68 @@
(function( window ) { (function( window ) {
'use strict'; 'use strict';
// represents a single todo item // represents a single todo item
var Todo = o_O.model.extend({ var Todo = o_O.model.extend({
title: '', title: '',
completed: false completed: false
},
{
initialize: function() {
this.editing = o_O( false );
},
startEditing: function() {
this.editing( true );
var self = this;
setTimeout(function() {
$( self.el ).parent().find('input.edit').select();
}, 0);
}, },
{
initialize: function() {
this.editing = o_O( false );
},
startEditing: function() {
this.editing( true );
var self = this;
setTimeout(function() {
$( self.el ).parent().find('input.edit').select();
}, 0);
},
stopEditing: function() {
var text = $.trim( this.title() );
if ( text ) {
this.title( text );
} else {
this.remove();
}
stopEditing: function() { this.editing( false );
var text = $.trim( this.title() ); },
if ( text ) {
this.title( text );
} else {
this.remove();
}
this.editing( false );
},
remove: function() { remove: function() {
todoapp.todos.remove( this ); todoapp.todos.remove( this );
}, },
visible: function() { visible: function() {
var filter = todoapp.filter(), var filter = todoapp.filter(),
completed = this.completed(); completed = this.completed();
return filter === '' || return filter === '' ||
( filter === 'completed' && completed ) || ( filter === 'completed' && completed ) ||
( filter === 'active' && !completed ); ( filter === 'active' && !completed );
}, },
klass: function() { klass: function() {
if ( this.editing() ) { if ( this.editing() ) {
return 'editing'; return 'editing';
} }
if ( this.completed() ) { if ( this.completed() ) {
return 'completed'; return 'completed';
} else { } else {
return ''; return '';
}
} }
} }
} );
);
// main application
// main application var TodoApp = o_O.model.extend({
var TodoApp = o_O.model.extend({ current: '',
current: '', completedCount: 0,
completedCount: 0, filter: ''
filter: '' }, {
}, {
initialize: function() { initialize: function() {
var self = this; var self = this;
...@@ -123,59 +123,58 @@ var TodoApp = o_O.model.extend({ ...@@ -123,59 +123,58 @@ var TodoApp = o_O.model.extend({
pluralize: function( word, count ) { pluralize: function( word, count ) {
return word + ( count === 1 ? '' : 's' ); return word + ( count === 1 ? '' : 's' );
} }
} });
);
function main() { function main() {
// load todos // load todos
var i, l, var i, l,
todos = []; todos = [];
try { try {
todos = JSON.parse( localStorage['todos-o_O'] ); todos = JSON.parse( localStorage['todos-o_O'] );
} catch( e ) {} } catch( e ) {}
// create models // create models
for( i = 0, l = todos.length; i < l; i++ ) { for( i = 0, l = todos.length; i < l; i++ ) {
todos[ i ] = Todo.create( todos[ i ] ); todos[ i ] = Todo.create( todos[ i ] );
}
// create app
window.todoapp = TodoApp({
todos: todos
});
// bind to DOM element
todoapp.bind('#todoapp');
// setup Routing
o_O.router()
.add('*filter', function( filter ) {
todoapp.filter( filter );
$('#filters a')
.removeClass('selected')
.filter( '[href="#/' + filter + '"]' )
.addClass('selected');
})
.start();
} }
// create app // a custom binding to handle the enter key
window.todoapp = TodoApp({ o_O.bindings.enterKey = function( func, $el ) {
todos: todos var ENTER_KEY = 13,
}); context = this;
// bind to DOM element $el.keyup(function( e ) {
todoapp.bind('#todoapp'); if ( e.which === ENTER_KEY ) {
func.call( context );
// setup Routing }
o_O.router() });
.add('*filter', function( filter ) { };
todoapp.filter( filter );
$('#filters a')
.removeClass('selected')
.filter( '[href="#/' + filter + '"]' )
.addClass('selected');
})
.start();
}
// a custom binding to handle the enter key
o_O.bindings.enterKey = function( func, $el ) {
var ENTER_KEY = 13,
context = this;
$el.keyup(function( e ) {
if ( e.which === ENTER_KEY ) {
func.call( context );
}
});
};
o_O.bindingTypes.enterKey = 'outbound'; o_O.bindingTypes.enterKey = 'outbound';
// kick it off // kick it off
main(); main();
})( window ); })( window );
\ 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