Commit 9005b8d2 authored by Pascal Hartig's avatar Pascal Hartig

o_O: jshint style

parent ae0d41a3
/*global $, o_O, todoapp */ /*jshint camelcase:false newcap:false*/
(function( window ) { /*global $ o_O todoapp */
(function (window) {
'use strict'; 'use strict';
// represents a single todo item // represents a single todo item
...@@ -8,48 +10,48 @@ ...@@ -8,48 +10,48 @@
completed: false completed: false
}, },
{ {
initialize: function() { initialize: function () {
this.editing = o_O( false ); this.editing = o_O(false);
}, },
startEditing: function() { startEditing: function () {
this.editing( true ); this.editing(true);
var self = this; var self = this;
setTimeout(function() { setTimeout(function () {
$( self.el ).parent().find('input.edit').focus(); $(self.el).parent().find('input.edit').focus();
}, 0); }, 0);
}, },
stopEditing: function() { stopEditing: function () {
var text = $.trim( this.title() ); var text = $.trim(this.title());
if ( text ) { if (text) {
this.title( text ); this.title(text);
} else { } else {
this.remove(); this.remove();
} }
this.editing( false ); 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 '';
...@@ -64,44 +66,44 @@ ...@@ -64,44 +66,44 @@
completedCount: 0, completedCount: 0,
filter: '' filter: ''
}, { }, {
initialize: function() { initialize: function () {
var self = this; var self = this;
self.todos = o_O.array( this.todos() ); self.todos = o_O.array(this.todos());
this.todos.on( 'set:completed set:title add remove', function() { this.todos.on('set:completed set:title add remove', function () {
var completed = self.todos.filter(function( todo ) { var completed = self.todos.filter(function (todo) {
return todo.completed(); return todo.completed();
}); });
self.completedCount( completed.length ); self.completedCount(completed.length);
self.persist(); self.persist();
}); });
this.remainingCount = o_O(function() { this.remainingCount = o_O(function () {
return self.todos.count() - self.completedCount(); return self.todos.count() - self.completedCount();
}); });
// writeable computed observable // writeable computed observable
// handles marking all complete/incomplete // handles marking all complete/incomplete
// or retrieving if this is true // or retrieving if this is true
this.allCompleted = o_O(function( v ) { this.allCompleted = o_O(function (v) {
if ( !arguments.length ) { if (!arguments.length) {
return !self.remainingCount(); return !self.remainingCount();
} }
self.todos.each(function( todo ) { self.todos.each(function (todo) {
todo.completed( v ); todo.completed(v);
}); });
return v; return v;
}); });
}, },
add: function() { add: function () {
var text = $.trim( this.current() ); var text = $.trim(this.current());
if ( text ) { if (text) {
this.todos.unshift(Todo({ this.todos.unshift(Todo({
title: text title: text
})); }));
...@@ -109,19 +111,19 @@ ...@@ -109,19 +111,19 @@
} }
}, },
removeCompleted: function() { removeCompleted: function () {
this.todos.remove(function( todo ) { this.todos.remove(function (todo) {
return todo.completed(); return todo.completed();
}); });
return false; return false;
}, },
persist: function() { persist: function () {
localStorage['todos-o_O'] = JSON.stringify( this.todos.toJSON() ); localStorage['todos-o_O'] = JSON.stringify(this.todos.toJSON());
}, },
pluralize: function( word, count ) { pluralize: function (word, count) {
return word + ( count === 1 ? '' : 's' ); return word + (count === 1 ? '' : 's');
} }
}); });
...@@ -131,12 +133,12 @@ ...@@ -131,12 +133,12 @@
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 // create app
...@@ -149,25 +151,25 @@ ...@@ -149,25 +151,25 @@
// setup Routing // setup Routing
o_O.router() o_O.router()
.add('*filter', function( filter ) { .add('*filter', function (filter) {
todoapp.filter( filter ); todoapp.filter(filter);
$('#filters a') $('#filters a')
.removeClass('selected') .removeClass('selected')
.filter( '[href="#/' + filter + '"]' ) .filter('[href="#/' + filter + '"]')
.addClass('selected'); .addClass('selected');
}) })
.start(); .start();
} }
// a custom binding to handle the enter key // a custom binding to handle the enter key
o_O.bindings.enterKey = function( func, $el ) { o_O.bindings.enterKey = function (func, $el) {
var ENTER_KEY = 13, var ENTER_KEY = 13,
context = this; context = this;
$el.keyup(function( e ) { $el.keyup(function (e) {
if ( e.which === ENTER_KEY ) { if (e.which === ENTER_KEY) {
func.call( context ); func.call(context);
} }
}); });
}; };
...@@ -177,4 +179,4 @@ ...@@ -177,4 +179,4 @@
// kick it off // kick it off
main(); main();
})( window ); })(window);
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