-
-
Save anlek/440149 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 delete_field = item.first('input.delete'); | |
var options = {}; | |
if (delete_field) { | |
delete_field.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