1234 |
- /*! ColReorder 1.1.3
- * ©2010-2014 SpryMedia Ltd - datatables.net/license
- */
- !function(a,b,c){function d(a){for(var b=[],c=0,d=a.length;d>c;c++)b[a[c]]=c;return b}function e(a,b,c){var d=a.splice(b,1)[0];a.splice(c,0,d)}function f(a,b,c){for(var d=[],e=0,f=a.childNodes.length;f>e;e++)1==a.childNodes[e].nodeType&&d.push(a.childNodes[e]);var g=d[b];null!==c?a.insertBefore(g,d[c]):a.appendChild(g)}var g=function(a,g){"use strict";a.fn.dataTableExt.oApi.fnColReorder=function(b,c,g){var h,i,j,k,l,m,n=a.fn.dataTable.Api?!0:!1,o=b.aoColumns.length,p=function(a,b,c){if(a[b]){var d=a[b].split("."),e=d.shift();isNaN(1*e)||(a[b]=c[1*e]+"."+d.join("."))}};if(c!=g){if(0>c||c>=o)return void this.oApi._fnLog(b,1,"ColReorder 'from' index is out of bounds: "+c);if(0>g||g>=o)return void this.oApi._fnLog(b,1,"ColReorder 'to' index is out of bounds: "+g);var q=[];for(h=0,i=o;i>h;h++)q[h]=h;e(q,c,g);var r=d(q);for(h=0,i=b.aaSorting.length;i>h;h++)b.aaSorting[h][0]=r[b.aaSorting[h][0]];if(null!==b.aaSortingFixed)for(h=0,i=b.aaSortingFixed.length;i>h;h++)b.aaSortingFixed[h][0]=r[b.aaSortingFixed[h][0]];for(h=0,i=o;i>h;h++){for(m=b.aoColumns[h],j=0,k=m.aDataSort.length;k>j;j++)m.aDataSort[j]=r[m.aDataSort[j]];n&&(m.idx=r[m.idx])}for(n&&a.each(b.aLastSort,function(a,c){b.aLastSort[a].src=r[c.src]}),h=0,i=o;i>h;h++)m=b.aoColumns[h],"number"==typeof m.mData?(m.mData=r[m.mData],b.oApi._fnColumnOptions(b,h,{})):a.isPlainObject(m.mData)&&(p(m.mData,"_",r),p(m.mData,"filter",r),p(m.mData,"sort",r),p(m.mData,"type",r),b.oApi._fnColumnOptions(b,h,{}));if(b.aoColumns[c].bVisible){var s=this.oApi._fnColumnIndexToVisible(b,c),t=null;for(h=c>g?g:g+1;null===t&&o>h;)t=this.oApi._fnColumnIndexToVisible(b,h),h++;for(l=b.nTHead.getElementsByTagName("tr"),h=0,i=l.length;i>h;h++)f(l[h],s,t);if(null!==b.nTFoot)for(l=b.nTFoot.getElementsByTagName("tr"),h=0,i=l.length;i>h;h++)f(l[h],s,t);for(h=0,i=b.aoData.length;i>h;h++)null!==b.aoData[h].nTr&&f(b.aoData[h].nTr,s,t)}for(e(b.aoColumns,c,g),e(b.aoPreSearchCols,c,g),h=0,i=b.aoData.length;i>h;h++){var u=b.aoData[h];n?(u.anCells&&e(u.anCells,c,g),"dom"!==u.src&&a.isArray(u._aData)&&e(u._aData,c,g)):(a.isArray(u._aData)&&e(u._aData,c,g),e(u._anHidden,c,g))}for(h=0,i=b.aoHeader.length;i>h;h++)e(b.aoHeader[h],c,g);if(null!==b.aoFooter)for(h=0,i=b.aoFooter.length;i>h;h++)e(b.aoFooter[h],c,g);if(n){var v=new a.fn.dataTable.Api(b);v.rows().invalidate()}for(h=0,i=o;i>h;h++)a(b.aoColumns[h].nTh).off("click.DT"),this.oApi._fnSortAttachListener(b,b.aoColumns[h].nTh,h);a(b.oInstance).trigger("column-reorder",[b,{"iFrom":c,"iTo":g,"aiInvertMapping":r}])}};var h=function(b,c){var d;if(a.fn.dataTable.Api?d=new a.fn.dataTable.Api(b).settings()[0]:b.fnSettings?d=b.fnSettings():"string"==typeof b?a.fn.dataTable.fnIsDataTable(a(b)[0])&&(d=a(b).eq(0).dataTable().fnSettings()):b.nodeName&&"table"===b.nodeName.toLowerCase()?a.fn.dataTable.fnIsDataTable(b.nodeName)&&(d=a(b.nodeName).dataTable().fnSettings()):b instanceof jQuery?a.fn.dataTable.fnIsDataTable(b[0])&&(d=b.eq(0).dataTable().fnSettings()):d=b,d._colReorder)throw"ColReorder already initialised on table #"+d.nTable.id;var e=a.fn.dataTable.camelToHungarian;return e&&(e(h.defaults,h.defaults,!0),e(h.defaults,c||{})),this.s={"dt":null,"init":a.extend(!0,{},h.defaults,c),"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.dt=d,this.s.dt._colReorder=this,this._fnConstruct(),d.oApi._fnCallbackReg(d,"aoDestroyCallback",a.proxy(this._fnDestroy,this),"ColReorder"),this};return h.prototype={"fnReset":function(){for(var a=[],b=0,c=this.s.dt.aoColumns.length;c>b;b++)a.push(this.s.dt.aoColumns[b]._ColReorder_iOrigCol);return this._fnOrderColumns(a),this},"fnGetCurrentOrder":function(){return this.fnOrder()},"fnOrder":function(a){if(a===c){for(var b=[],e=0,f=this.s.dt.aoColumns.length;f>e;e++)b.push(this.s.dt.aoColumns[e]._ColReorder_iOrigCol);return b}return this._fnOrderColumns(d(a)),this},"_fnConstruct":function(){var a,b=this,c=this.s.dt.aoColumns.length;for(this.s.init.iFixedColumns&&(this.s.fixed=this.s.init.iFixedColumns),this.s.fixedRight=this.s.init.iFixedColumnsRight?this.s.init.iFixedColumnsRight:0,this.s.init.fnReorderCallback&&(this.s.reorderCallback=this.s.init.fnReorderCallback),a=0;c>a;a++)a>this.s.fixed-1&&a<c-this.s.fixedRight&&this._fnMouseListener(a,this.s.dt.aoColumns[a].nTh),this.s.dt.aoColumns[a]._ColReorder_iOrigCol=a;this.s.dt.oApi._fnCallbackReg(this.s.dt,"aoStateSaveParams",function(a,c){b._fnStateSave.call(b,c)},"ColReorder_State");var e=null;if(this.s.init.aiOrder&&(e=this.s.init.aiOrder.slice()),this.s.dt.oLoadedState&&"undefined"!=typeof this.s.dt.oLoadedState.ColReorder&&this.s.dt.oLoadedState.ColReorder.length==this.s.dt.aoColumns.length&&(e=this.s.dt.oLoadedState.ColReorder),e)if(b.s.dt._bInitComplete){var f=d(e);b._fnOrderColumns.call(b,f)}else{var g=!1;this.s.dt.aoDrawCallback.push({"fn":function(){if(!b.s.dt._bInitComplete&&!g){g=!0;var a=d(e);b._fnOrderColumns.call(b,a)}},"sName":"ColReorder_Pre"})}else this._fnSetColumnIndexes()},"_fnOrderColumns":function(b){if(b.length!=this.s.dt.aoColumns.length)return void this.s.dt.oInstance.oApi._fnLog(this.s.dt,1,"ColReorder - array reorder does not match known number of columns. Skipping.");for(var c=0,d=b.length;d>c;c++){var f=a.inArray(c,b);c!=f&&(e(b,f,c),this.s.dt.oInstance.fnColReorder(f,c))}(""!==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),this._fnSetColumnIndexes(),null!==this.s.reorderCallback&&this.s.reorderCallback.call(this)},"_fnStateSave":function(b){var c,d,e,f=this.s.dt,g=f.aoColumns;if(b.ColReorder=[],b.aaSorting){for(c=0;c<b.aaSorting.length;c++)b.aaSorting[c][0]=g[b.aaSorting[c][0]]._ColReorder_iOrigCol;var h=a.extend(!0,[],b.aoSearchCols);for(c=0,d=g.length;d>c;c++)e=g[c]._ColReorder_iOrigCol,b.aoSearchCols[e]=h[c],b.abVisCols[e]=g[c].bVisible,b.ColReorder.push(e)}else if(b.order){for(c=0;c<b.order.length;c++)b.order[c][0]=g[b.order[c][0]]._ColReorder_iOrigCol;var i=a.extend(!0,[],b.columns);for(c=0,d=g.length;d>c;c++)e=g[c]._ColReorder_iOrigCol,b.columns[e]=i[c],b.ColReorder.push(e)}},"_fnMouseListener":function(b,c){var d=this;a(c).on("mousedown.ColReorder",function(a){a.preventDefault(),d._fnMouseDown.call(d,a,c)})},"_fnMouseDown":function(d,e){var f=this,g=a(d.target).closest("th, td"),h=g.offset(),i=parseInt(a(e).attr("data-column-index"),10);i!==c&&(this.s.mouse.startX=d.pageX,this.s.mouse.startY=d.pageY,this.s.mouse.offsetX=d.pageX-h.left,this.s.mouse.offsetY=d.pageY-h.top,this.s.mouse.target=this.s.dt.aoColumns[i].nTh,this.s.mouse.targetIndex=i,this.s.mouse.fromIndex=i,this._fnRegions(),a(b).on("mousemove.ColReorder",function(a){f._fnMouseMove.call(f,a)}).on("mouseup.ColReorder",function(a){f._fnMouseUp.call(f,a)}))},"_fnMouseMove":function(a){if(null===this.dom.drag){if(Math.pow(Math.pow(a.pageX-this.s.mouse.startX,2)+Math.pow(a.pageY-this.s.mouse.startY,2),.5)<5)return;this._fnCreateDragNode()}this.dom.drag.css({"left":a.pageX-this.s.mouse.offsetX,"top":a.pageY-this.s.mouse.offsetY});for(var b=!1,c=this.s.mouse.toIndex,d=1,e=this.s.aoTargets.length;e>d;d++)if(a.pageX<this.s.aoTargets[d-1].x+(this.s.aoTargets[d].x-this.s.aoTargets[d-1].x)/2){this.dom.pointer.css("left",this.s.aoTargets[d-1].x),this.s.mouse.toIndex=this.s.aoTargets[d-1].to,b=!0;break}b||(this.dom.pointer.css("left",this.s.aoTargets[this.s.aoTargets.length-1].x),this.s.mouse.toIndex=this.s.aoTargets[this.s.aoTargets.length-1].to),this.s.init.bRealtime&&c!==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._fnRegions())},"_fnMouseUp":function(c){a(b).off("mousemove.ColReorder mouseup.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),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 b=this.s.dt.aoColumns;this.s.aoTargets.splice(0,this.s.aoTargets.length),this.s.aoTargets.push({"x":a(this.s.dt.nTable).offset().left,"to":0});for(var c=0,d=0,e=b.length;e>d;d++)d!=this.s.mouse.fromIndex&&c++,b[d].bVisible&&this.s.aoTargets.push({"x":a(b[d].nTh).offset().left+a(b[d].nTh).outerWidth(),"to":c});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 b=""!==this.s.dt.oScroll.sX||""!==this.s.dt.oScroll.sY,c=this.s.dt.aoColumns[this.s.mouse.targetIndex].nTh,d=c.parentNode,e=d.parentNode,f=e.parentNode,g=a(c).clone();this.dom.drag=a(f.cloneNode(!1)).addClass("DTCR_clonedTable").append(a(e.cloneNode(!1)).append(a(d.cloneNode(!1)).append(g[0]))).css({"position":"absolute","top":0,"left":0,"width":a(c).outerWidth(),"height":a(c).outerHeight()}).appendTo("body"),this.dom.pointer=a("<div></div>").addClass("DTCR_pointer").css({"position":"absolute","top":b?a("div.dataTables_scroll",this.s.dt.nTableWrapper).offset().top:a(this.s.dt.nTable).offset().top,"height":b?a("div.dataTables_scroll",this.s.dt.nTableWrapper).height():a(this.s.dt.nTable).height()}).appendTo("body")},"_fnDestroy":function(){var b,c;for(b=0,c=this.s.dt.aoDrawCallback.length;c>b;b++)if("ColReorder_Pre"===this.s.dt.aoDrawCallback[b].sName){this.s.dt.aoDrawCallback.splice(b,1);break}a(this.s.dt.nTHead).find("*").off(".ColReorder"),a.each(this.s.dt.aoColumns,function(b,c){a(c.nTh).removeAttr("data-column-index")}),this.s.dt._colReorder=null,this.s=null},"_fnSetColumnIndexes":function(){a.each(this.s.dt.aoColumns,function(b,c){a(c.nTh).attr("data-column-index",b)})}},h.defaults={"aiOrder":null,"bRealtime":!1,"iFixedColumns":0,"iFixedColumnsRight":0,"fnReorderCallback":null},h.version="1.1.3",a.fn.dataTable.ColReorder=h,a.fn.DataTable.ColReorder=h,"function"==typeof a.fn.dataTable&&"function"==typeof a.fn.dataTableExt.fnVersionCheck&&a.fn.dataTableExt.fnVersionCheck("1.9.3")?a.fn.dataTableExt.aoFeatures.push({"fnInit":function(a){var b=a.oInstance;if(a._colReorder)b.oApi._fnLog(a,1,"ColReorder attempted to initialise twice. Ignoring second");else{var c=a.oInit,d=c.colReorder||c.oColReorder||{};new h(a,d)}return null},"cFeature":"R","sFeature":"ColReorder"}):alert("Warning: ColReorder requires DataTables 1.9.3 or greater - www.datatables.net/download"),a.fn.dataTable.Api&&(a.fn.dataTable.Api.register("colReorder.reset()",function(){return this.iterator("table",function(a){a._colReorder.fnReset()})}),a.fn.dataTable.Api.register("colReorder.order()",function(a){return a?this.iterator("table",function(b){b._colReorder.fnOrder(a)}):this.context.length?this.context[0]._colReorder.fnOrder():null})),h};"function"==typeof define&&define.amd?define(["jquery","datatables"],g):"object"==typeof exports?g(require("jquery"),require("datatables")):jQuery&&!jQuery.fn.dataTable.ColReorder&&g(jQuery,jQuery.fn.dataTable)}(window,document);
|