Skip to content

Instantly share code, notes, and snippets.

@quackingduck
Created September 16, 2009 06:12
Show Gist options
  • Save quackingduck/187903 to your computer and use it in GitHub Desktop.
Save quackingduck/187903 to your computer and use it in GitHub Desktop.
var $item = $('.item').remove().
methods({
load: function(attribs) {
this.set(attribs);
this.e.trigger('item:loaded',this);
return this;
},
set: function(attribs) {
this.id = attribs.id;
this.find('.content input').val(attribs.content);
return this;
}
}).
end();
$('#items').
find('> .add button').
click(function() { $(this).tigger('items:new') }).
end().
bind('items:new', function() { $(this).c().add() }).
methods({
load: function(items) {
var self = this;
$.each(items, function() { self.add().load(this) });
},
add: function() {
return $item.cloneWithMethods().show().appendTo(this.e.find('.items'));
}
});
$(document).bind('items:loaded', function(e, items) {
$('#items').c().load(items)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment