/*! * Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/ * Dual-licensed under the BSD or MIT licenses */ !function(a,b,c,d){function e(c,d){this.w=a(b),this.el=a(c),this.options=a.extend({},j,d),this.init()}var f=("ontouchstart"in c.documentElement,function(){var a=c.createElement("div"),d=c.documentElement;if(!("pointerEvents"in a.style))return!1;a.style.pointerEvents="auto",a.style.pointerEvents="x",d.appendChild(a);var e=b.getComputedStyle&&"auto"===b.getComputedStyle(a,"").pointerEvents;return d.removeChild(a),!!e}()),g="mousedown touchstart MSPointerDown pointerdown",h="mousemove touchmove MSPointerMove pointermove",i="mouseup touchend touchcancel MSPointerUp MSPointerCancel pointerup pointercancel",j={listNodeName:"ol",itemNodeName:"li",rootClass:"dd",listClass:"dd-list",itemClass:"dd-item",dragClass:"dd-dragel",handleClass:"dd-handle",collapsedClass:"dd-collapsed",placeClass:"dd-placeholder",noDragClass:"dd-nodrag",emptyClass:"dd-empty",expandBtnHTML:'',collapseBtnHTML:'',group:0,maxDepth:5,threshold:20};e.prototype={init:function(){var b=this;b.reset(),b.el.data("nestable-group",this.options.group),b.placeEl=a('
'),a.each(this.el.find(b.options.itemNodeName),function(c,d){b.setParent(a(d))}),b.el.on("click","button",function(c){if(!(b.dragEl||"button"in c&&0!==c.button)){var d=a(c.currentTarget),e=d.data("action"),f=d.parent(b.options.itemNodeName);"collapse"===e&&b.collapseItem(f),"expand"===e&&b.expandItem(f)}});var c=function(c){c=c.originalEvent;var d=a(c.target);if(!d.hasClass(b.options.handleClass)){if(d.closest("."+b.options.noDragClass).length)return;d=d.closest("."+b.options.handleClass)}!d.length||b.dragEl||"button"in c&&0!==c.button||"touches"in c&&1!==c.touches.length||(c.preventDefault(),b.dragStart("touches"in c?c.touches[0]:c))},d=function(a){b.dragEl&&(a=a.originalEvent,a.preventDefault(),b.dragMove("touches"in a?a.touches[0]:a))},e=function(a){b.dragEl&&(a=a.originalEvent,a.preventDefault(),b.dragStop("touches"in a?a.touches[0]:a))};b.el.on(g,c),b.w.on(h,d),b.w.on(i,e)},serialize:function(){var b,c=0,d=this;return step=function(b,c){var e=[],f=b.children(d.options.itemNodeName);return f.each(function(){var b=a(this),f=a.extend({},b.data()),g=b.children(d.options.listNodeName);g.length&&(f.children=step(g,c+1)),e.push(f)}),e},b=step(d.el.find(d.options.listNodeName).first(),c)},serialise:function(){return this.serialize()},reset:function(){this.mouse={offsetX:0,offsetY:0,startX:0,startY:0,lastX:0,lastY:0,nowX:0,nowY:0,distX:0,distY:0,dirAx:0,dirX:0,dirY:0,lastDirX:0,lastDirY:0,distAxX:0,distAxY:0},this.moving=!1,this.dragEl=null,this.dragRootEl=null,this.dragDepth=0,this.hasNewRoot=!1,this.pointEl=null},expandItem:function(a){a.removeClass(this.options.collapsedClass),a.children('[data-action="expand"]').hide(),a.children('[data-action="collapse"]').show(),a.children(this.options.listNodeName).show()},collapseItem:function(a){var b=a.children(this.options.listNodeName);b.length&&(a.addClass(this.options.collapsedClass),a.children('[data-action="collapse"]').hide(),a.children('[data-action="expand"]').show(),a.children(this.options.listNodeName).hide())},expandAll:function(){var b=this;b.el.find(b.options.itemNodeName).each(function(){b.expandItem(a(this))})},collapseAll:function(){var b=this;b.el.find(b.options.itemNodeName).each(function(){b.collapseItem(a(this))})},setParent:function(b){b.children(this.options.listNodeName).length&&(b.prepend(a(this.options.expandBtnHTML)),b.prepend(a(this.options.collapseBtnHTML))),b.children('[data-action="expand"]').hide()},unsetParent:function(a){a.removeClass(this.options.collapsedClass),a.children("[data-action]").remove(),a.children(this.options.listNodeName).remove()},dragStart:function(b){var e=this.mouse,f=a(b.target),g=f.closest(this.options.itemNodeName);this.placeEl.css("height",g.height()),e.offsetX=b.offsetX!==d?b.offsetX:b.pageX-f.offset().left,e.offsetY=b.offsetY!==d?b.offsetY:b.pageY-f.offset().top,e.startX=e.lastX=b.pageX,e.startY=e.lastY=b.pageY,this.dragRootEl=this.el,this.dragEl=a(c.createElement(this.options.listNodeName)).addClass(this.options.listClass+" "+this.options.dragClass),this.dragEl.css("width",g.width()),g.after(this.placeEl),g[0].parentNode.removeChild(g[0]),g.appendTo(this.dragEl),a(c.body).append(this.dragEl),this.dragEl.css({left:b.pageX-e.offsetX,top:b.pageY-e.offsetY});var h,i,j=this.dragEl.find(this.options.itemNodeName);for(h=0;h