jlindley (owner)

Revisions

  • 606858 jlindley Tue Jul 22 11:39:56 -0700 2008
  • 81abc8 jlindley Tue Jul 22 09:08:18 -0700 2008
  • 7a2d3e jlindley Mon Jul 21 20:02:14 -0700 2008
  • fcdaf5 jlindley Mon Jul 21 19:18:07 -0700 2008
gist: 608 Download_button fork
public
Description:
Merb/jQuery: add delete method to destroy links.
Public Clone URL: git://gist.github.com/608.git
Embed All Files: show embed
jquery.deletable.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
29
// Make merb resource route url link_to's with class deletable fake delete HTTP method.
 
jQuery.fn.deletable = function() {
    return this.each(function() {
        var delete_link = $(this);
        var hidden_form = document.createElement('form');
        hidden_form.style.display = 'none';
        delete_link.append(hidden_form);
        hidden_form.method = 'POST';
        hidden_form.action = delete_link.attr('href');
        var method_input = document.createElement('input');
        method_input.setAttribute('type', 'hidden');
        method_input.setAttribute('name', '_method');
        method_input.setAttribute('value', 'delete');
        hidden_form.appendChild(method_input);
        this.form = hidden_form;
        delete_link.click(function() {
if (confirm("Are you sure?")){
this.form.submit();
}
            return false;
        });
    });
};
 
$(document).ready(function() {
    $('a.deletable').deletable();
})