From bd4b0451be634cbad04122ba5e5ede5758f2ab10 Mon Sep 17 00:00:00 2001 From: Piotr Nalepa Date: Mon, 12 Dec 2016 14:52:18 +0100 Subject: [PATCH] Removing existing placeholders before creating a new one --- bower.json | 2 +- dragster.js | 9 ++++++--- dragster.min.js | 6 +++--- dragster.min.js.gz | Bin 2719 -> 2727 bytes dragster.style.css | 4 ++-- package.json | 2 +- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bower.json b/bower.json index d77cb8d..b0ec76f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "dragsterjs", - "version": "1.3.5", + "version": "1.3.6", "homepage": "https://github.com/sunpietro/dragster", "authors": [ "Piotr Nalepa " diff --git a/dragster.js b/dragster.js index 1fb15af..633bc84 100644 --- a/dragster.js +++ b/dragster.js @@ -1,5 +1,5 @@ /*@preserve - * Dragster - drag'n'drop library v1.3.5 + * Dragster - drag'n'drop library v1.3.6 * https://github.com/sunpietro/dragster * * Copyright 2015-2016 Piotr Nalepa @@ -8,7 +8,7 @@ * Released under the MIT license * https://github.com/sunpietro/dragster/blob/master/LICENSE * - * Date: 2016-12-12T07:00Z + * Date: 2016-12-12T19:00Z */ (function (window, document) { 'use strict'; @@ -145,7 +145,7 @@ */ clonedTo: NULL, }, - dragsterEventInfo, + dragsterEventInfo = {}, key, regions, getElement, @@ -574,10 +574,13 @@ dragsterEventInfo.shadow.left = left; if (dropTarget && dropTarget !== draggedElement && !isInDragOnlyRegion) { + moveActions.removePlaceholders(); moveActions.addPlaceholderOnTarget(dropTarget, elementPositionY, pageYOffset); } else if (isTargetRegion && !isTargetRegionDragOnly && !hasTargetDraggaBleElements && !hasTargetPlaceholders) { + moveActions.removePlaceholders(); moveActions.addPlaceholderInRegion(unknownTarget); } else if (isTargetRegion && !isTargetRegionDragOnly && hasTargetDraggaBleElements && !hasTargetPlaceholders) { + moveActions.removePlaceholders(); moveActions.addPlaceholderInRegionBelowTargets(unknownTarget); } else if (!isTargetRegion && !isTargetPlaceholder) { moveActions.removePlaceholders(); diff --git a/dragster.min.js b/dragster.min.js index 8ab0c1c..ef5051e 100644 --- a/dragster.min.js +++ b/dragster.min.js @@ -1,5 +1,5 @@ /*@preserve - * Dragster - drag'n'drop library v1.3.5 + * Dragster - drag'n'drop library v1.3.6 * https://github.com/sunpietro/dragster * * Copyright 2015-2016 Piotr Nalepa @@ -8,6 +8,6 @@ * Released under the MIT license * https://github.com/sunpietro/dragster/blob/master/LICENSE * - * Date: 2016-12-12T07:00Z + * Date: 2016-12-12T19:00Z */ -!function(e,t){"use strict";e.Dragster=function(n){var r,o,a,s,l,i,d,c,g,u,m,p,f,h,v,E,L,y,C,w,b,D,B,T,H,N,A,S,M,R="dragster-",O="is-dragging",P="is-drag-over",I=R+"draggable",Y=R+"drag-region",q=R+"drop-placeholder",x=R+"temp",F=x+"-container",X=R+"is-hidden",k=R+"replacable",J=R+"region--drag-only",W="touchstart",j="touchmove",z="touchend",G="mousedown",K="mousemove",Q="mouseup",U="top",V="bottom",Z="px",$="div",_=!1,ee=!0,te=null,ne=function(){},re={elementSelector:".dragster-block",regionSelector:".dragster-region",dragHandleCssClass:_,dragOnlyRegionCssClass:J,replaceElements:_,updateRegionsHeight:ee,minimumRegionHeight:60,onBeforeDragStart:ne,onAfterDragStart:ne,onBeforeDragMove:ne,onAfterDragMove:ne,onBeforeDragEnd:ne,onAfterDragEnd:ne,onAfterDragDrop:ne,scrollWindowOnDrag:_,dragOnlyRegionsEnabled:_,cloneElements:_,wrapDraggableElements:ee},oe="data-placeholder-position",ae={top:_,bottom:_},se={drag:{node:te},drop:{node:te},shadow:{node:te,top:0,left:0},placeholder:{node:te,position:te},dropped:te,clonedFrom:te,clonedTo:te},le=e.innerHeight;for(o in n)n.hasOwnProperty(o)&&(re[o]=n[o]);return B=function(){return[].slice.call(t.querySelectorAll(re.elementSelector))},T=function(e){return re.wrapDraggableElements===_?(console.warn("You have disabled the default behavior of wrapping the draggable elements. If you want Dragster.js to work properly you still will have to do this manually.\n\nMore info: https://github.com/sunpietro/dragster/blob/master/README.md#user-content-wrapdraggableelements---boolean"),_):void e.forEach(function(e){var t=E(),n=e.parentNode;return n.classList.contains(I)?_:(n.insertBefore(t,e),n.removeChild(e),void t.appendChild(e))})},g=B(),a=[].slice.call(t.querySelectorAll(re.regionSelector)),re.replaceElements&&(d=t.createElement($),d.classList.add(X),d.classList.add(F),t.body.appendChild(d)),s=function(e,t){var n=e.parentNode;if(n&&(!e.classList||!e.classList.contains(Y)||e.classList.contains(J)))return t(e)?e:t(n)?n:s(n,t)},w=function(e){var n=[].slice.call(t.getElementsByClassName(e));n.forEach(function(e){e.parentNode.removeChild(e)})},b=function(e,n){n&&(a.forEach(function(e){e.removeEventListener(n,u.mousemove)}),t.body.removeEventListener(n,u.mousemove)),e&&e.classList.remove(O),[].slice.call(t.getElementsByClassName(I)).forEach(function(e){e.firstChild||e.parentNode.removeChild(e)}),w(q),w(x),H()},D=function(){[].slice.call(t.getElementsByClassName(k)).forEach(function(e){e.classList.remove(k)})},E=function(){var e=t.createElement($);return e.classList.add(I),e},y=function(){var e=t.createElement($);return e.classList.add(q),e},L=function(){var e=t.createElement($);return e.classList.add(x),e.classList.add(X),e.style.position="fixed",t.body.appendChild(e),e},h=function(e,t){if(e&&e.parentNode){var n=re.wrapDraggableElements===_?e:e.nextSibling;e.parentNode.insertBefore(t,n)}},v=function(e,t){e&&e.parentNode&&e.parentNode.insertBefore(t,e)},p=function(e){return e.classList&&e.classList.contains(I)},m=function(e){return e.classList&&e.classList.contains(q)},f=function(e){return e.classList&&e.classList.contains(re.dragOnlyRegionCssClass)},H=function(){if(re.updateRegionsHeight){var n=[].slice.call(t.getElementsByClassName(Y));n.forEach(function(t){var n=[].slice.call(t.querySelectorAll(re.elementSelector)),r=re.minimumRegionHeight;n.length&&(n.forEach(function(t){var n=e.getComputedStyle(t);r+=t.offsetHeight+parseInt(n.marginTop,10)+parseInt(n.marginBottom,10)}),t.style.height=r+Z)})}},u={mousedown:function(e){if(re.dragHandleCssClass&&("string"!=typeof re.dragHandleCssClass||!e.target.classList.contains(re.dragHandleCssClass)))return!1;var n,o;return e.dragster=r,re.onBeforeDragStart(e)===_||3===e.which?_:(e.preventDefault(),o=e.type===W?j:K,a.forEach(function(e){e.addEventListener(o,u.mousemove)}),t.body.addEventListener(o,u.mousemove),(c=s(e.target,p))?(n=c.getBoundingClientRect(),l=L(),l.innerHTML=c.innerHTML,l.style.width=n.width+Z,l.style.height=n.height+Z,i=l.getBoundingClientRect(),c.classList.add(O),r=JSON.parse(JSON.stringify(se)),r.drag.node=c,r.shadow.node=l,e.dragster=r,void re.onAfterDragStart(e)):_)},mousemove:function(e){if(e.dragster=r,re.onBeforeDragMove(e)===_)return _;e.preventDefault();var n=e.changedTouches?e.changedTouches[0]:e,o=n.view?n.view.pageXOffset:0,a=n.view?n.view.pageYOffset:0,d=n.clientY+a,g=n.clientX+o,u=t.elementFromPoint(n.clientX,n.clientY),m=s(u,p),h=n.clientY,v=g-i.width/2,E=!(!m||!s(m,f)),L=u.classList.contains(Y),y=u.classList.contains(J),w=u.classList.contains(q),b=u.getElementsByClassName(I).length>0,D=u.getElementsByClassName(q).length>0;clearTimeout(C),l.style.top=h+Z,l.style.left=v+Z,l.classList.remove(X),r.shadow.top=h,r.shadow.left=v,m&&m!==c&&!E?M.addPlaceholderOnTarget(m,d,a):!L||y||b||D?L&&!y&&b&&!D?M.addPlaceholderInRegionBelowTargets(u):L||w||M.removePlaceholders():M.addPlaceholderInRegion(u),re.scrollWindowOnDrag&&N(e),H(),re.onAfterDragMove(e)},mouseup:function(e){if(e.dragster=r,re.onBeforeDragEnd(e)===_)return _;var n,o=re.replaceElements?k:q,a=t.getElementsByClassName(o)[0],l=!(!c||!s(c,f)),i=e.type===W?j:K,d=re.cloneElements&&l;return C=setTimeout(function(){b(c,i)},200),D(),c&&a?(n=s(a,p),n=n||a,c!==n&&(re.replaceElements||d?re.replaceElements&&!d?(e.dragster=S.replaceElements(e.dragster,n),re.onAfterDragDrop(e)):!re.replaceElements&&d&&(e.dragster=S.cloneElements(e.dragster,a,n),re.onAfterDragDrop(e)):(e.dragster=S.moveElement(e.dragster,a,n),re.onAfterDragDrop(e)),n.classList.remove(P)),b(c,i),void re.onAfterDragEnd(e)):(b(c,i),_)}},M={addPlaceholderOnTarget:function(e,t,n){var o=e.getBoundingClientRect(),a=y(),s=o.height/2;D(),re.replaceElements?e.classList.add(k):t-n-o.top0,b=g.getElementsByClassName(Y).length>0;clearTimeout(y),s.style.top=f+V,s.style.left=h+V,s.classList.remove(F),se.shadow.top=f,se.shadow.left=h,u&&u!==d&&!v?(S.removePlaceholders(),S.addPlaceholderOnTarget(u,i,o)):!E||L||w||b?E&&!L&&w&&!b?(S.removePlaceholders(),S.addPlaceholderInRegionBelowTargets(g)):E||C||S.removePlaceholders():(S.removePlaceholders(),S.addPlaceholderInRegion(g)),ne.scrollWindowOnDrag&&H(e),T(),ne.onAfterDragMove(e)},mouseup:function(e){if(e.dragster=se,ne.onBeforeDragEnd(e)===$)return $;var n,r=ne.replaceElements?X:Y,o=t.getElementsByClassName(r)[0],s=!(!d||!a(d,p)),l=e.type===J?W:G,i=ne.cloneElements&&s;return y=setTimeout(function(){w(d,l)},200),b(),d&&o?(n=a(o,m),n=n||o,d!==n&&(ne.replaceElements||i?ne.replaceElements&&!i?(e.dragster=A.replaceElements(e.dragster,n),ne.onAfterDragDrop(e)):!ne.replaceElements&&i&&(e.dragster=A.cloneElements(e.dragster,o,n),ne.onAfterDragDrop(e)):(e.dragster=A.moveElement(e.dragster,o,n),ne.onAfterDragDrop(e)),n.classList.remove(P)),w(d,l),void ne.onAfterDragEnd(e)):(w(d,l),$)}},S={addPlaceholderOnTarget:function(e,t,n){var r=e.getBoundingClientRect(),o=L(),a=r.height/2;b(),ne.replaceElements?e.classList.add(X):t-n-r.top$|17vbxXLEFAaxQIYZZ2wb0HqjfbJ|Gq`~C`{bFtF8k#V*z zRVP-*`9U_$`jNy=VsAE;5@-M=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style.css b/dragster.style.css index d56e60b..69e2580 100644 --- a/dragster.style.css +++ b/dragster.style.css @@ -1,5 +1,5 @@ /* - * Dragster - drag'n'drop library v1.3.5 + * Dragster - drag'n'drop library v1.3.6 * https://github.com/sunpietro/dragster * * Copyright 2015-2016 Piotr Nalepa @@ -8,7 +8,7 @@ * Released under the MIT license * https://github.com/sunpietro/dragster/blob/master/LICENSE * - * Date: 2016-12-12T07:00Z + * Date: 2016-12-12T19:00Z */ * { box-sizing: border-box; diff --git a/package.json b/package.json index 38b0723..8e4d473 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dragsterjs", - "version": "1.3.5", + "version": "1.3.6", "description": "Tiny vanilla JS plugin that enables drag'n'drop interactions to a user of your website", "main": "dragster.js", "scripts": {