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.
Plugins/features/slidingChild/datatables.slidingChild.min.js

2 lines
4.0 KiB
JavaScript

/*! © Nick Adkinson, SpryMedia Ltd - datatables.net/license */
!function(o){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(i){return o(i,window,document)}):"object"==typeof exports?module.exports=function(i,t){return i=i||window,(t=t||("undefined"!=typeof window?require("jquery"):require("jquery")(i))).fn.dataTable||require("datatables.net")(i,t),o(t,0,i.document)}:o(jQuery,window,document)}(function(d,i,s,t){"use strict";function a(i,t){var o=this,n=(i.on("draw",function(){o._updateFadedRows()}),i.table()),e=s.createElement("div");e.className="slider",this.s=d.extend({},{dt:i,table:d(n.node()),slider:d(e)},a.defaults,t),this._bind()}var o=d.fn.dataTable;a.prototype._bind=function(){var t=this,o=t.s;d(o.table,"> tbody").on("click",o.selector,function(){var i=d(this),i=i.is("tr")?i:i.closest("tr");i.is("tr")&&(i=o.dt.row(i),t._toggleChild(i))})},a.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)},a.prototype._showChildCallback=function(i){return function(i){this._showChild(i)}.bind(this,i)},a.prototype._showChild=function(i){var t=d(i.node());this.s.displayLoadingIndicator&&this._addLoadingIndicator(t),this.s.source(t,this._response(i))},a.prototype._response=function(i){return function(i,t){this.__showChild(i,t)}.bind(this,i)},a.prototype.__showChild=function(i,t){var o=this.s,n=o.slider,e=d(i.node());o.displayLoadingIndicator&&d("."+this.s.loadingIndicatorClass).remove(),n.append(t),i.child(n,o.childClass).show(),e.toggleClass("shown"),this._updateFadedRows(),o.animateShow?this._showChildWithAnimation(i):this._showChildWithoutAnimation(i)},a.prototype._showChildWithAnimation=function(i){var t=this.s;d(t.slider,i.child()).slideDown(t.animationSpeed,function(){t.onShown(i)})},a.prototype._showChildWithoutAnimation=function(i){var t=this.s;d(t.slider,i.child()).show(),t.onShown(i)},a.prototype._hideChild=function(i,t){var o=this.s;d(i.node()).toggleClass("shown"),this._updateFadedRows(),o.animateHide?this._hideChildWithAnimation(i,t):this._hideChildWithoutAnimation(i,t)},a.prototype._hideChildWithAnimation=function(i,t){var o=this.s,n=o.slider;d(n,i.child()).slideUp(o.animationSpeed,function(){i.child.remove(),n.empty(),o.onHidden(i),t()})},a.prototype._hideChildWithoutAnimation=function(i,t){var o=this.s,n=o.slider;d(n,i.child()).hide(),i.child.remove(),n.empty(),o.onHidden(i),t()},a.prototype._updateFadedRows=function(){this.s.fadeNonShowingRows?(this._fadeNonShowingRows(),this._removeFadeFromShowingRows()):this._removeFadeFromRows()},a.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()},a.prototype._removeFadeFromShowingRows=function(){this.s.dt.rows(".shown.faded:visible").nodes().to$().css("opacity",1).removeClass("faded")},a.prototype._removeFadeFromRows=function(){this.s.dt.rows(".faded").nodes().to$().css("opacity",1).removeClass("faded")},a.prototype._addLoadingIndicator=function(i){var t=i.position(),o=d(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)};return a.defaults={selector:"tr",childClass:"child",source:function(){},toggle:!0,animateShow:!0,animateHide:!0,fadeNonShowingRows:!1,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>'},o.SlidingChild=a,d(s).on("init.dt",function(i,t){"dt"===i.namespace&&(i=new o.Api(t),d(i.table().node()).hasClass("slidingChild")||t.oInit.slidingChild||o.defaults.slidingChild)&&new a(i,t.oInit.slidingChild)}),o});