Forked from zachinglis/unobtrusive_put_post_links.js
Created
August 21, 2008 21:10
-
-
Save kneath/6643 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(document).ready(function($) { | |
| var form_to_link = $('.form_to_link'); | |
| var form = form_to_link.parents('form'); | |
| // Ripped from Rails | |
| var onclick = "var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', " + form_to_link.siblings('[name=_method]').attr('value') + "); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'authenticity_tokenhidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', "+ form_to_link.siblings('[name=authenticity_token]').attr('value') + "); f.appendChild(s);f.submit();return false;"; | |
| form.replaceWith('<a href="' + form.attr('action') + '" onclick="' + onclick + '">' + form_to_link.attr('value') + '</a>'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment