/
patuta.min.js
1 lines (1 loc) · 1.64 KB
/
patuta.min.js
1
!function(t){t.fn.patuta=function(e){var d=t.extend({addBtn:"addRowBtn",removeBtn:"removeRowBtn"},e);function n(e){if(""!=e){var n=e.parents(".add-remove-tbl:eq(0)"),o=t(n).find("table")[0],r=t(n).find("."+d.removeBtn);if(1==t(o).hasClass("nested")){var i=t(o).find("tbody>tr").length;if(1==t(e).hasClass("removeRowBtn"))if(2==i){t(e).closest("tr").remove();var s=t(o).find("tbody>tr");t(s).find("td").last().find("."+d.removeBtn).hide()}else{t(e).closest("tr").remove();s=t(o).find("tbody>tr").not("tbody>tr>td>table>tbody>tr");t(s).find("td").last().find("."+d.removeBtn).show()}else t(r).show()}else{i=t(o).find("tbody>tr").not("tbody>tr>td>table>tbody>tr").length;if(1==t(e).hasClass("removeRowBtn"))if(2==i){t(e).closest("tr").remove();s=t(o).find("tbody>tr").not("tbody>tr>td>table>tbody>tr");t(s).find("td").last().find("."+d.removeBtn).hide()}else{t(e).closest("tr").remove();s=t(o).find("tbody>tr").not("tbody>tr>td>table>tbody>tr");t(s).find("td").last().find("."+d.removeBtn).show()}else{s=t(o).find("tbody>tr").not("tbody>tr>td>table>tbody>tr");t(s).each(function(){t(this).find("td").last().find("."+d.removeBtn).show()})}}}}t("."+d.removeBtn).hide(),t("body").on("click","."+d.addBtn,function(){var e=t(this).parents().eq(1),o=t(e).find("table").first(),r=t(o).find("tbody").first();t(o).find("."+d.removeBtn);if(t(o).hasClass("nested"))t(o).find("tbody tr").first().clone().appendTo(r);else t(o).find("tbody tr").first().clone().find(".nested tbody tr:not(:first-child)").remove().end().find(".nested tbody tr td:last-child ."+d.removeBtn).css("display","none").end().appendTo(r);n(t(this))}),t("body").on("click","."+d.removeBtn,function(){n(t(this))})}}(jQuery);