* added option to specify position of insertion for the add partial
This commit is contained in:
parent
dc1ad12845
commit
75c3a9bacd
@ -3,6 +3,8 @@ $(document).ready(function() {
|
|||||||
$('.add_fields').live('click', function() {
|
$('.add_fields').live('click', function() {
|
||||||
var assoc = $(this).attr('data-association');
|
var assoc = $(this).attr('data-association');
|
||||||
var content = $(this).siblings('#' + assoc + '_fields_template').html();
|
var content = $(this).siblings('#' + assoc + '_fields_template').html();
|
||||||
|
var insertionPosition = $(this).attr('data-association-insertion-position');
|
||||||
|
var insertionNode = $(this).attr('data-association-insertion-node');
|
||||||
var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g');
|
var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g');
|
||||||
var new_id = new Date().getTime();
|
var new_id = new Date().getTime();
|
||||||
var new_content = content.replace(regexp_braced, '[' + new_id + ']');
|
var new_content = content.replace(regexp_braced, '[' + new_id + ']');
|
||||||
@ -10,7 +12,19 @@ $(document).ready(function() {
|
|||||||
regexp_braced = new RegExp('\\[new_' + assoc + 's\\]', 'g');
|
regexp_braced = new RegExp('\\[new_' + assoc + 's\\]', 'g');
|
||||||
new_content = content.replace(regexp_braced, '[' + new_id + ']');
|
new_content = content.replace(regexp_braced, '[' + new_id + ']');
|
||||||
}
|
}
|
||||||
$(this).parent().before(new_content);
|
if (insertionNode) {
|
||||||
|
insertionNode = $(insertionNode);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
insertionNode = $(this).parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (insertionPosition == 'after'){
|
||||||
|
insertionNode.after(new_content);
|
||||||
|
} else {
|
||||||
|
insertionNode.before(new_content);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -25,4 +39,5 @@ $(document).ready(function() {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user