Commit 84b4a7b6 authored by Ralph Holzmann's avatar Ralph Holzmann

Updated can.each param order in each example.

parent 9447769a
......@@ -33,7 +33,7 @@ Todo = can.Model({
data = dojo.fromJson( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = dojo.toJson(data);
......@@ -45,7 +45,7 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
......@@ -128,7 +128,7 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0
});
return completed;
......@@ -223,7 +223,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all click' : function(el, ev) {
var toggle = el.attr('checked')[0];
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......
......@@ -22,7 +22,7 @@ Todo = can.Model({
data = dojo.fromJson( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = dojo.toJson(data);
......@@ -34,7 +34,7 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
......@@ -91,7 +91,7 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0
});
return completed;
......@@ -178,7 +178,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all click' : function(el, ev) {
var toggle = el.attr('checked')[0];
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......
......@@ -17,7 +17,7 @@ Todo = can.Model({
data = JSON.parse( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = JSON.stringify(data);
......@@ -29,7 +29,7 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
......@@ -113,7 +113,7 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0
});
return completed;
......@@ -141,9 +141,6 @@ Todos = can.Control({
// Clear the new todo field
$('#new-todo').val('').focus();
$.each(this.element.data(), function() {
});
},
// Listen for when a new Todo has been entered
......@@ -204,7 +201,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all click' : function(el, ev) {
var toggle = el.prop('checked');
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......@@ -266,4 +263,4 @@ Todo.findAll({}, function(todos) {
});
});
})();
\ No newline at end of file
})();
......@@ -10,7 +10,7 @@ Todo = can.Model({
data = JSON.parse( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = JSON.stringify(data);
......@@ -22,11 +22,11 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
})
});
return def;
},
......@@ -41,32 +41,32 @@ Todo = can.Model({
}
def.resolve({});
});
return def
return def;
},
create: function(attrs){
var def = new can.Deferred();
this.localStore(function(todos){
attrs.id = attrs.id || parseInt(100000 *Math.random());
attrs.id = attrs.id || parseInt(100000 *Math.random(), 10);
todos.push(attrs);
});
def.resolve({id : attrs.id});
return def
return def;
},
update: function(id, attrs){
var def = new can.Deferred();
var def = new can.Deferred(), todo;
this.localStore(function(todos){
for (var i = 0; i < todos.length; i++) {
if (todos[i].id === id) {
var todo = todos[i];
todo = todos[i];
break;
}
}
can.extend(todo, attrs);
});
def.resolve({});
return def
return def;
}
},{});
......@@ -79,8 +79,8 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
completed += todo.attr('complete') ? 1 : 0
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0;
});
return completed;
},
......@@ -166,7 +166,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all click' : function(el, ev) {
var toggle = el.prop('checked');
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......@@ -174,11 +174,13 @@ Todos = can.Control({
// Listen for removing all completed Todos
'#clear-completed click' : function() {
for (var i = this.options.todos.length - 1, todo; i > -1 && (todo = this.options.todos[i]); i--) {
todo.attr('complete') && todo.destroy();
if ( todo.attr('complete') ) {
todo.destroy();
}
}
}
})
});
// Initialize the app
Todo.findAll({}, function(todos) {
......@@ -187,4 +189,4 @@ Todo.findAll({}, function(todos) {
});
});
})();
\ No newline at end of file
})();
......@@ -10,7 +10,7 @@ Todo = can.Model({
data = JSON.decode( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = JSON.encode(data);
......@@ -22,7 +22,7 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
......@@ -79,7 +79,7 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0
});
return completed;
......@@ -170,7 +170,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all click' : function(el, ev) {
var toggle = el.get('checked')[0];
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......@@ -191,4 +191,4 @@ Todo.findAll({}, function(todos) {
});
});
})();
\ No newline at end of file
})();
......@@ -19,7 +19,7 @@ Todo = can.Model({
data = Y.JSON.parse( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = Y.JSON.stringify(data);
......@@ -31,7 +31,7 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
......@@ -115,7 +115,7 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0
});
return completed;
......@@ -210,7 +210,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all click' : function(el, ev) {
var toggle = el.get('checked');
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......@@ -273,4 +273,4 @@ Todo.findAll({}, function(todos) {
});
})();
\ No newline at end of file
})();
......@@ -12,7 +12,7 @@ Todo = can.Model({
data = Y.JSON.parse( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = Y.JSON.stringify(data);
......@@ -24,7 +24,7 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
......@@ -81,7 +81,7 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0
});
return completed;
......@@ -168,7 +168,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all click' : function(el, ev) {
var toggle = el.get('checked');
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......@@ -191,4 +191,4 @@ Todo.findAll({}, function(todos) {
});
})();
\ No newline at end of file
})();
......@@ -10,7 +10,7 @@ Todo = can.Model({
data = JSON.parse( window.localStorage[name] || (window.localStorage[name] = '[]') ),
res = cb.call(this, data);
if(res !== false){
can.each(data, function(i, todo) {
can.each(data, function(todo) {
delete todo.editing;
});
window.localStorage[name] = JSON.stringify(data);
......@@ -22,7 +22,7 @@ Todo = can.Model({
this.localStore(function(todos){
var instances = [],
self = this;
can.each(todos, function(i, todo) {
can.each(todos, function(todo) {
instances.push(new self(todo));
});
def.resolve({data: instances});
......@@ -79,7 +79,7 @@ Todo.List = can.Model.List({
this.attr('length');
var completed = 0;
this.each(function(i, todo) {
this.each(function(todo) {
completed += todo.attr('complete') ? 1 : 0
});
return completed;
......@@ -110,7 +110,7 @@ Todos = can.Control({
// Listen for when a new Todo has been entered
'#new-todo keyup' : function(el, ev){
if(ev.keyCode == 13){
if ( ev.keyCode == 13 ) {
new Todo({
text : el.val(),
complete : false
......@@ -168,7 +168,7 @@ Todos = can.Control({
// Listen for toggle all completed Todos
'#toggle-all change' : function(el, ev) {
var toggle = el[0].checked;
can.each(this.options.todos, function(i, todo) {
can.each(this.options.todos, function(todo) {
todo.attr('complete', toggle).save();
});
},
......@@ -189,4 +189,4 @@ Todo.findAll({}, function(todos) {
});
});
})();
\ 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