Commit 4965102c authored by Pascal Hartig's avatar Pascal Hartig

Dermis: jshint style

parent ccad8ec9
(function( window ) { /*global $ dermis require*/
(function () {
'use strict'; 'use strict';
dermis.route('/'); dermis.route('/');
dermis.route('/active'); dermis.route('/active');
dermis.route('/completed'); dermis.route('/completed');
require(['js/models/Todo', 'js/models/Todos', 'js/storage'], function(Todo, Todos, storage){ require(['js/models/Todo', 'js/models/Todos', 'js/storage'], function (Todo, Todos, storage) {
//Bind Todos to DOM //Bind Todos to DOM
Todos.bind($('#content')); Todos.bind($('#content'));
$('#content').on('dblclick', '.view > label', function(){ $('#content').on('dblclick', '.view > label', function () {
$(this).parent().siblings('input').focus(); $(this).parent().siblings('input').focus();
}); });
//Load previous todos //Load previous todos
var todos = storage.load('todos-dermis'); var todos = storage.load('todos-dermis');
if(todos){ if (todos) {
todos.forEach(function(todo){ todos.forEach(function (todo) {
Todos.push(Todo.create({collection:Todos}) Todos.push(Todo.create({collection: Todos})
.set(todo) .set(todo)
.set({editable:false})); .set({editable: false}));
}); });
} }
//Save when todos modified //Save when todos modified
var save = function(){ var save = function () {
storage.save('todos-dermis', Todos.serialize()); storage.save('todos-dermis', Todos.serialize());
}; };
Todos.on('change',save).on('change:child',save); Todos.on('change', save).on('change:child', save);
//Add todo when box submitted //Add todo when box submitted
var box = $('#new-todo'); var box = $('#new-todo');
box.change(function(){ box.change(function () {
var title = box.val().trim(); var title = box.val().trim();
if(title.length === 0) return; if (title.length === 0) {
Todos.push(Todo.create({collection:Todos}) return;
}
Todos.push(Todo.create({collection: Todos})
.set({ .set({
title: title, title: title,
completed: false, completed: false,
...@@ -43,4 +46,4 @@ ...@@ -43,4 +46,4 @@
box.val(''); box.val('');
}); });
}); });
})( window ); })();
\ No newline at end of file
define(function(){ /*global define dermis window*/
define(function () {
'use strict';
var Todo = dermis.model({ var Todo = dermis.model({
setEditable: function(){ setEditable: function () {
this.set('editable', true); this.set('editable', true);
}, },
save: function(){ save: function () {
this.set('editable', false); this.set('editable', false);
var title = this.get('title').trim(); var title = this.get('title').trim();
if(title.length === 0) { if (title.length === 0) {
var todo = this; var todo = this;
setTimeout(function(){ window.setTimeout(function () {
todo.destroy(); todo.destroy();
}, 1); }, 1);
} }
}, },
destroy: function(){ destroy: function () {
this.collection.remove(this); this.collection.remove(this);
}, },
serialize: function(){ serialize: function () {
return { return {
title: this.get('title'), title: this.get('title'),
completed: this.get('completed') completed: this.get('completed')
......
define(function(Todo){ /*global define dermis*/
define(function () {
'use strict';
var Todos = dermis.collection({ var Todos = dermis.collection({
toggle: function(){ toggle: function () {
var toggled = this.allCompleted(); var toggled = this.allCompleted();
this.emit('change:toggle'); this.emit('change:toggle');
this.all().forEach(function(todo){ this.all().forEach(function (todo) {
todo.set('completed', !toggled); todo.set('completed', !toggled);
}); });
}, },
clear: function(){ clear: function () {
this.completed().forEach(function(todo){ this.completed().forEach(function (todo) {
todo.destroy(); todo.destroy();
}); });
}, },
// These can all be implemented as rivets formatters // These can all be implemented as rivets formatters
allCompleted: function(){ allCompleted: function () {
return this.completed().length === this.all().length; return this.completed().length === this.all().length;
}, },
todos: function(){ todos: function () {
return this[this.get('mode')](); return this[this.get('mode')]();
}, },
all: function(){ all: function () {
return this.get('items'); return this.get('items');
}, },
completed: function(){ completed: function () {
var out = []; var out = [];
this.all().forEach(function(todo){ this.all().forEach(function (todo) {
if (todo.get('completed')) out.push(todo); if (todo.get('completed')) {
out.push(todo);
}
}); });
return out; return out;
}, },
active: function(){ active: function () {
var out = []; var out = [];
this.all().forEach(function(todo){ this.all().forEach(function (todo) {
if (!todo.get('completed')) out.push(todo); if (!todo.get('completed')) {
out.push(todo);
}
}); });
return out; return out;
}, },
serialize: function(){ serialize: function () {
var out = []; var out = [];
this.all().forEach(function(todo){ this.all().forEach(function (todo) {
out.push(todo.serialize()); out.push(todo.serialize());
}); });
return out; return out;
......
define(function(){ /*global define window*/
define(function () {
'use strict';
var mod = { var mod = {
load: function(key){ load: function (key) {
if (!'localStorage' in window) return; if (window.localStorage === undefined) {
return;
}
var d = window.localStorage[key]; var d = window.localStorage[key];
if (d){ if (d) {
return JSON.parse(d); return JSON.parse(d);
} else { } else {
return; return;
} }
}, },
save: function(key, data){ save: function (key, data) {
if (!'localStorage' in window) return; if (window.localStorage === undefined) {
return;
}
window.localStorage[key] = JSON.stringify(data); window.localStorage[key] = JSON.stringify(data);
} }
}; };
......
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