Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kneath/6643 to your computer and use it in GitHub Desktop.

Select an option

Save kneath/6643 to your computer and use it in GitHub Desktop.

Revisions

  1. kneath revised this gist Aug 21, 2008. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions unobtrusive_put_post_links.js
    Original file line number Diff line number Diff line change
    @@ -4,13 +4,16 @@
    // 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('.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;
    });
    })


    jQuery('.button_link_to').click(function(){
    form.submit();
    return false;
    });
    });
  2. @zachinglis zachinglis revised this gist Aug 21, 2008. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions unobtrusive_put_post_links.js
    Original 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 = $('.form_to_link');
    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();

    $('.button_link_to').click(function(){
    jQuery('.button_link_to').click(function(){
    form.submit();
    return false;
    });
  3. @zachinglis zachinglis revised this gist Aug 21, 2008. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion unobtrusive_put_post_links.js
    Original 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') + '" onclick="form.submit();">' + form_to_link.attr('value') + '</a>');
    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;
    });
    });
  4. @zachinglis zachinglis revised this gist Aug 21, 2008. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions unobtrusive_put_post_links.js
    Original 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');

    // 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>');
    form.after('<a href="' + form.attr('action') + '" onclick="form.submit();">' + form_to_link.attr('value') + '</a>');
    form.hide();
    });
  5. @zachinglis zachinglis revised this gist Aug 21, 2008. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion unobtrusive_put_post_links.js
    Original 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>');
    });
    });
  6. @zachinglis zachinglis renamed this gist Aug 21, 2008. 1 changed file with 0 additions and 0 deletions.
  7. @zachinglis zachinglis renamed this gist Aug 21, 2008. 1 changed file with 0 additions and 0 deletions.
  8. @zachinglis zachinglis created this gist Aug 21, 2008.
    9 changes: 9 additions & 0 deletions button_to to link_to unobtrusively
    Original 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>');
    });