!function(t,e,a,i){var n="ontouchstart"in a.documentElement,r=n?"touchstart":"mousedown",l=n?"touchmove":"mousemove",s=n?"touchend":"mouseup";n&&t.each("touchstart touchmove touchend".split(" "),function(e,a){t.event.fixHooks[a]=t.event.mouseHooks}),t(a).ready(function(){function e(t){for(var e={},a=t.match(/([^;:]+)/g)||[];a.length;)e[a.shift()]=a.shift().trim();return e}t("table").each(function(){"dnd"==t(this).data("table")&&t(this).tableDnD({onDragStyle:t(this).data("ondragstyle")&&e(t(this).data("ondragstyle"))||null,onDropStyle:t(this).data("ondropstyle")&&e(t(this).data("ondropstyle"))||null,onDragClass:void 0==t(this).data("ondragclass")&&"tDnD_whileDrag"||t(this).data("ondragclass"),onDrop:t(this).data("ondrop")&&Function("table","row",t(this).data("ondrop")),onDragStart:t(this).data("ondragstart")&&Function("table","row",t(this).data("ondragstart")),scrollAmount:t(this).data("scrollamount")||5,sensitivity:t(this).data("sensitivity")||10,hierarchyLevel:t(this).data("hierarchylevel")||0,indentArtifact:t(this).data("indentartifact")||'
 
',autoWidthAdjust:t(this).data("autowidthadjust")||!0,autoCleanRelations:t(this).data("autocleanrelations")||!0,jsonPretifySeparator:t(this).data("jsonpretifyseparator")||" ",serializeRegexp:t(this).data("serializeregexp")&&RegExp(t(this).data("serializeregexp"))||/[^\-]*$/,serializeParamName:t(this).data("serializeparamname")||!1,dragHandle:t(this).data("draghandle")||null})})}),jQuery.tableDnD={currentTable:null,dragObject:null,mouseOffset:null,oldX:0,oldY:0,build:function(e){return this.each(function(){this.tableDnDConfig=t.extend({onDragStyle:null,onDropStyle:null,onDragClass:"tDnD_whileDrag",onDrop:null,onDragStart:null,scrollAmount:5,sensitivity:10,hierarchyLevel:0,indentArtifact:'
 
',autoWidthAdjust:!0,autoCleanRelations:!0,jsonPretifySeparator:" ",serializeRegexp:/[^\-]*$/,serializeParamName:!1,dragHandle:null},e||{}),t.tableDnD.makeDraggable(this),this.tableDnDConfig.hierarchyLevel&&t.tableDnD.makeIndented(this)}),this},makeIndented:function(e){var a,i,n=e.tableDnDConfig,r=e.rows,l=t(r).first().find("td:first")[0],s=0,o=0;if(t(e).hasClass("indtd"))return null;i=t(e).addClass("indtd").attr("style"),t(e).css({whiteSpace:"nowrap"});for(var d=0;dt.vertical&&this.dragObject.parentNode.insertBefore(this.dragObject,e.nextSibling)||00&&t(a).find("td:first").children(":first").remove()&&t(a).data("level",--i),0>e.horizontal&&i=i&&t(a).children(":first").prepend(n.indentArtifact)&&t(a).data("level",++i)},mousemove:function(e){var a,i,n,r,l,s=t(t.tableDnD.dragObject),o=t.tableDnD.currentTable.tableDnDConfig;return e&&e.preventDefault(),!!t.tableDnD.dragObject&&("touchmove"==e.type&&event.preventDefault(),o.onDragClass&&s.addClass(o.onDragClass)||s.css(o.onDragStyle),r=(i=t.tableDnD.mouseCoords(e)).x-t.tableDnD.mouseOffset.x,l=i.y-t.tableDnD.mouseOffset.y,t.tableDnD.autoScroll(i),a=t.tableDnD.findDropTargetRow(s,l),n=t.tableDnD.findDragDirection(r,l),t.tableDnD.moveVerticle(n,a),t.tableDnD.moveHorizontal(n,a),!1)},findDragDirection:function(t,e){var a=this.currentTable.tableDnDConfig.sensitivity,i=this.oldX,n=this.oldY,r={horizontal:t>=i-a&&t<=i+a?0:t>i?-1:1,vertical:e>=n-a&&e<=n+a?0:e>n?-1:1};return 0!=r.horizontal&&(this.oldX=t),0!=r.vertical&&(this.oldY=e),r},findDropTargetRow:function(e,a){for(var i=0,n=this.currentTable.rows,r=this.currentTable.tableDnDConfig,l=0,s=null,o=0;ol-i&&a1&&t(this.currentTable.rows).each(function(){if((r=t(this).data("level"))>1)for(n=t(this).prev().data("level");r>n+1;)t(this).find("td:first").children(":first").remove(),t(this).data("level",--r)}),e.onDragClass&&t(i).removeClass(e.onDragClass)||t(i).css(e.onDropStyle),this.dragObject=null,e.onDrop&&this.originalOrder!=this.currentOrder()&&t(i).hide().fadeIn("fast")&&e.onDrop(this.currentTable,i),this.currentTable=null},mouseup:function(e){return e&&e.preventDefault(),t.tableDnD.processMouseup(),!1},jsonize:function(t){var e=this.currentTable;return t?JSON.stringify(this.tableData(e),null,e.tableDnDConfig.jsonPretifySeparator):JSON.stringify(this.tableData(e))},serialize:function(){return t.param(this.tableData(this.currentTable))},serializeTable:function(t){for(var e="",a=t.tableDnDConfig.serializeParamName||t.id,i=t.rows,n=0;n0&&(e+="&");var r=i[n].id;r&&t.tableDnDConfig&&t.tableDnDConfig.serializeRegexp&&(e+=a+"[]="+(r=r.match(t.tableDnDConfig.serializeRegexp)[0]))}return e},serializeTables:function(){var e=[];return t("table").each(function(){this.id&&e.push(t.param(this.tableData(this)))}),e.join("&")},tableData:function(e){var a,i,n,r,l=e.tableDnDConfig,s=[],o=0,d=0,h=null,u={};if(e||(e=this.currentTable),!e||!e.id||!e.rows||!e.rows.length)return{error:{code:500,message:"Not a valid table, no serializable unique id provided."}};r=l.autoCleanRelations&&e.rows||t.makeArray(e.rows),n=i=l.serializeParamName||e.id,a=function(t){return t&&l&&l.serializeRegexp?t.match(l.serializeRegexp)[0]:t},u[n]=[],!l.autoCleanRelations&&t(r[0]).data("level")&&r.unshift({id:"undefined"});for(var c=0;co)s.push([n,o]),n=a(r[c-1].id);else if(d=o&&(s[f][1]=0);o=d,t.isArray(u[n])||(u[n]=[]),(h=a(r[c].id))&&u[n].push(h)}else(h=a(r[c].id))&&u[n].push(h);return u}},jQuery.fn.extend({tableDnD:t.tableDnD.build,tableDnDUpdate:t.tableDnD.updateTables,tableDnDSerialize:t.proxy(t.tableDnD.serialize,t.tableDnD),tableDnDSerializeAll:t.tableDnD.serializeTables,tableDnDData:t.proxy(t.tableDnD.tableData,t.tableDnD)})}(jQuery,window,window.document);