/*! * Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/ * Dual-licensed under the BSD or MIT licenses */ (function(e,g,h,c){var f="ontouchstart" in g;var b=(function(){var m=h.createElement("div"),n=h.documentElement;if(!("pointerEvents" in m.style)){return false}m.style.pointerEvents="auto";m.style.pointerEvents="x";n.appendChild(m);var l=g.getComputedStyle&&g.getComputedStyle(m,"").pointerEvents==="auto";n.removeChild(m);return !!l})();var k=f?"touchstart":"mousedown",j=f?"touchmove":"mousemove",a=f?"touchend":"mouseup";eCancel=f?"touchcancel":"mouseup";var d={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};function i(m,l){this.w=e(g);this.el=e(m);this.options=e.extend({},d,l);this.init()}i.prototype={init:function(){var o=this;o.reset();o.el.data("nestable-group",this.options.group);o.placeEl=e('
');e.each(this.el.find(o.options.itemNodeName),function(p,q){o.setParent(e(q))});o.el.on("click","button",function(s){if(o.dragEl||(!f&&s.button!==0)){return}var r=e(s.currentTarget),q=r.data("action"),p=r.parent(o.options.itemNodeName);if(q==="collapse"){o.collapseItem(p)}if(q==="expand"){o.expandItem(p)}});var l=function(q){var p=e(q.target);if(!p.hasClass(o.options.handleClass)){if(p.closest("."+o.options.noDragClass).length){return}p=p.closest("."+o.options.handleClass)}if(!p.length||o.dragEl||(!f&&q.button!==0)||(f&&q.touches.length!==1)){return}q.preventDefault();o.dragStart(f?q.touches[0]:q)};var n=function(p){if(o.dragEl){p.preventDefault();o.dragMove(f?p.touches[0]:p)}};var m=function(p){if(o.dragEl){p.preventDefault();o.dragStop(f?p.touches[0]:p)}};if(f){o.el[0].addEventListener(k,l,false);g.addEventListener(j,n,false);g.addEventListener(a,m,false);g.addEventListener(eCancel,m,false)}else{o.el.on(k,l);o.w.on(j,n);o.w.on(a,m)}},serialize:function(){var m,n=0,l=this;step=function(r,p){var q=[],o=r.children(l.options.itemNodeName);o.each(function(){var s=e(this),u=e.extend({},s.data()),t=s.children(l.options.listNodeName);if(t.length){u.children=step(t,p+1)}q.push(u)});return q};m=step(l.el.find(l.options.listNodeName).first(),n);return m},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=false;this.dragEl=null;this.dragRootEl=null;this.dragDepth=0;this.hasNewRoot=false;this.pointEl=null},expandItem:function(l){l.removeClass(this.options.collapsedClass);l.children('[data-action="expand"]').hide();l.children('[data-action="collapse"]').show();l.children(this.options.listNodeName).show()},collapseItem:function(m){var l=m.children(this.options.listNodeName);if(l.length){m.addClass(this.options.collapsedClass);m.children('[data-action="collapse"]').hide();m.children('[data-action="expand"]').show();m.children(this.options.listNodeName).hide()}},expandAll:function(){var l=this;l.el.find(l.options.itemNodeName).each(function(){l.expandItem(e(this))})},collapseAll:function(){var l=this;l.el.find(l.options.itemNodeName).each(function(){l.collapseItem(e(this))})},setParent:function(l){if(l.children(this.options.listNodeName).length){l.prepend(e(this.options.expandBtnHTML));l.prepend(e(this.options.collapseBtnHTML))}l.children('[data-action="expand"]').hide()},unsetParent:function(l){l.removeClass(this.options.collapsedClass);l.children("[data-action]").remove();l.children(this.options.listNodeName).remove()},dragStart:function(q){var m=this.mouse,p=e(q.target).closest("."+this.options.handleClass),o=p.closest(this.options.itemNodeName);console.log(p);this.placeEl.css("height",o.height());m.offsetX=q.offsetX!==c?q.offsetX:q.pageX-p.offset().left;m.offsetY=q.offsetY!==c?q.offsetY:q.pageY-p.offset().top;m.startX=m.lastX=q.pageX;m.startY=m.lastY=q.pageY;this.dragRootEl=this.el;this.dragEl=e(h.createElement(this.options.listNodeName)).addClass(this.options.listClass+" "+this.options.dragClass);this.dragEl.css("width",o.width());o.after(this.placeEl);o[0].parentNode.removeChild(o[0]);o.appendTo(this.dragEl);e(h.body).append(this.dragEl);this.dragEl.css({left:q.pageX-m.offsetX,top:q.pageY-m.offsetY});var n,r,l=this.dragEl.find(this.options.itemNodeName);for(n=0;n