$(function() { $("body").on("ajax:success", ".abracadabra-form", function(e) { $(e.target).find(".abracadabra-cancel").click(); }) $("body").on("click", ".abracadabra-cancel", function() { container = $(this).closest(".abracadabra-container"); value = $(this).parents(".abracadabra-buttons").siblings().find("input").val(); container.siblings(".abracadabra").text(value).show(); $(this).closest(".abracadabra-container").remove(); }); $("body").on("keydown", ".abracadabra-input input", function(e) { if (e.which == 9) { e.preventDefault(); $(this.form).submit(); } }); $(".abracadabra").on("click", function() { link = $(this); link.hide(); path = link.data("path"); attribute = link.data("attribute"); form_method = link.data("method"); remote = ((link.data("remote") == true) ? " data-remote='true'" : ""); if(remote == "") { auth_token = ""; type = ""; } else { auth_token = ""; type = " data-type='" + link.data("type") + "'"; } instance_class = link.data("class"); input_value = link.text(); input_id = instance_class + "_" + attribute; input_name = instance_class + "[" + attribute + "]"; buttons = ""; open_form_tag = "
"; hidden_method_tags = "
" + auth_token + "
"; input = ""; html = "" + open_form_tag + hidden_method_tags; html += "
" + input + "
"; html += "
" + buttons + "
"; link.after(html); }); });