diff options
author | Marius Mathiesen <marius@shortcut.no> | 2009-11-26 15:42:24 +0100 |
---|---|---|
committer | Marius Mathiesen <marius@shortcut.no> | 2009-12-03 14:18:58 +0100 |
commit | c753d1dbaa667dc9382c28f5942d95f46a1b765f (patch) | |
tree | 8559c60b81806d4861d1ca3f5e6254cd4e4df1e8 /public/javascripts/application.js | |
parent | e45da1cce6d9e71605c29c9c0672203f3fec0824 (diff) | |
download | gitorious-mainline-outdated-c753d1dbaa667dc9382c28f5942d95f46a1b765f.zip gitorious-mainline-outdated-c753d1dbaa667dc9382c28f5942d95f46a1b765f.tar.gz gitorious-mainline-outdated-c753d1dbaa667dc9382c28f5942d95f46a1b765f.tar.bz2 |
Hook into the create/delete actions for watching with some Ajax goodness
- Add a custom attr to the a tags
- Replace the obtrusive Rails actions with some homebrew
- Favorites#{create,destroy} now supplies a Location header intercepted by javascript
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) |