From 75c3a9bacde0efc751df61b190592f31f097b4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihai=20T=C3=A2rnovan?= Date: Thu, 3 Mar 2011 19:22:23 +0100 Subject: [PATCH] * added option to specify position of insertion for the add partial --- .../cocoon/install/templates/cocoon.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/generators/cocoon/install/templates/cocoon.js b/lib/generators/cocoon/install/templates/cocoon.js index 0bec43b..e0b6d25 100644 --- a/lib/generators/cocoon/install/templates/cocoon.js +++ b/lib/generators/cocoon/install/templates/cocoon.js @@ -3,6 +3,8 @@ $(document).ready(function() { $('.add_fields').live('click', function() { var assoc = $(this).attr('data-association'); 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 new_id = new Date().getTime(); var new_content = content.replace(regexp_braced, '[' + new_id + ']'); @@ -10,7 +12,19 @@ $(document).ready(function() { regexp_braced = new RegExp('\\[new_' + assoc + 's\\]', 'g'); 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; }); @@ -25,4 +39,5 @@ $(document).ready(function() { return false; }); -}); \ No newline at end of file +}); +