Skip to content

Instantly share code, notes, and snippets.

@rightjs
Created June 5, 2010 06:48
Show Gist options
  • Save rightjs/426379 to your computer and use it in GitHub Desktop.
Save rightjs/426379 to your computer and use it in GitHub Desktop.
var Driver = {
add: function(event) {
event.stop();
$(this.get('rel'))
.insert(Driver.template(this))
.subNodes().last().show('fade');
},
remove: function(event) {
event.stop();
var item = this.parent('.item');
var link = item.first('a.delete');
var options = {};
if (link) {
link.first('input').value = 1;
} else {
options.onFinish = item.remove.bind(item);
}
item.hide('fade', options);
},
template: function(element) {
return window[element.parent('.nested').get('data-template')]
.replace(/NEW_RECORD/g, new Date().getTime());
}
};
".nested .add_nested".on('click', Driver.add);
".nested .remove_nested".on('click', Driver.remove);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment