Skip to content

Commit

Permalink
Feature: update region elements (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
dew326 authored and sunpietro committed Apr 14, 2017
1 parent f51adca commit 8c6c764
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions dragster.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
cleanWorkspace,
cleanReplacables,
findDraggableElements,
findRegionElements,
wrapDraggableElements,
updateRegionsHeight,
scrollWindow,
Expand All @@ -176,6 +177,7 @@
moveActions,
shadowElementPositionXDiff,
shadowElementPositionYDiff,
addEventListenersToRegions,
windowHeight = window.innerHeight,
dragsterId = Math.floor((1 + Math.random()) * 0x10000).toString(16);

Expand All @@ -197,6 +199,17 @@
return [].slice.call(document.querySelectorAll(finalParams.elementSelector));
};

/*
* Find all regions elements on the page
*
* @private
* @method findRegionElements
* @return {Array}
*/
findRegionElements = function () {
return [].slice.call(document.querySelectorAll(finalParams.regionSelector));
};

/*
* Wrap all elements from the `elements` param with a draggable wrapper
*
Expand Down Expand Up @@ -232,7 +245,7 @@
};

draggableElements = findDraggableElements();
regions = [].slice.call(document.querySelectorAll(finalParams.regionSelector));
regions = findRegionElements();

if (finalParams.replaceElements) {
tempContainer = document.createElement(DIV);
Expand Down Expand Up @@ -917,15 +930,24 @@

wrapDraggableElements(draggableElements);

// add `mousedown`/`touchstart` and `mouseup`/`touchend` event listeners to regions
regions.forEach(function (region) {
region.classList.add(CLASS_REGION);
region.dataset.dragsterId = dragsterId;

region.addEventListener(EVT_MOUSEDOWN, regionEventHandlers.mousedown, FALSE);
region.addEventListener(EVT_TOUCHSTART, regionEventHandlers.mousedown, FALSE);
/**
* Adds event listeners to the regions
*
* @method addEventListenersToRegions
* @private
*/
addEventListenersToRegions = function () {
// add `mousedown`/`touchstart` and `mouseup`/`touchend` event listeners to regions
regions.forEach(function (region) {
region.classList.add(CLASS_REGION);
region.dataset.dragsterId = dragsterId;

region.addEventListener(EVT_MOUSEDOWN, regionEventHandlers.mousedown, FALSE);
region.addEventListener(EVT_TOUCHSTART, regionEventHandlers.mousedown, FALSE);
});
};

});
addEventListenersToRegions();

window.addEventListener('resize', discoverWindowHeight, false);

Expand All @@ -936,6 +958,11 @@
wrapDraggableElements(draggableElements);
updateRegionsHeight();
discoverWindowHeight();
},
updateRegions: function () {
regions = findRegionElements();

addEventListenersToRegions();
}
};
};
Expand Down

0 comments on commit 8c6c764

Please sign in to comment.