Skip to content

Commit

Permalink
Added destroy() method to remove existing dragster events
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Nalepa committed Jun 28, 2017
1 parent 768d7b2 commit 652e036
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dragster-comment.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions dragster-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,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);
}
};
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dragsterjs",
"version": "1.5.0",
"version": "1.6.0",
"description": "Tiny vanilla JS plugin that enables drag'n'drop interactions to a user of your website",
"main": "dragster.js",
"scripts": {
Expand Down

0 comments on commit 652e036

Please sign in to comment.