2024-06-24 14:07:01 -07:00
|
|
|
!function(e){e.widget("akottr.dragtable",{options:{revert:!1,dragHandle:".table-handle",maxMovingRows:40,excludeFooter:!1,onlyHeaderThreshold:100,dragaccept:null,persistState:null,restoreState:null,exact:!0,clickDelay:10,containment:null,cursor:"move",cursorAt:!1,distance:0,tolerance:"pointer",axis:"x",beforeStart:e.noop,beforeMoving:e.noop,beforeReorganize:e.noop,beforeStop:e.noop},originalTable:{el:null,selectedHandle:null,sortOrder:null,startIndex:0,endIndex:0},sortableTable:{el:e(),selectedHandle:e(),movingRow:e()},persistState:function(){var t=this;this.originalTable.el.find("th").each((function(e){""!==this.id&&(t.originalTable.sortOrder[this.id]=e)})),e.ajax({url:this.options.persistState,data:this.originalTable.sortOrder})},_restoreState:function(t){for(var r in t)this.originalTable.startIndex=e("#"+r).closest("th").prevAll().length+1,this.originalTable.endIndex=parseInt(t[r],10)+1,this._bubbleCols()},_bubbleCols:function(){var e,t,r,o,i=this.originalTable.startIndex,a=this.originalTable.endIndex,s=this.originalTable.el.children();if(this.options.excludeFooter&&(s=s.not("tfoot")),i<a)for(e=i;e<a;e++)for(r=s.find("> tr > td:nth-child("+e+")").add(s.find("> tr > th:nth-child("+e+")")),o=s.find("> tr > td:nth-child("+(e+1)+")").add(s.find("> tr > th:nth-child("+(e+1)+")")),t=0;t<r.length;t++)n(r[t],o[t]);else for(e=i;e>a;e--)for(r=s.find("> tr > td:nth-child("+e+")").add(s.find("> tr > th:nth-child("+e+")")),o=s.find("> tr > td:nth-child("+(e-1)+")").add(s.find("> tr > th:nth-child("+(e-1)+")")),t=0;t<r.length;t++)n(r[t],o[t])},_rearrangeTableBackroundProcessing:function(){var n=this;return function(){n._bubbleCols(),n.options.beforeStop(n.originalTable),n.sortableTable.el.remove(),function(){e("#__dragtable_disable_text_selection__").remove(),t?e(document.body).attr("onselectstart",t):e(document.body).removeAttr("onselectstart");r?e(document.body).attr("unselectable",r):e(document.body).removeAttr("unselectable")}(),null!==n.options.persistState&&(e.isFunction(n.options.persistState)?n.options.persistState(n.originalTable):n.persistState())}},_rearrangeTable:function(){var e=this;return function(){e.originalTable.selectedHandle.removeClass("dragtable-handle-selected"),e.sortableTable.el.sortable("disable"),e.sortableTable.el.addClass("dragtable-disabled"),e.options.beforeReorganize(e.originalTable,e.sortableTable),e.originalTable.endIndex=e.sortableTable.movingRow.prevAll().length+1,setTimeout(e._rearrangeTableBackroundProcessing(),50)}},_generateSortable:function(t){!t.cancelBubble&&(t.cancelBubble=!0);for(var r=this,n=this.originalTable.el[0].attributes,o="",i=0;i<n.length;i++)n[i].nodeValue&&"id"!=n[i].nodeName&&"width"!=n[i].nodeName&&(o+=n[i].nodeName+'="'+n[i].nodeValue+'" ');var a=[],s=[];this.originalTable.el.find("tr").slice(0,this.options.maxMovingRows).each((function(t,r){for(var n=this.attributes,o="",i=0;i<n.length;i++)n[i].nodeValue&&"id"!=n[i].nodeName&&(o+=" "+n[i].nodeName+'="'+n[i].nodeValue+'"');a.push(o),s.push(e(this).height())}));var c=[],l=0,u=r.originalTable.el.children();if(this.options.excludeFooter&&(u=u.not("tfoot")),u.find("> tr > th").each((function(t,r){var n=e(this).is(":visible")?e(this).outerWidth():0;c.push(n),l+=n})),r.options.exact){var f=l-r.originalTable.el.outerWidth();c[0]-=f}var h='<ul class="dragtable-sortable" style="position:absolute; width:'+(l+=2)+'px;">';u.find("> tr > th").each((function(t,n){var i=e(this).is(":visible")?e(this).outerWidth():0;h+='<li style="width:'+i+'px;">',h+="<table "+o+">";var c=u.find("> tr > th:nth-child("+(t+1)+")");r.options.maxMovingRows>1&&(c=c.add(u.find("> tr > td:nth-child("+(t+1)+")").slice(0,r.options.maxMovingRows-1))),c.each((function(t){var r=e(this).clone().wrap("<div></div>").parent().html();0===r.toLowerCase().indexOf("<th")&&(h+="<thead>"),h+="<tr "+a[t]+'" style="height:'+s[t]+'px;">',h+=r,0===r.toLowerCase().indexOf("<th")&&(h+="</thead>"),h+="</tr>"})),h+="</table>",h+="</li>"})),h+="</ul>",this.sortableTable.el=this.originalTable.el.before(h).prev(),this.sortableTable.el.find("> li > table").each((function(t,r){e(this).css
|