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

Dermis: jshint style

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