From 577e01a465415e7490a109f3f042af7ebaaeb1c3 Mon Sep 17 00:00:00 2001 From: williammustaffa Date: Sat, 25 Jul 2020 16:27:32 -0300 Subject: [PATCH] build --- dist/jquery.dad.js | 10 ++++------ dist/jquery.dad.min.js | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/dist/jquery.dad.js b/dist/jquery.dad.js index 19849fd..95dde46 100644 --- a/dist/jquery.dad.js +++ b/dist/jquery.dad.js @@ -72,11 +72,11 @@ */ Dad.defaultOptions = { active: true, - draggable: null, + draggable: false, exchangeable: true, transition: 200, - placeholderTarget: null, - placeholderTemplate: null, + placeholderTarget: false, + placeholderTemplate: "
", }; /** @@ -216,10 +216,8 @@ width: $target.outerWidth(), }); - var placeholderTemplate = this.options.placeholderTarget || "
"; - // Add placeholder - var $placeholder = $(placeholderTemplate).css({ + var $placeholder = $(this.options.placeholderTemplate).css({ position: "absolute", pointerEvents: "none", zIndex: 9998, diff --git a/dist/jquery.dad.min.js b/dist/jquery.dad.min.js index 7e67254..6eb10f0 100644 --- a/dist/jquery.dad.min.js +++ b/dist/jquery.dad.min.js @@ -1 +1 @@ -!function(h){"use strict";function i(){this.positionX=0,this.positionY=0,this.offsetX=0,this.offsetY=0}function e(t,e){this.options=this.parseOptions(e),this.$container=h(t),this.$current=null,this.$target=null,this.$clone=null,this.mouse=new i,this.holding=!1,this.dragging=!1,this.dropzones=[],this.setActive(this.options.active),this.setup()}i.prototype.update=function(t){var e,i;("ontouchstart"in window||navigator.msMaxTouchPoints)&&"touchmove"==t.type?(e=t.originalEvent.touches[0],i=document.elementFromPoint(e.clientX,e.clientY),h(i).trigger("touchenter"),this.positionX=e.pageX,this.positionY=e.pageY):(this.positionX=t.pageX,this.positionY=t.pageY)},e.defaultOptions={active:!0,draggable:null,exchangeable:!0,transition:200,placeholderTarget:null,placeholderTemplate:null},e.prototype.parseOptions=function(o){var n=h.extend(!0,{},e.defaultOptions);return o&&h.each(n,function(t,e){var i=o[t];void 0!==i&&(n[t]="object"==typeof i?h.extend(n[t],i):i)}),n},e.prototype.setup=function(){var n=this;this.$container.css({position:"relative","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none"}),this.$container.find("img").attr("ondragstart","return false"),this.$container.on("mouseenter touchenter",function(t){var e,i,o;n.$current&&(i=!(e=h(this)).is(n.$current),o=n.options.exchangeable,n.dragging&&i&&o&&(n.$current=e,n.updatePlaceholder(t,e,!0)))}),this.$container.on("mousedown touchstart","> *",function(t){var e=h(this);n.prepare(t,e)}),this.$container.on("mouseenter touchenter","> *",function(t){var e,i,o;n.$current&&(e=h(this),i=!!n.$current.find(this).length,o=n.options.exchangeable,n.dragging&&(i||o)&&n.updatePlaceholder(t,e))}),h("body").on("mousemove touchmove",this.update.bind(this)),h("body").on("mouseup touchend",this.end.bind(this)),h("body").on("mouseleave",this.end.bind(this)),h(window).on("blur",this.end.bind(this))},e.prototype.prepare=function(t,e){var i=this.options.draggable,o=i&&h(i);this.active&&(!o||(o.is(t.target)||o.find(t.target).length))&&(this.holding=!0,this.$target=e,this.$current=e.closest(this.$container),this.mouse.update(t))},e.prototype.start=function(t){var e=this.$target,i=e.clone().css({position:"absolute",zIndex:9999,pointerEvents:"none",height:e.outerHeight(),width:e.outerWidth()}),o=this.options.placeholderTarget||"
",n=h(o).css({position:"absolute",pointerEvents:"none",zIndex:9998,margin:0,padding:0,height:e.outerHeight(),width:e.outerWidth()});this.mouse.offsetX=this.mouse.positionX-e.offset().left,this.mouse.offsetY=this.mouse.positionY-e.offset().top,e.css("visibility","hidden"),e.attr("data-dad-target",!0),this.dragging=!0,this.$target=e,this.$clone=i,this.$placeholder=n,this.$current.append(n).append(i),this.updateClonePosition(),this.updatePlaceholderPosition()},e.prototype.update=function(t){this.mouse.update(t),this.holding&&!this.dragging&&this.start(t),this.dragging&&this.updateClonePosition()},e.prototype.end=function(t){var e,i,o,n,s,r;this.holding=!1,this.dragging&&(e=this.$current,i=this.$target,o=this.$clone,n=this.$placeholder,s=i.offset().left-e.offset().left,r=i.offset().top-e.offset().top,h(e).trigger("dadDropStart",[i[0]]),o.animate({top:r,left:s,height:i.outerHeight(),width:i.outerWidth()},this.options.transition,function(){o.remove(),n.remove(),i.removeAttr("data-dad-target"),i.css("visibility",""),h(e).trigger("dadDropEnd",[i[0]])}),this.dragging=!1,this.$current=null,this.$target=null,this.$clone=null,this.$placeholder=null)},e.prototype.updateClonePosition=function(){var t=this.mouse.positionY-this.$current.offset().top-this.mouse.offsetY,e=this.mouse.positionX-this.$current.offset().left-this.mouse.offsetX;this.$clone.css({top:t,left:e})},e.prototype.updatePlaceholder=function(t,e,i){i?(e.append(this.$target),e.append(this.$clone),e.append(this.$placeholder)):e.index()>this.$target.index()?e.after(this.$target):e.before(this.$target),this.updatePlaceholderPosition()},e.prototype.updatePlaceholderPosition=function(){var t=this.options.placeholderTarget,e=t?this.$target.find(t):this.$target,i=e.offset().top-this.$current.offset().top,o=e.offset().left-this.$current.offset().left,n=e.outerHeight(),s=e.outerWidth();this.$placeholder.css({top:i,left:o,width:s,height:n})},e.prototype.onDrop=function(t,e){h(t).on("mouseenter touchenter",function(t){h(this).attr("data-dad-active",!0)})},e.prototype.setActive=function(t){this.active=t,this.$container.attr("data-dad-active",t)},e.prototype.activate=function(){this.setActive(!0)},e.prototype.deactivate=function(){this.setActive(!1)},h.fn.dad=function(t){return new e(this,t)}}(jQuery); \ No newline at end of file +!function(h){"use strict";function i(){this.positionX=0,this.positionY=0,this.offsetX=0,this.offsetY=0}function e(t,e){this.options=this.parseOptions(e),this.$container=h(t),this.$current=null,this.$target=null,this.$clone=null,this.mouse=new i,this.holding=!1,this.dragging=!1,this.dropzones=[],this.setActive(this.options.active),this.setup()}e.defaultOptions={active:!0,draggable:!(i.prototype.update=function(t){var e,i;("ontouchstart"in window||navigator.msMaxTouchPoints)&&"touchmove"==t.type?(e=t.originalEvent.touches[0],i=document.elementFromPoint(e.clientX,e.clientY),h(i).trigger("touchenter"),this.positionX=e.pageX,this.positionY=e.pageY):(this.positionX=t.pageX,this.positionY=t.pageY)}),exchangeable:!0,transition:200,placeholderTarget:!1,placeholderTemplate:"
"},e.prototype.parseOptions=function(o){var n=h.extend(!0,{},e.defaultOptions);return o&&h.each(n,function(t,e){var i=o[t];void 0!==i&&(n[t]="object"==typeof i?h.extend(n[t],i):i)}),n},e.prototype.setup=function(){var n=this;this.$container.css({position:"relative","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none"}),this.$container.find("img").attr("ondragstart","return false"),this.$container.on("mouseenter touchenter",function(t){var e,i,o;n.$current&&(i=!(e=h(this)).is(n.$current),o=n.options.exchangeable,n.dragging&&i&&o&&(n.$current=e,n.updatePlaceholder(t,e,!0)))}),this.$container.on("mousedown touchstart","> *",function(t){var e=h(this);n.prepare(t,e)}),this.$container.on("mouseenter touchenter","> *",function(t){var e,i,o;n.$current&&(e=h(this),i=!!n.$current.find(this).length,o=n.options.exchangeable,n.dragging&&(i||o)&&n.updatePlaceholder(t,e))}),h("body").on("mousemove touchmove",this.update.bind(this)),h("body").on("mouseup touchend",this.end.bind(this)),h("body").on("mouseleave",this.end.bind(this)),h(window).on("blur",this.end.bind(this))},e.prototype.prepare=function(t,e){var i=this.options.draggable,o=i&&h(i);this.active&&(!o||(o.is(t.target)||o.find(t.target).length))&&(this.holding=!0,this.$target=e,this.$current=e.closest(this.$container),this.mouse.update(t))},e.prototype.start=function(t){var e=this.$target,i=e.clone().css({position:"absolute",zIndex:9999,pointerEvents:"none",height:e.outerHeight(),width:e.outerWidth()}),o=h(this.options.placeholderTemplate).css({position:"absolute",pointerEvents:"none",zIndex:9998,margin:0,padding:0,height:e.outerHeight(),width:e.outerWidth()});this.mouse.offsetX=this.mouse.positionX-e.offset().left,this.mouse.offsetY=this.mouse.positionY-e.offset().top,e.css("visibility","hidden"),e.attr("data-dad-target",!0),this.dragging=!0,this.$target=e,this.$clone=i,this.$placeholder=o,this.$current.append(o).append(i),this.updateClonePosition(),this.updatePlaceholderPosition()},e.prototype.update=function(t){this.mouse.update(t),this.holding&&!this.dragging&&this.start(t),this.dragging&&this.updateClonePosition()},e.prototype.end=function(t){var e,i,o,n,s,r;this.holding=!1,this.dragging&&(e=this.$current,i=this.$target,o=this.$clone,n=this.$placeholder,s=i.offset().left-e.offset().left,r=i.offset().top-e.offset().top,h(e).trigger("dadDropStart",[i[0]]),o.animate({top:r,left:s,height:i.outerHeight(),width:i.outerWidth()},this.options.transition,function(){o.remove(),n.remove(),i.removeAttr("data-dad-target"),i.css("visibility",""),h(e).trigger("dadDropEnd",[i[0]])}),this.dragging=!1,this.$current=null,this.$target=null,this.$clone=null,this.$placeholder=null)},e.prototype.updateClonePosition=function(){var t=this.mouse.positionY-this.$current.offset().top-this.mouse.offsetY,e=this.mouse.positionX-this.$current.offset().left-this.mouse.offsetX;this.$clone.css({top:t,left:e})},e.prototype.updatePlaceholder=function(t,e,i){i?(e.append(this.$target),e.append(this.$clone),e.append(this.$placeholder)):e.index()>this.$target.index()?e.after(this.$target):e.before(this.$target),this.updatePlaceholderPosition()},e.prototype.updatePlaceholderPosition=function(){var t=this.options.placeholderTarget,e=t?this.$target.find(t):this.$target,i=e.offset().top-this.$current.offset().top,o=e.offset().left-this.$current.offset().left,n=e.outerHeight(),s=e.outerWidth();this.$placeholder.css({top:i,left:o,width:s,height:n})},e.prototype.onDrop=function(t,e){h(t).on("mouseenter touchenter",function(t){h(this).attr("data-dad-active",!0)})},e.prototype.setActive=function(t){this.active=t,this.$container.attr("data-dad-active",t)},e.prototype.activate=function(){this.setActive(!0)},e.prototype.deactivate=function(){this.setActive(!1)},h.fn.dad=function(t){return new e(this,t)}}(jQuery); \ No newline at end of file