diff --git a/dragster.es6.js b/dragster.es6.js
index 37ea20f..0dae93c 100644
--- a/dragster.es6.js
+++ b/dragster.es6.js
@@ -1,5 +1,5 @@
/*@preserve
- * Dragster - drag'n'drop library v1.5.0
+ * Dragster - drag'n'drop library v1.6.0
* https://github.com/sunpietro/dragster
*
* Copyright 2015-2017 Piotr Nalepa
@@ -10,7 +10,7 @@
*
* Date: 2017-05-06T22:30Z
*/
-
+ //jshint ignore:line
var Dragster = function (params) {
var PREFIX_CLASS_DRAGSTER = 'dragster-',
CLASS_DRAGGING = 'is-dragging',
@@ -961,9 +961,29 @@ var Dragster = function (params) {
regions = findRegionElements();
addEventListenersToRegions();
+ },
+ destroy: function () {
+ regions.forEach(function (region) {
+ region.classList.remove(CLASS_REGION);
+
+ region.removeEventListener(EVT_MOUSEDOWN, regionEventHandlers.mousedown, FALSE);
+ region.removeEventListener(EVT_MOUSEMOVE, regionEventHandlers.mousemove, FALSE);
+ region.removeEventListener(EVT_MOUSEUP, regionEventHandlers.mouseup, FALSE);
+
+ region.removeEventListener(EVT_TOUCHSTART, regionEventHandlers.mousedown, FALSE);
+ region.removeEventListener(EVT_TOUCHMOVE, regionEventHandlers.mousemove, FALSE);
+ region.removeEventListener(EVT_TOUCHEND, regionEventHandlers.mouseup, FALSE);
+ });
+
+ document.body.removeEventListener(EVT_MOUSEMOVE, regionEventHandlers.mousemove, FALSE);
+ document.body.removeEventListener(EVT_TOUCHMOVE, regionEventHandlers.mousemove, FALSE);
+ document.body.removeEventListener(EVT_MOUSEUP, regionEventHandlers.mouseup, FALSE);
+ document.body.removeEventListener(EVT_TOUCHEND, regionEventHandlers.mouseup, FALSE);
+
+ window.removeEventListener('resize', discoverWindowHeight, false);
}
};
};
-
+ //jshint ignore:line
export default Dragster;
diff --git a/dragster.js b/dragster.js
index 6414b93..5554e39 100644
--- a/dragster.js
+++ b/dragster.js
@@ -1,5 +1,5 @@
/*@preserve
- * Dragster - drag'n'drop library v1.5.0
+ * Dragster - drag'n'drop library v1.6.0
* https://github.com/sunpietro/dragster
*
* Copyright 2015-2017 Piotr Nalepa
@@ -10,7 +10,7 @@
*
* Date: 2017-05-06T22:30Z
*/
-
+ //jshint ignore:line
;(function (root, moduleName, factory) {
'use strict';
@@ -974,6 +974,26 @@ var Dragster = function (params) {
regions = findRegionElements();
addEventListenersToRegions();
+ },
+ destroy: function () {
+ regions.forEach(function (region) {
+ region.classList.remove(CLASS_REGION);
+
+ region.removeEventListener(EVT_MOUSEDOWN, regionEventHandlers.mousedown, FALSE);
+ region.removeEventListener(EVT_MOUSEMOVE, regionEventHandlers.mousemove, FALSE);
+ region.removeEventListener(EVT_MOUSEUP, regionEventHandlers.mouseup, FALSE);
+
+ region.removeEventListener(EVT_TOUCHSTART, regionEventHandlers.mousedown, FALSE);
+ region.removeEventListener(EVT_TOUCHMOVE, regionEventHandlers.mousemove, FALSE);
+ region.removeEventListener(EVT_TOUCHEND, regionEventHandlers.mouseup, FALSE);
+ });
+
+ document.body.removeEventListener(EVT_MOUSEMOVE, regionEventHandlers.mousemove, FALSE);
+ document.body.removeEventListener(EVT_TOUCHMOVE, regionEventHandlers.mousemove, FALSE);
+ document.body.removeEventListener(EVT_MOUSEUP, regionEventHandlers.mouseup, FALSE);
+ document.body.removeEventListener(EVT_TOUCHEND, regionEventHandlers.mouseup, FALSE);
+
+ window.removeEventListener('resize', discoverWindowHeight, false);
}
};
};
diff --git a/dragster.min.js b/dragster.min.js
index 3668a57..e3824ea 100644
--- a/dragster.min.js
+++ b/dragster.min.js
@@ -1,5 +1,5 @@
/*@preserve
- * Dragster - drag'n'drop library v1.5.0
+ * Dragster - drag'n'drop library v1.6.0
* https://github.com/sunpietro/dragster
*
* Copyright 2015-2017 Piotr Nalepa
@@ -10,4 +10,4 @@
*
* Date: 2017-05-06T22:30Z
*/
-!function(e,t,n){"use strict";"function"==typeof define&&define.amd?define(t,n):"object"==typeof exports?exports=module.exports=n():e[t]=n()}(this,"Dragster",function(){"use strict";var e=function(e){var t,n,o,r,a,s,l,d,i,c,g,u,m,p,f,h,v,E,w,L,y,C,D,b,B,T,H,M,N,P,R,S,I,A="dragster-",O="is-dragging",Y="is-drag-over",x=A+"draggable",X=A+"drag-region",q=A+"drop-placeholder",F=A+"temp",U=F+"-container",j=A+"is-hidden",k=A+"replacable",J="touchstart",W="touchmove",z="touchend",G="mousedown",K="mousemove",Q="mouseup",V="top",Z="bottom",$="px",_="div",ee=!1,te=!0,ne=null,oe=function(){},re={elementSelector:".dragster-block",regionSelector:".dragster-region",dragHandleCssClass:ee,dragOnlyRegionCssClass:A+"region--drag-only",replaceElements:ee,updateRegionsHeight:te,minimumRegionHeight:60,onBeforeDragStart:oe,onAfterDragStart:oe,onBeforeDragMove:oe,onAfterDragMove:oe,onBeforeDragEnd:oe,onAfterDragEnd:oe,onAfterDragDrop:oe,scrollWindowOnDrag:ee,dragOnlyRegionsEnabled:ee,cloneElements:ee,wrapDraggableElements:te,shadowElementUnderMouse:ee},ae={top:ee,bottom:ee},se={drag:{node:ne},drop:{node:ne},shadow:{node:ne,top:0,left:0},placeholder:{node:ne,position:ne},dropped:ne,clonedFrom:ne,clonedTo:ne},le={},de=window.innerHeight,ie=Math.floor(65536*(1+Math.random())).toString(16);for(t in e)e.hasOwnProperty(t)&&(re[t]=e[t]);return C=function(){return[].slice.call(document.querySelectorAll(re.elementSelector))},D=function(){return[].slice.call(document.querySelectorAll(re.regionSelector))},b=function(e){return re.wrapDraggableElements===ee?(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"),ee):void e.forEach(function(e){var t=f(),n=e.parentNode;return n.classList.contains(x)?ee:(n.insertBefore(t,e),n.removeChild(e),void t.appendChild(e))})},d=C(),n=D(),re.replaceElements&&(s=document.createElement(_),s.classList.add(j),s.classList.add(U),document.body.appendChild(s)),o=function(e,t){var n=e.parentNode;if(n&&(!e.classList||!e.classList.contains(X)||e.classList.contains(re.dragOnlyRegionCssClass)))return t(e)?e:t(n)?n:o(n,t)},w=function(e){var t=[].slice.call(document.getElementsByClassName(e));t.forEach(function(e){e.dataset.dragsterId===ie&&e.parentNode.removeChild(e)})},L=function(e,t){t&&(n.forEach(function(e){e.removeEventListener(t,i.mousemove)}),document.body.removeEventListener(t,i.mousemove)),e&&e.classList.remove(O),[].slice.call(document.getElementsByClassName(x)).forEach(function(e){e.firstChild||e.parentNode.removeChild(e)}),w(q),w(F),B()},y=function(){[].slice.call(document.getElementsByClassName(k)).forEach(function(e){e.classList.remove(k)})},f=function(){var e=document.createElement(_);return e.classList.add(x),e.dataset.dragsterId=ie,e},v=function(){var e=document.createElement(_);return e.classList.add(q),e.dataset.dragsterId=ie,e},h=function(){var e=document.createElement(_);return e.classList.add(F),e.classList.add(j),e.style.position="fixed",e.dataset.dragsterId=ie,document.body.appendChild(e),e},m=function(e,t){if(e&&e.parentNode){var n=re.wrapDraggableElements===ee?e:e.nextSibling;e.parentNode.insertBefore(t,n)}},p=function(e,t){e&&e.parentNode&&e.parentNode.insertBefore(t,e)},g=function(e){return e.classList&&e.classList.contains(x)&&e.dataset.dragsterId===ie},c=function(e){return e.classList&&e.classList.contains(q)},u=function(e){return e.classList&&e.classList.contains(re.dragOnlyRegionCssClass)},B=function(){if(re.updateRegionsHeight){var e=[].slice.call(document.getElementsByClassName(X));e.forEach(function(e){var t=[].slice.call(e.querySelectorAll(re.elementSelector)),n=re.minimumRegionHeight;t.length&&(t.forEach(function(e){var t=window.getComputedStyle(e);n+=e.offsetHeight+parseInt(t.marginTop,10)+parseInt(t.marginBottom,10)}),e.style.height=n+$)})}},M=function(e,t){L(l,e),L(l,t)},i={mousedown:function(e){if(re.dragHandleCssClass&&("string"!=typeof re.dragHandleCssClass||!e.target.classList.contains(re.dragHandleCssClass)))return ee;var t,s,d,c=e.type===J,u=e.changedTouches?e.changedTouches[0]:e;return le=JSON.parse(JSON.stringify(se)),e.dragster=le,re.onBeforeDragStart(e)===ee||3===e.which?ee:(e.preventDefault(),(l=o(e.target,g))?(s=c?W:K,d=c?z:Q,n.forEach(function(e){e.addEventListener(s,i.mousemove,ee),e.addEventListener(d,i.mouseup,ee)}),document.body.addEventListener(s,i.mousemove,ee),document.body.addEventListener(d,i.mouseup,ee),t=l.getBoundingClientRect(),R=t.left-u.clientX,S=t.top-u.clientY,r=h(),r.innerHTML=l.innerHTML,r.style.width=t.width+$,r.style.height=t.height+$,r.dataset.dragsterId=ie,a=r.getBoundingClientRect(),l.classList.add(O),le.drag.node=l,le.shadow.node=r,e.dragster=le,void re.onAfterDragStart(e)):ee)},mousemove:function(e){if(e.dragster=le,re.onBeforeDragMove(e)===ee||!a)return ee;e.preventDefault();var t=e.changedTouches?e.changedTouches[0]:e,n=t.view?t.view.pageXOffset:0,s=t.view?t.view.pageYOffset:0,d=t.clientY+s,i=t.clientX+n,c=document.elementFromPoint(t.clientX,t.clientY),m=o(c,g),p=re.shadowElementUnderMouse?t.clientY+S:t.clientY,f=re.shadowElementUnderMouse?i+R:i-a.width/2,h=le.drag.node&&le.drag.node.dataset,v=!(!m||!o(m,u)),w=c.dataset.dragsterId===ie,L=c.classList.contains(X)&&w,y=c.classList.contains(re.dragOnlyRegionCssClass)&&w,C=c.classList.contains(q),D=c.getElementsByClassName(x).length>0,b=c.getElementsByClassName(q).length>0;clearTimeout(E),r.style.top=p+$,r.style.left=f+$,r.classList.remove(j),le.shadow.top=p,le.shadow.left=f,h||L||C?m&&m!==l&&!v?(P.removePlaceholders(),P.addPlaceholderOnTarget(m,d,s)):!L||y||D||b?L&&!y&&D&&!b&&(P.removePlaceholders(),P.addPlaceholderInRegionBelowTargets(c)):(P.removePlaceholders(),P.addPlaceholderInRegion(c)):P.removePlaceholders(),re.scrollWindowOnDrag&&T(e),B(),re.onAfterDragMove(e)},mouseup:function(e){e.dragster=le;var t,n,r,a,s,d=e.type===J,i=d?W:K,c=d?z:Q;return re.onBeforeDragEnd(e)===ee?(M(i,c),ee):(t=re.replaceElements?k:q,n=document.getElementsByClassName(t)[0],a=!(!l||!o(l,u)),s=re.cloneElements&&a,E=setTimeout(M,200),y(),l&&n?(r=o(n,g),r=r||n,l!==r&&(re.replaceElements||s?re.replaceElements&&!s?(e.dragster=N.replaceElements(e.dragster,r),re.onAfterDragDrop(e)):!re.replaceElements&&s&&(e.dragster=N.cloneElements(e.dragster,n,r),re.onAfterDragDrop(e)):(e.dragster=N.moveElement(e.dragster,n,r),re.onAfterDragDrop(e)),r.classList.remove(Y)),M(i,c),void re.onAfterDragEnd(e)):(M(i,c),ee))}},P={addPlaceholderOnTarget:function(e,t,n){var o=e.getBoundingClientRect(),r=v(),a=o.height/2;y(),re.replaceElements?e.classList.add(k):t-n-o.top0,D=c.getElementsByClassName(q).length>0;clearTimeout(E),r.style.top=p+$,r.style.left=f+$,r.classList.remove(j),de.shadow.top=p,de.shadow.left=f,h||w||C?g&&g!==d&&!v?(P.removePlaceholders(),P.addPlaceholderOnTarget(g,l,s)):!w||y||b||D?w&&!y&&b&&!D&&(P.removePlaceholders(),P.addPlaceholderInRegionBelowTargets(c)):(P.removePlaceholders(),P.addPlaceholderInRegion(c)):P.removePlaceholders(),re.scrollWindowOnDrag&&T(e),B(),re.onAfterDragMove(e)},mouseup:function(e){e.dragster=de;var t,n,r,a,s,l=e.type===z,i=l?J:K,c=l?W:Q;return re.onBeforeDragEnd(e)===ee?(M(i,c),ee):(t=re.replaceElements?k:q,n=document.getElementsByClassName(t)[0],a=!(!d||!o(d,u)),s=re.cloneElements&&a,E=setTimeout(M,200),y(),d&&n?(r=o(n,m),r=r||n,d!==r&&(re.replaceElements||s?re.replaceElements&&!s?(e.dragster=N.replaceElements(e.dragster,r),re.onAfterDragDrop(e)):!re.replaceElements&&s&&(e.dragster=N.cloneElements(e.dragster,n,r),re.onAfterDragDrop(e)):(e.dragster=N.moveElement(e.dragster,n,r),re.onAfterDragDrop(e)),r.classList.remove(Y)),M(i,c),void re.onAfterDragEnd(e)):(M(i,c),ee))}},P={addPlaceholderOnTarget:function(e,t,n){var o=e.getBoundingClientRect(),r=v(),a=o.height/2;y(),re.replaceElements?e.classList.add(k):t-n-o.top