From 72d16756b169e1f751470670eececf76e88b2bd7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 27 Nov 2008 05:37:20 +0000 Subject: Refactor cloud generation into a helper so that we can call it from Tags_Controller::_index(). This enables our Ajax code to reload the tags block after we submit a new tag, so update the JS to do that properly. --- modules/tag/js/tag.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'modules/tag/js') diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js index 30e9ca50..fbcbd419 100644 --- a/modules/tag/js/tag.js +++ b/modules/tag/js/tag.js @@ -1,19 +1,17 @@ $("document").ready(function() { - var options = { - target: "#gTagFormContainer", - success: function(responseText, statusText) { - $("#gAddTag").ajaxForm(options); - } - }; - $("#gAddTag").ajaxForm(options); + ajaxify_tag_form(); }); -function get_tag_block(url) { - $.post(url, function(data) { - $('#gTagFormContainer').html(data); - $("#gAddTag").submit(function(event){ - get_tag_block($("#gAddTag").attr("action")); - return false; - }); +function ajaxify_tag_form() { + $("form#gAddTag").ajaxForm({ + complete: function(xhr, statusText) { + $("form#gAddTag").replaceWith(xhr.responseText); + if (xhr.status == 201) { + $.get($("#gTagCloud").attr("src"), function(data, textStatus) { + $("#gTagCloud").html(data); + }); + } + ajaxify_tag_form(); + } }); } -- cgit v1.2.3