in lib/@uncharted.software/stories-facets/src/components/group.js [1007:1077]
Group.prototype._performDragging = function (event) {
/* calculate the group dimensions */
var groupOffset = this._element.offset();
var groupTop = groupOffset.top;
var groupHeight = this._element.height();
/* calculate the new position */
var newTop, newLeft;
if (event.type === 'scroll') {
var contentOffset = this._groupContent.offset();
newTop = contentOffset.top - groupTop - this._draggingYOffset;
newLeft = contentOffset.left - groupOffset.left;
} else {
newTop = event.clientY - this._draggingY;
newLeft = event.clientX - this._draggingX;
}
/* calculate the scroll offset, if any */
this._draggingYOffset += this._draggingGroupTop - groupTop;
this._draggingGroupTop = groupTop;
newTop += this._draggingYOffset;
/* calculate the content dimensions */
var contentTop = groupTop + newTop;
var contentMiddle = contentTop + (groupHeight * 0.5);
/* retrieve all the groups */
var groups = this._widget._groups;
/* iterate through the groups */
for (var i = 0, n = groups.length; i < n; ++i) {
var group = groups[i];
/* get the target group measurements */
var targetHeight = group._element.height();
var targetTop = group._element.offset().top;
var targetBottom = targetTop + targetHeight;
var targetAreaThreshold = Math.min(targetHeight, groupHeight) * 0.5;
if ((groupTop > targetTop && contentMiddle >= targetTop - targetAreaThreshold && contentMiddle <= targetTop + targetAreaThreshold) ||
(groupTop < targetTop && contentMiddle >= targetBottom - targetAreaThreshold && contentMiddle <= targetBottom + targetAreaThreshold)){
if (group !== this) {
var targetOffset = 0;
if (targetTop < groupTop) {
group._element.before(this._element);
targetOffset = (targetTop - groupTop);
this._draggingY += targetOffset;
newTop -= targetOffset;
} else {
group._element.after(this._element);
targetOffset = (targetTop - groupTop) - (groupHeight - targetHeight);
this._draggingY += targetOffset;
newTop -= targetOffset;
}
this._draggingGroupTop = this._element.offset().top;
/* update the group indices */
this._widget.updateGroupIndices();
}
break;
}
}
/* apply the new position */
this._groupContent.css({
top: newTop,
left: newLeft
});
/* trigger the drag move event */
this.emit('facet-group:dragging:move', event, this._key);
};