ReinH (owner)

Fork Of

Forks

Revisions

gist: 7308 Download_button fork
public
Public Clone URL: git://gist.github.com/7308.git
Embed All Files: show embed
unobtrusive_put_post_links.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Examples:
//
// HTML:
// <form action='messages/1/mark_unread'><input type='submit' class='button_to_link' value='Mark Unread'/></form>
//
// Rails:
// button_to "Mark as unread", mark_as_unread_message_path(message), :method => :put, :class => "button_to_link"
//
// jQuery:
// $(document).ready(function() {
// $('.button_to_link').button_to_link()
// });
//
jQuery.fn.button_to_link = function() {
  // return the jQuery object for chaining
  return this.each(function(button){
    var form = button.parents('form');
    form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + button.attr('value') + '</a>');
    form.hide();
    
    form.next('a.button_link_to').click(function(){
      form.submit();
      return false;
    });
  })
});
 
// Or you could just use a button and style it.