From cebcb21242d4a898aab08f2dc89de3129f5b6f8f Mon Sep 17 00:00:00 2001 From: Tangerine Cat Date: Wed, 13 Apr 2011 16:08:25 +0600 Subject: [PATCH] Made available call to external jQuery callbacks on add_fields click --- lib/generators/cocoon/install/templates/cocoon.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/generators/cocoon/install/templates/cocoon.js b/lib/generators/cocoon/install/templates/cocoon.js index 0cc9544..50434ec 100644 --- a/lib/generators/cocoon/install/templates/cocoon.js +++ b/lib/generators/cocoon/install/templates/cocoon.js @@ -12,6 +12,7 @@ $(document).ready(function() { var content = $(this).attr('data-template'); var insertionPosition = $(this).attr('data-association-insertion-position'); var insertionNode = $(this).attr('data-association-insertion-node'); + var insertionCallback = $(this).data('insertion-callback'); var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g'); var regexp_underscord = new RegExp('_new_' + assoc + '_', 'g'); var new_id = new Date().getTime(); @@ -31,11 +32,17 @@ $(document).ready(function() { else { insertionNode = $(this).parent(); } + + var contentNode = $(new_content); if (insertionPosition == 'after'){ - insertionNode.after(new_content); + insertionNode.after(contentNode); } else { - insertionNode.before(new_content); + insertionNode.before(contentNode); + } + + if(insertionCallback){ + insertionCallback.call(contentNode); } return false;