diff options
Diffstat (limited to 'public/javascripts/application.js')
-rw-r--r-- | public/javascripts/application.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 91ebabd..1e7e338 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -183,6 +183,40 @@ $(document).ready(function() { years: "%d years" }); jQuery('abbr.timeago').timeago(); + + jQuery.each(jQuery("a[data-request-method]"), function (){ + var action = $(this).attr("href"); + var httpMethod = $(this).attr("data-request-method"); + $(this).attr("onclick", ""); + var newElement = jQuery("<a>"); + newElement.html($(this).html()); + newElement.insertAfter($(this)); + $(this).hide(); + newElement.bind("click", function (){ + newElement.removeClass("waiting").addClass("waiting"); + jQuery.ajax({ + url: action, + type: "post", + data: {"_method": httpMethod}, + success: function (data, status) { + if (httpMethod == "post") { + newElement.html(newElement.html().replace("Start","Stop")); + httpMethod = "delete" + } + else { + newElement.html(newElement.html().replace("Stop","Start")); + httpMethod = "post" + } + + }, + complete: function(xhr, textStatus) { + newElement.removeClass("waiting"); + action = xhr.getResponseHeader("Location"); + } + }); + return false; + }); + }) }); if (!Gitorious) |