You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
3.9 KiB
JavaScript
2 lines
3.9 KiB
JavaScript
/*! © Nick Adkinson, SpryMedia Ltd - datatables.net/license */
|
|
import $ from"jquery";import DataTable from"datatables.net";var SlidingChild=function(i,t){var o=this,d=(i.on("draw",function(){o._updateFadedRows()}),i.table()),n=document.createElement("div");n.className="slider",this.s=$.extend({},{dt:i,table:$(d.node()),slider:$(n)},SlidingChild.defaults,t),this._bind()};SlidingChild.prototype._bind=function(){var t=this,o=t.s;$(o.table,"> tbody").on("click",o.selector,function(){var i=$(this),i=i.is("tr")?i:i.closest("tr");i.is("tr")&&(i=o.dt.row(i),t._toggleChild(i))})},SlidingChild.prototype._toggleChild=function(i){var t,o=this.s;i.child.isShown()?this._hideChild(i,function(){}):(t=o.dt.row(".shown")).length&&o.toggle?this._hideChild(t,this._showChildCallback(i)):this._showChild(i)},SlidingChild.prototype._showChildCallback=function(i){return function(i){this._showChild(i)}.bind(this,i)},SlidingChild.prototype._showChild=function(i){var t=$(i.node());this.s.displayLoadingIndicator&&this._addLoadingIndicator(t),this.s.source(t,this._response(i))},SlidingChild.prototype._response=function(i){return function(i,t){this.__showChild(i,t)}.bind(this,i)},SlidingChild.prototype.__showChild=function(i,t){var o=this.s,d=o.slider,n=$(i.node());o.displayLoadingIndicator&&$("."+this.s.loadingIndicatorClass).remove(),d.append(t),i.child(d,o.childClass).show(),n.toggleClass("shown"),this._updateFadedRows(),o.animateShow?this._showChildWithAnimation(i):this._showChildWithoutAnimation(i)},SlidingChild.prototype._showChildWithAnimation=function(i){var t=this.s;$(t.slider,i.child()).slideDown(t.animationSpeed,function(){t.onShown(i)})},SlidingChild.prototype._showChildWithoutAnimation=function(i){var t=this.s;$(t.slider,i.child()).show(),t.onShown(i)},SlidingChild.prototype._hideChild=function(i,t){var o=this.s;$(i.node()).toggleClass("shown"),this._updateFadedRows(),o.animateHide?this._hideChildWithAnimation(i,t):this._hideChildWithoutAnimation(i,t)},SlidingChild.prototype._hideChildWithAnimation=function(i,t){var o=this.s,d=o.slider;$(d,i.child()).slideUp(o.animationSpeed,function(){i.child.remove(),d.empty(),o.onHidden(i),t()})},SlidingChild.prototype._hideChildWithoutAnimation=function(i,t){var o=this.s,d=o.slider;$(d,i.child()).hide(),i.child.remove(),d.empty(),o.onHidden(i),t()},SlidingChild.prototype._updateFadedRows=function(){this.s.fadeNonShowingRows?(this._fadeNonShowingRows(),this._removeFadeFromShowingRows()):this._removeFadeFromRows()},SlidingChild.prototype._fadeNonShowingRows=function(){this.s.dt.rows(".shown:visible").count()?this.s.dt.rows(":visible:not(.shown):not(.faded)").nodes().to$().css("opacity",this.s.fadeOpacity).addClass("faded"):this._removeFadeFromRows()},SlidingChild.prototype._removeFadeFromShowingRows=function(){this.s.dt.rows(".shown.faded:visible").nodes().to$().css("opacity",1).removeClass("faded")},SlidingChild.prototype._removeFadeFromRows=function(){this.s.dt.rows(".faded").nodes().to$().css("opacity",1).removeClass("faded")};const options={selector:"tr",childClass:"child",source:function(){},toggle:!0,animateShow:!0,animateHide:!0,fadeNonShowingRows:!(SlidingChild.prototype._addLoadingIndicator=function(i){var t=i.position(),o=$(this.s.loadingIndicatorContent);o.addClass(this.s.loadingIndicatorClass),o.css("top",t.top),o.css("left",t.left),o.css("height",i.height()),i.append(o)}),fadeOpacity:.4,animationSpeed:200,onShown:function(){},onHidden:function(){},displayLoadingIndicator:!1,loadingIndicatorClass:"loading-indicator",loadingIndicatorContent:'<div style="background: black; color: white; display: flex; align-items: center; justify-content: center; opacity: 0.5; position: absolute; width: 100%; z-index: 100;">Loading...</div>'};SlidingChild.defaults=options,DataTable.SlidingChild=SlidingChild,$(document).on("init.dt",function(i,t){"dt"===i.namespace&&(i=new DataTable.Api(t),$(i.table().node()).hasClass("slidingChild")||t.oInit.slidingChild||DataTable.defaults.slidingChild)&&new SlidingChild(i,t.oInit.slidingChild)});export default DataTable; |