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.
Revisions
-
kneath revised this gist
Aug 21, 2008 . 1 changed file with 11 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,13 +4,16 @@ // button_to "New Alert", new_alert // jQuery(document).ready(function($) { jQuery('.form_to_link').each(function(el){ var form = el.parents('form'); form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>'); form.hide(); el.getElementsBySelector('.button_link_to').click(function(){ form.submit(); return false; }); }) }); -
zachinglis revised this gist
Aug 21, 2008 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,12 @@ // button_to "New Alert", new_alert // jQuery(document).ready(function($) { var form_to_link = jQuery('.form_to_link'); var form = form_to_link.parents('form'); form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>'); form.hide(); jQuery('.button_link_to').click(function(){ form.submit(); return false; }); -
zachinglis revised this gist
Aug 21, 2008 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,11 @@ jQuery(document).ready(function($) { var form_to_link = $('.form_to_link'); var form = form_to_link.parents('form'); form.after('<a href="' + form.attr('action') + '" class="button_link_to">' + form_to_link.attr('value') + '</a>'); form.hide(); $('.button_link_to').click(function(){ form.submit(); return false; }); }); -
zachinglis revised this gist
Aug 21, 2008 . 1 changed file with 2 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,6 @@ jQuery(document).ready(function($) { var form_to_link = $('.form_to_link'); var form = form_to_link.parents('form'); form.after('<a href="' + form.attr('action') + '" onclick="form.submit();">' + form_to_link.attr('value') + '</a>'); form.hide(); }); -
zachinglis revised this gist
Aug 21, 2008 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,8 @@ // Examples: // // button_to "Mark as unread", mark_as_unread_message_path(message), :method => :put, :class => "form_to_link" // button_to "New Alert", new_alert // jQuery(document).ready(function($) { var form_to_link = $('.form_to_link'); var form = form_to_link.parents('form'); @@ -6,4 +11,4 @@ jQuery(document).ready(function($) { 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>'); }); -
zachinglis renamed this gist
Aug 21, 2008 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zachinglis renamed this gist
Aug 21, 2008 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zachinglis created this gist
Aug 21, 2008 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ 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>'); });