TIF_E41201544/public/assets/libs/datatables.net-colreorder/js/dataTables.colReorder.min.mjs

4 lines
13 KiB
JavaScript

/*! ColReorder 1.6.2
* © SpryMedia Ltd - datatables.net/license
*/
import $ from"jquery";import DataTable from"datatables.net";function fnInvertKeyValues(t){for(var e=[],o=0,n=t.length;o<n;o++)e[t[o]]=o;return e}function fnArraySwitch(t,e,o){e=t.splice(e,1)[0];t.splice(o,0,e)}function fnDomSwitch(t,e,o){for(var n=[],r=0,s=t.childNodes.length;r<s;r++)1==t.childNodes[r].nodeType&&n.push(t.childNodes[r]);e=n[e];null!==o?t.insertBefore(e,n[o]):t.appendChild(e)}$.fn.dataTableExt.oApi.fnColReorder=function(o,t,e,n,r){function s(t,e,o){var n,r;t[e]&&"function"!=typeof t[e]&&(r=(n=t[e].split(".")).shift(),isNaN(+r)||(t[e]=o[+r]+"."+n.join(".")))}var i,a,l,d,f,h,u=o.aoColumns.length;if(t!=e)if(t<0||u<=t)this.oApi._fnLog(o,1,"ColReorder 'from' index is out of bounds: "+t);else if(e<0||u<=e)this.oApi._fnLog(o,1,"ColReorder 'to' index is out of bounds: "+e);else{var c=[];for(p=0,i=u;p<i;p++)c[p]=p;fnArraySwitch(c,t,e);var C=fnInvertKeyValues(c);for(p=0,i=o.aaSorting.length;p<i;p++)o.aaSorting[p][0]=C[o.aaSorting[p][0]];if(null!==o.aaSortingFixed)for(p=0,i=o.aaSortingFixed.length;p<i;p++)o.aaSortingFixed[p][0]=C[o.aaSortingFixed[p][0]];for(p=0,i=u;p<i;p++){for(a=0,l=(h=o.aoColumns[p]).aDataSort.length;a<l;a++)h.aDataSort[a]=C[h.aDataSort[a]];h.idx=C[h.idx]}for($.each(o.aLastSort,function(t,e){o.aLastSort[t].src=C[e.src]}),p=0,i=u;p<i;p++)"number"==typeof(h=o.aoColumns[p]).mData?h.mData=C[h.mData]:$.isPlainObject(h.mData)&&(s(h.mData,"_",C),s(h.mData,"filter",C),s(h.mData,"sort",C),s(h.mData,"type",C));if(o.aoColumns[t].bVisible){for(var g=this.oApi._fnColumnIndexToVisible(o,t),m=null,p=e<t?e:e+1;null===m&&p<u;)m=this.oApi._fnColumnIndexToVisible(o,p),p++;for(p=0,i=(f=o.nTHead.getElementsByTagName("tr")).length;p<i;p++)fnDomSwitch(f[p],g,m);if(null!==o.nTFoot)for(p=0,i=(f=o.nTFoot.getElementsByTagName("tr")).length;p<i;p++)fnDomSwitch(f[p],g,m);for(p=0,i=o.aoData.length;p<i;p++)null!==o.aoData[p].nTr&&fnDomSwitch(o.aoData[p].nTr,g,m)}for(fnArraySwitch(o.aoColumns,t,e),p=0,i=u;p<i;p++)o.oApi._fnColumnOptions(o,p,{});for(fnArraySwitch(o.aoPreSearchCols,t,e),p=0,i=o.aoData.length;p<i;p++){var R=o.aoData[p],_=R.anCells;if(_)for(fnArraySwitch(_,t,e),a=0,d=_.length;a<d;a++)_[a]&&_[a]._DT_CellIndex&&(_[a]._DT_CellIndex.column=a);Array.isArray(R._aData)&&fnArraySwitch(R._aData,t,e)}for(p=0,i=o.aoHeader.length;p<i;p++)fnArraySwitch(o.aoHeader[p],t,e);if(null!==o.aoFooter)for(p=0,i=o.aoFooter.length;p<i;p++)fnArraySwitch(o.aoFooter[p],t,e);for(!r&&void 0!==r||$.fn.dataTable.Api(o).rows().invalidate("data"),p=0,i=u;p<i;p++)$(o.aoColumns[p].nTh).off(".DT"),this.oApi._fnSortAttachListener(o,o.aoColumns[p].nTh,p);$(o.oInstance).trigger("column-reorder.dt",[o,{from:t,to:e,mapping:C,drop:n,iFrom:t,iTo:e,aiInvertMapping:C}])}};var ColReorder=function(t,e){t=new $.fn.dataTable.Api(t).settings()[0];if(t._colReorder)return t._colReorder;!0===e&&(e={});var o=$.fn.dataTable.camelToHungarian;return o&&(o(ColReorder.defaults,ColReorder.defaults,!0),o(ColReorder.defaults,e||{})),this.s={dt:null,enable:null,init:$.extend(!0,{},ColReorder.defaults,e),fixed:0,fixedRight:0,reorderCallback:null,mouse:{startX:-1,startY:-1,offsetX:-1,offsetY:-1,target:-1,targetIndex:-1,fromIndex:-1},aoTargets:[]},this.dom={drag:null,pointer:null},this.s.enable=this.s.init.bEnable,this.s.dt=t,(this.s.dt._colReorder=this)._fnConstruct(),this};$.extend(ColReorder.prototype,{fnEnable:function(t){if(!1===t)return this.fnDisable();this.s.enable=!0},fnDisable:function(){this.s.enable=!1},fnReset:function(){return this._fnOrderColumns(this.fnOrder()),this},fnGetCurrentOrder:function(){return this.fnOrder()},fnOrder:function(t,e){var o=[],n=this.s.dt.aoColumns;if(void 0===t){for(s=0,i=n.length;s<i;s++)o.push(n[s]._ColReorder_iOrigCol);return o}if(e){for(var r=this.fnOrder(),s=0,i=t.length;s<i;s++)o.push($.inArray(t[s],r));t=o}return this._fnOrderColumns(fnInvertKeyValues(t)),this},fnTranspose:function(t,e){e=e||"toCurrent";var o=this.fnOrder(),n=this.s.dt.aoColumns;return"toCurrent"===e?Array.isArray(t)?$.map(t,function(t){return $.inArray(t,o)}):$.inArray(t,o):Array.isArray(t)?$.map(t,function(t){return n[t]._ColReorder_iOrigCol}):n[t]._ColReorder_iOrigCol},_fnConstruct:function(){var t,o=this,e=this.s.dt.aoColumns.length,n=this.s.dt.nTable;for(this.s.init.iFixedColumns&&(this.s.fixed=this.s.init.iFixedColumns),this.s.init.iFixedColumnsLeft&&(this.s.fixed=this.s.init.iFixedColumnsLeft),this.s.fixedRight=this.s.init.iFixedColumnsRight||0,this.s.init.fnReorderCallback&&(this.s.reorderCallback=this.s.init.fnReorderCallback),t=0;t<e;t++)t>this.s.fixed-1&&t<e-this.s.fixedRight&&this._fnMouseListener(t,this.s.dt.aoColumns[t].nTh),this.s.dt.aoColumns[t]._ColReorder_iOrigCol=t;this.s.dt.oApi._fnCallbackReg(this.s.dt,"aoStateSaveParams",function(t,e){o._fnStateSave.call(o,e)},"ColReorder_State"),this.s.dt.oApi._fnCallbackReg(this.s.dt,"aoStateLoadParams",function(t,e){o.s.dt._colReorder.fnOrder(e.ColReorder,!0)});var r,s,i=null;this.s.init.aiOrder&&(i=this.s.init.aiOrder.slice()),(i=this.s.dt.oLoadedState&&void 0!==this.s.dt.oLoadedState.ColReorder&&this.s.dt.oLoadedState.ColReorder.length==this.s.dt.aoColumns.length?this.s.dt.oLoadedState.ColReorder:i)?o.s.dt._bInitComplete?(r=fnInvertKeyValues(i),o._fnOrderColumns.call(o,r)):(s=!1,$(n).on("draw.dt.colReorder",function(){var t;o.s.dt._bInitComplete||s||(s=!0,t=fnInvertKeyValues(i),o._fnOrderColumns.call(o,t))})):this._fnSetColumnIndexes(),$(n).on("destroy.dt.colReorder",function(){o.fnReset(),$(n).off("destroy.dt.colReorder draw.dt.colReorder"),$.each(o.s.dt.aoColumns,function(t,e){$(e.nTh).off(".ColReorder"),$(e.nTh).removeAttr("data-column-index")}),o.s.dt._colReorder=null,o.s=null})},_fnOrderColumns:function(t){var e=!1;if(t.length!=this.s.dt.aoColumns.length)this.s.dt.oInstance.oApi._fnLog(this.s.dt,1,"ColReorder - array reorder does not match known number of columns. Skipping.");else{for(var o=0,n=t.length;o<n;o++){var r=$.inArray(o,t);o!=r&&(fnArraySwitch(t,r,o),this.s.dt.oInstance.fnColReorder(r,o,!0,!1),e=!0)}this._fnSetColumnIndexes(),e&&($.fn.dataTable.Api(this.s.dt).rows().invalidate("data"),""===this.s.dt.oScroll.sX&&""===this.s.dt.oScroll.sY||this.s.dt.oInstance.fnAdjustColumnSizing(!1),this.s.dt.oInstance.oApi._fnSaveState(this.s.dt),null!==this.s.reorderCallback&&this.s.reorderCallback.call(this))}},_fnStateSave:function(t){if(null!==this.s){var e,o=this.s.dt.aoColumns;if(t.ColReorder=[],t.aaSorting){for(r=0;r<t.aaSorting.length;r++)t.aaSorting[r][0]=o[t.aaSorting[r][0]]._ColReorder_iOrigCol;for(var n=$.extend(!0,[],t.aoSearchCols),r=0,s=o.length;r<s;r++)e=o[r]._ColReorder_iOrigCol,t.aoSearchCols[e]=n[r],t.abVisCols[e]=o[r].bVisible,t.ColReorder.push(e)}else if(t.order){for(r=0;r<t.order.length;r++)t.order[r][0]=o[t.order[r][0]]._ColReorder_iOrigCol;var i=$.extend(!0,[],t.columns);for(r=0,s=o.length;r<s;r++)e=o[r]._ColReorder_iOrigCol,t.columns[e]=i[r],t.ColReorder.push(e)}}},_fnMouseListener:function(t,e){var o=this;$(e).on("mousedown.ColReorder",function(t){o.s.enable&&1===t.which&&o._fnMouseDown.call(o,t,e)}).on("touchstart.ColReorder",function(t){o.s.enable&&o._fnMouseDown.call(o,t,e)})},_fnMouseDown:function(t,e){var o=this,n=$(t.target).closest("th, td").offset(),e=parseInt($(e).attr("data-column-index"),10);void 0!==e&&(this.s.mouse.startX=this._fnCursorPosition(t,"pageX"),this.s.mouse.startY=this._fnCursorPosition(t,"pageY"),this.s.mouse.offsetX=this._fnCursorPosition(t,"pageX")-n.left,this.s.mouse.offsetY=this._fnCursorPosition(t,"pageY")-n.top,this.s.mouse.target=this.s.dt.aoColumns[e].nTh,this.s.mouse.targetIndex=e,this.s.mouse.fromIndex=e,this._fnRegions(),$(document).on("mousemove.ColReorder touchmove.ColReorder",function(t){o._fnMouseMove.call(o,t)}).on("mouseup.ColReorder touchend.ColReorder",function(t){o._fnMouseUp.call(o,t)}))},_fnMouseMove:function(t){var e,o=this;if(null===this.dom.drag){if(Math.pow(Math.pow(this._fnCursorPosition(t,"pageX")-this.s.mouse.startX,2)+Math.pow(this._fnCursorPosition(t,"pageY")-this.s.mouse.startY,2),.5)<5)return;this._fnCreateDragNode()}this.dom.drag.css({left:this._fnCursorPosition(t,"pageX")-this.s.mouse.offsetX,top:this._fnCursorPosition(t,"pageY")-this.s.mouse.offsetY});function n(){for(var t=o.s.aoTargets.length-1;0<t;t--)if(o.s.aoTargets[t].x!==o.s.aoTargets[t-1].x)return o.s.aoTargets[t]}for(var r=this.s.mouse.toIndex,s=this._fnCursorPosition(t,"pageX"),i=1;i<this.s.aoTargets.length;i++){var a=function(t){for(;0<=t;){if(--t<=0)return null;if(o.s.aoTargets[t+1].x!==o.s.aoTargets[t].x)return o.s.aoTargets[t]}}(i),l=(a=a||function(){for(var t=0;t<o.s.aoTargets.length-1;t++)if(o.s.aoTargets[t].x!==o.s.aoTargets[t+1].x)return o.s.aoTargets[t]}()).x+(this.s.aoTargets[i].x-a.x)/2;if(this._fnIsLtr()){if(s<l){e=a;break}}else if(l<s){e=a;break}}e?(this.dom.pointer.css("left",e.x),this.s.mouse.toIndex=e.to):(this.dom.pointer.css("left",n().x),this.s.mouse.toIndex=n().to),this.s.init.bRealtime&&r!==this.s.mouse.toIndex&&(this.s.dt.oInstance.fnColReorder(this.s.mouse.fromIndex,this.s.mouse.toIndex),this.s.mouse.fromIndex=this.s.mouse.toIndex,""===this.s.dt.oScroll.sX&&""===this.s.dt.oScroll.sY||this.s.dt.oInstance.fnAdjustColumnSizing(!1),this._fnRegions())},_fnMouseUp:function(t){$(document).off(".ColReorder"),null!==this.dom.drag&&(this.dom.drag.remove(),this.dom.pointer.remove(),this.dom.drag=null,this.dom.pointer=null,this.s.dt.oInstance.fnColReorder(this.s.mouse.fromIndex,this.s.mouse.toIndex,!0),this._fnSetColumnIndexes(),""===this.s.dt.oScroll.sX&&""===this.s.dt.oScroll.sY||this.s.dt.oInstance.fnAdjustColumnSizing(!1),this.s.dt.oInstance.oApi._fnSaveState(this.s.dt),null!==this.s.reorderCallback&&this.s.reorderCallback.call(this))},_fnRegions:function(){var t=this.s.dt.aoColumns,n=this._fnIsLtr(),r=(this.s.aoTargets.splice(0,this.s.aoTargets.length),$(this.s.dt.nTable).offset().left),s=[],e=($.each(t,function(t,e){var o;e.bVisible&&"none"!==e.nTh.style.display?(o=(e=$(e.nTh)).offset().left,n&&(o+=e.outerWidth()),s.push({index:t,bound:o}),r=o):s.push({index:t,bound:r})}),s[0]),t=$(t[e.index].nTh).outerWidth();this.s.aoTargets.push({to:0,x:e.bound-t});for(var o=0;o<s.length;o++){var i=s[o],a=i.index;i.index<this.s.mouse.fromIndex&&a++,this.s.aoTargets.push({to:a,x:i.bound})}0!==this.s.fixedRight&&this.s.aoTargets.splice(this.s.aoTargets.length-this.s.fixedRight),0!==this.s.fixed&&this.s.aoTargets.splice(0,this.s.fixed)},_fnCreateDragNode:function(){var t=""!==this.s.dt.oScroll.sX||""!==this.s.dt.oScroll.sY,e=this.s.dt.aoColumns[this.s.mouse.targetIndex].nTh,o=e.parentNode,n=o.parentNode,r=n.parentNode,s=$(e).clone();this.dom.drag=$(r.cloneNode(!1)).addClass("DTCR_clonedTable").append($(n.cloneNode(!1)).append($(o.cloneNode(!1)).append(s[0]))).css({position:"absolute",top:0,left:0,width:$(e).outerWidth(),height:$(e).outerHeight()}).appendTo("body"),this.dom.pointer=$("<div></div>").addClass("DTCR_pointer").css({position:"absolute",top:$(t?$(this.s.dt.nScrollBody).parent():this.s.dt.nTable).offset().top,height:$(t?$(this.s.dt.nScrollBody).parent():this.s.dt.nTable).height()}).appendTo("body")},_fnSetColumnIndexes:function(){$.each(this.s.dt.aoColumns,function(t,e){$(e.nTh).attr("data-column-index",t)})},_fnCursorPosition:function(t,e){return(-1!==t.type.indexOf("touch")?t.originalEvent.touches[0]:t)[e]},_fnIsLtr:function(){return"rtl"!==$(this.s.dt.nTable).css("direction")}}),ColReorder.defaults={aiOrder:null,bEnable:!0,bRealtime:!0,iFixedColumnsLeft:0,iFixedColumnsRight:0,fnReorderCallback:null},ColReorder.version="1.6.2",$.fn.dataTable.ColReorder=ColReorder,$.fn.DataTable.ColReorder=ColReorder,"function"==typeof $.fn.dataTable&&"function"==typeof $.fn.dataTableExt.fnVersionCheck&&$.fn.dataTableExt.fnVersionCheck("1.10.8")?$.fn.dataTableExt.aoFeatures.push({fnInit:function(t){var e=t.oInstance;return t._colReorder?e.oApi._fnLog(t,1,"ColReorder attempted to initialise twice. Ignoring second"):(e=(e=t.oInit).colReorder||e.oColReorder||{},new ColReorder(t,e)),null},cFeature:"R",sFeature:"ColReorder"}):alert("Warning: ColReorder requires DataTables 1.10.8 or greater - www.datatables.net/download"),$(document).on("preInit.dt.colReorder",function(t,e){var o;"dt"===t.namespace&&(t=e.oInit.colReorder,o=DataTable.defaults.colReorder,(t||o)&&(o=$.extend({},t,o),!1!==t&&new ColReorder(e,o)))}),$.fn.dataTable.Api.register("colReorder.reset()",function(){return this.iterator("table",function(t){t._colReorder.fnReset()})}),$.fn.dataTable.Api.register("colReorder.order()",function(e,o){return e?this.iterator("table",function(t){t._colReorder.fnOrder(e,o)}):this.context.length?this.context[0]._colReorder.fnOrder():null}),$.fn.dataTable.Api.register("colReorder.transpose()",function(t,e){return this.context.length&&this.context[0]._colReorder?this.context[0]._colReorder.fnTranspose(t,e):t}),$.fn.dataTable.Api.register("colReorder.move()",function(t,e,o,n){return this.context.length&&(this.context[0]._colReorder.s.dt.oInstance.fnColReorder(t,e,o,n),this.context[0]._colReorder._fnSetColumnIndexes()),this}),$.fn.dataTable.Api.register("colReorder.enable()",function(e){return this.iterator("table",function(t){t._colReorder&&t._colReorder.fnEnable(e)})}),$.fn.dataTable.Api.register("colReorder.disable()",function(){return this.iterator("table",function(t){t._colReorder&&t._colReorder.fnDisable()})});export default DataTable;