/**
 * Copyright (c) 2013 - 2019 fusionCSS. All rights reserved.
 * @link http://fusionCSS.com
 * @version 3.3.0
 */
$.fn.extend({makeDragContainer:function(O){return(O=O||{}).dragMarkerClass=O.dragMarkerClass||"dragMarker",O.dragItemClass=O.dragItemClass||"dragItem",O.dragDraggingClass=O.dragDraggingClass||"dragDragging",O.disableDragInto=O.disableDragInto||!1,O.dragTopOnly=O.dragTopOnly||!1,this.each(function(){var c,p,u,o,f,t,h=$(this),m=null,v=0,w=0,C=null,D=null,r=null,a=null,y=!1;function e(t){var e=$(t.target),o=e.closest("."+O.dragItemClass),r=h.offset();!e.closest("a").length&&o.length&&(u=(t.touches&&t.touches.length?(p=t.touches[0].pageX,t.touches[0]):(p=t.pageX,t)).pageY,v=p-o.offset().left,w=u-o.offset().top,p-=r.left,u-=r.top,y&&(p+=h.scrollLeft(),u+=h.scrollTop()),h.trigger("draggingStart",r={dragging:o,eventTarget:e,allowDrag:!0}),r.allowDrag)&&(t.preventDefault(),(m=o).addClass(O.dragDraggingClass),C=D=null,c=h.find("."+O.dragMarkerClass),O.copyFunction?O.copyFunction(c,m):c.html(m.html()),c.css("left",p-v+"px").css("top",u-w+"px").width(m.outerWidth(!0)),h.on("mousemove",g).on("touchmove",g).on("mouseup",I).on("touchend",I))}function n(){a.scrollTop(a.scrollTop()+o),g(f)}function b(t,e){e?(r&&t[0]!=a[0]&&M(),a=t,o=2*e,null===r&&(r=window.setInterval(n,15))):r&&M()}function M(){null!==r&&(window.clearInterval(r),r=null)}function g(t){var e,o,r,a,n,g,l,s,i=h.offset(),d=h[0].getBoundingClientRect();t.preventDefault(),t.stopPropagation(),a=((f=t).touches&&t.touches.length?(e=t.touches[0].pageX,o=t.touches[0].pageY,r=t.touches[0].clientX,t.touches[0]):(e=t.pageX,o=t.pageY,r=t.clientX,t)).clientY,e-=i.left,o-=i.top,y&&(e+=h.scrollLeft(),o+=h.scrollTop()),r<=Math.ceil(d.left+2)||r>=Math.floor(d.right-2)||a<=Math.ceil(d.top+2)||a>=Math.floor(d.bottom-2)?I(t):(c.css("left",e-v+"px").css("top",o-w+"px"),c.hide(),i=document.elementFromPoint(r,a),!(i=$(i).closest("."+O.dragItemClass)).length||i.hasClass(O.dragDraggingClass)||i.closest("."+O.dragDraggingClass).length||(t=Math.abs(p-e),s=Math.abs(u-o),n=i[0].getBoundingClientRect(),g=!0,(O.disableDragInto||O.disableDropOn&&"true"===i.attr(O.disableDropOn))&&(g=!1),l={dragging:m,dropTarget:i,dropPosition:"on",allowPosition:!0},s<t?(s=g?n.width/3:n.width/2,r>n.right-s?(m.css("opacity",1),D="after",i.next()[0]!==m[0]&&(h.trigger("draggingOver",l),l.allowPosition)&&(m.remove(),m.insertAfter(i),p=e,u=o,C=i)):r<n.left+s?(m.css("opacity",1),D="before",i.prev()[0]!==m[0]&&(h.trigger("draggingOver",l),l.allowPosition)&&(m.remove(),m.insertBefore(i),p=e,u=o,C=i)):!g||i[0]===m[0]&&"on"===D||(h.trigger("draggingOver",l),l.allowPosition&&(D="on",m.css("opacity",.2),C=i))):(t=g?n.height/3:n.height/2,a>n.bottom-t?(m.css("opacity",1),D="after",i.next()[0]!==m[0]&&(h.trigger("draggingOver",l),l.allowPosition)&&(m.remove(),m.insertAfter(i),p=e,u=o,C=i)):a<n.top+t?(m.css("opacity",1),D="before",i.prev()[0]!==m[0]&&(h.trigger("draggingOver",l),l.allowPosition)&&(m.remove(),m.insertBefore(i),p=e,u=o,C=i)):!g||i[0]===m[0]&&"on"===D||(h.trigger("draggingOver",l),l.allowPosition&&(D="on",m.css("opacity",.2),C=i)))),c.show(),(d.top<0||d.bottom>$(window).height())&&(a<30||a>$(window).height()-30)?b($(window),a<30?-1:1):a<d.top+30?b(h,-1):a>d.bottom-30?b(h,1):M())}function I(t){m&&(m.css("opacity",1),t.preventDefault(),h.off("mousemove",g).off("touchmove",g).off("mouseup",I).off("touchend",I),M(),c.hide(),m.removeClass(O.dragDraggingClass),t={dragging:m,dropTarget:null===D?null:C,dropPosition:D},m=null,h.trigger("draggingEnd",t))}h.find("."+O.dragMarkerClass).length||h.append('<div class="'+O.dragMarkerClass+'" style="display: none;"></div>'),(O.dragTopOnly?(t=(t=h.find("ul")).length?t:h.find("ol")).first().children():h.find("li")).addClass(O.dragItemClass),h.find("li").parent().parent()[0]===h[0]&&(y=!0),h.on("mousedown",e).on("touchstart",e),$(document).on("keyup",function(t){m&&"Escape"===t.key&&(I(t),t.preventDefault())})})}});