/*! * dragtable * * @Version 2.0.15 * * Copyright (c) 2010-2013, Andres akottr@gmail.com * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * Inspired by the the dragtable from Dan Vanderkam (danvk.org/dragtable/) * Thanks to the jquery and jqueryui comitters * * Any comment, bug report, feature-request is welcome * Feel free to contact me. */ !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 i in t)this.originalTable.startIndex=e("#"+i).closest("th").prevAll().length+1,this.originalTable.endIndex=parseInt(t[i],10)+1,this._bubbleCols()},_bubbleCols:function(){var e,t,i,o,l=this.originalTable.startIndex,a=this.originalTable.endIndex,s=this.originalTable.el.children();if(this.options.excludeFooter&&(s=s.not("tfoot")),l 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)+")"));ta;e--)for(t=0,i=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 tr > th").each(function(t,i){var n=e(this).is(":visible")?e(this).outerWidth():0;r.push(n),d+=n}),i.options.exact){var b=d-i.originalTable.el.outerWidth();r[0]-=b}var c='
    ';h.find("> tr > th").each(function(t,n){c+='
  • ',c+="";var l=h.find("> tr > th:nth-child("+(t+1)+")");i.options.maxMovingRows>1&&(l=l.add(h.find("> tr > td:nth-child("+(t+1)+")").slice(0,i.options.maxMovingRows-1))),l.each(function(t){var i=e(this).clone().wrap("
    ").parent().html();0===i.toLowerCase().indexOf(""),c+="',c+=i,0===i.toLowerCase().indexOf(""),c+=""}),c+="
    ",c+="
  • "}),c+="
",this.sortableTable.el=this.originalTable.el.before(c).prev(),this.sortableTable.el.find("> li > table").each(function(t,i){e(this).css("width",r[t]+"px")}),this.sortableTable.selectedHandle=this.sortableTable.el.find("th .dragtable-handle-selected");var g,p=this.options.dragaccept?"li:has("+this.options.dragaccept+")":"li";this.sortableTable.el.sortable({items:p,stop:this._rearrangeTable(),revert:this.options.revert,tolerance:this.options.tolerance,containment:this.options.containment,cursor:this.options.cursor,cursorAt:this.options.cursorAt,distance:this.options.distance,axis:this.options.axis}),this.originalTable.startIndex=e(t.target).closest("th").prevAll().length+1,this.options.beforeMoving(this.originalTable,this.sortableTable),this.sortableTable.movingRow=this.sortableTable.el.find("> li:nth-child("+this.originalTable.startIndex+")"),g=e(''),e(document.head).append(g),e(document.body).attr("onselectstart","return false;").attr("unselectable","on"),window.getSelection?window.getSelection().removeAllRanges():document.selection.empty(),this.sortableTable.movingRow.trigger(e.extend(e.Event(t.type),{which:1,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,screenX:t.screenX,screenY:t.screenY}));var u=this.sortableTable.el.find(".ui-sortable-placeholder");0>=!u.height()&&u.css("height",this.sortableTable.el.find(".ui-sortable-helper").height()),u.html('
')},bindTo:{},_create:function(){this.originalTable={el:this.element,selectedHandle:e(),sortOrder:{},startIndex:0,endIndex:0},this.bindTo=this.originalTable.el.find("th"),this.options.dragaccept&&(this.bindTo=this.bindTo.filter(this.options.dragaccept)),this.bindTo.find(this.options.dragHandle).length>0&&(this.bindTo=this.bindTo.find(this.options.dragHandle)),null!==this.options.restoreState&&(e.isFunction(this.options.restoreState)?this.options.restoreState(this.originalTable):this._restoreState(this.options.restoreState));var t=this;this.bindTo.mousedown(function(i){1===i.which&&!1!==t.options.beforeStart(t.originalTable)&&(clearTimeout(this.downTimer),this.downTimer=setTimeout(function(){t.originalTable.selectedHandle=e(this),t.originalTable.selectedHandle.addClass("dragtable-handle-selected"),t._generateSortable(i)},t.options.clickDelay))}).mouseup(function(e){clearTimeout(this.downTimer)})},redraw:function(){this.destroy(),this._create()},destroy:function(){this.bindTo.unbind("mousedown"),e.Widget.prototype.destroy.apply(this,arguments)}});var t=e(document.body).attr("onselectstart"),i=e(document.body).attr("unselectable");function n(e,t){var i=e.parentNode,n=e.nextSibling===t?e:e.nextSibling;t.parentNode.insertBefore(e,t),i.insertBefore(t,n)}}(jQuery);