-
Notifications
You must be signed in to change notification settings - Fork 16
/
jquery.aCollapTable.min.js
1 lines (1 loc) · 2.71 KB
/
jquery.aCollapTable.min.js
1
!function(t){t.fn.extend({aCollapTable:function(a){var e={startCollapsed:!1,addColumn:!0,plusButton:"+",minusButton:"-"},a=t.extend(e,a),n=this,s=[],d=function(e,n,s,c){s="undefined"==typeof s?n.parents("tr").data("id"):s,c="undefined"==typeof c?n.hasClass("act-expanded")?"none":"table-row":c,t("tr[data-parent="+s+"]",e).each(function(a,s){t(s).css("display",c),t(s).hasClass("act-tr-expanded")&&d(e,n,t(s).data("id"),c)}),spacer=r(n.parents("tr")),"none"==c?(n.html(spacer+a.plusButton).removeClass("act-expanded").addClass("act-collapsed"),n.parents("tr").addClass("act-tr-collapsed").removeClass("act-tr-expanded")):(n.html(spacer+a.minusButton).removeClass("act-collapsed").addClass("act-expanded"),n.parents("tr").addClass("act-tr-expanded").removeClass("act-tr-collapsed"))},c=function(a){t("tr",a).each(function(a,e){t(e).data("id")&&($parentElement={id:t(e).data("id"),parent:t(e).data("parent")},s.push($parentElement))}),s=[],t("tr",a).each(function(a,e){t(e).data("id")&&(level=l(t(e)),t(e).attr("data-level",level))})},l=function(a,e){return e="undefined"==typeof e?0:e,""==a.data("parent")?e:($parentElement=t("tr[data-id="+a.data("parent")+"]"),l($parentElement,e+1))},r=function(t){for(spacer="",i=0;i<t.data("level");i++)spacer+=" ";return spacer},o=function(a){t(document).on("click",".act-button-expand",function(){t("tr",n).length>0&&(expands=[],t("tr",n).each(function(a,e){t(e).hasClass("act-tr-collapsed")&&"none"!=t(e).css("display")&&expands.push(t(e))}),t.each(expands,function(e,n){d(a,t(".act-more",n))}))}),t(document).on("click",".act-button-collapse",function(){t("tr",n).length>0}),t(document).on("click",".act-button-expand-all",function(){t("tr",n).length>0&&(collapseds=[],t("tr",n).each(function(a,e){t(e).hasClass("act-tr-collapsed")&&d(t(".act-more",t(e)))}))}),t(document).on("click",".act-button-collapse-all",function(){t("tr",n).length>0&&(collapseds=[],t("tr",n).each(function(a,e){t(e).hasClass("act-tr-expanded")&&d(t(".act-more",t(e)))}))})};return this.each(function(){var e=a,n=t(this);c(n),o(n),t("tr",n).length>0&&(t("tr",n).each(function(a,s){spacer=r(t(s)),$minus=t("<a />").attr("href","javascript:void(0)").addClass("act-more act-expanded").html(spacer+e.minusButton).bind("click",function(){d(n,t(this))}),t("tr[data-parent="+t(s).data("id")+"]",n).length>0?($button=1==e.addColumn?t("<td />").html($minus):$minus,itemClass=e.startCollapsed?"act-tr-collapsed":"act-tr-expanded",t(s).addClass(itemClass)):$button=1==e.addColumn?t("<td />").html(spacer+" "):spacer+" ",1==e.addColumn?t(s).prepend($button):t(s).children(":first").prepend($button),t(s).addClass("act-tr-level-"+t(s).data("level"))}),e.startCollapsed&&t(".act-more",n).each(function(a,e){t(e).click()}))})}})}(jQuery);