Esempio n. 1
0
Draggable.prototype.updateLimits = function () {
	var that = this;

	//initial translation offsets
	var initXY = that.getCoords();

	//calc initial coords
	that.prevX = initXY[0];
	that.prevY = initXY[1];
	that.initX = initXY[0];
	that.initY = initXY[1];

	//container rect might be outside the vp, so calc absolute offsets
	//zero-position offsets, with translation(0,0)
	var thatOffsets = offsets(that.element);

	that.initOffsetX = thatOffsets.left - that.prevX;
	that.initOffsetY = thatOffsets.top - that.prevY;
	that.offsets = thatOffsets;

	//handle parent case
	var within = that.within;
	if (that.within === 'parent' || that.within === true) {
		within = that.element.parentNode;
	}
	within = within || doc;

	//absolute offsets of a container
	var withinOffsets = offsets(within);

	if (within === win && that._isFixed) {
		withinOffsets.top -= win.pageYOffset;
		withinOffsets.left -= win.pageXOffset;
		withinOffsets.bottom -= win.pageYOffset;
		withinOffsets.right -= win.pageXOffset;
	}
	that.withinOffsets = withinOffsets;

	//calculate movement limits - pin width might be wider than constraints
	that.overflowX = that.pin.width - withinOffsets.width;
	that.overflowY = that.pin.height - withinOffsets.height;

	that.limits = {
		left: withinOffsets.left - that.initOffsetX - that.pin[0] - (that.overflowX < 0 ? 0 : that.overflowX),
		top: withinOffsets.top - that.initOffsetY - that.pin[1] - (that.overflowY < 0 ? 0 : that.overflowY),
		right: that.overflowX > 0 ? 0 : withinOffsets.right - that.initOffsetX - that.pin[2],
		bottom: (that.overflowY > 0 ? 0 : withinOffsets.bottom - that.initOffsetY - that.pin[3])
	};
};
Esempio n. 2
0
		that.dropTargets.forEach(function (dropTarget) {
			var targetRect = offsets(dropTarget);

			if (intersect(thatRect, targetRect, that.droppableTolerance)) {
				if (that.droppableClass) {
					dropTarget.classList.add(that.droppableClass);
				}
				if (!that.dropTarget) {
					that.dropTarget = dropTarget;

					emit(that, 'dragover', dropTarget);
					emit(dropTarget, 'dragover', that);
				}
			}
			else {
				if (that.dropTarget) {
					emit(that, 'dragout', dropTarget);
					emit(dropTarget, 'dragout', that);

					that.dropTarget = null;
				}
				if (that.droppableClass) {
					dropTarget.classList.remove(that.droppableClass);
				}
			}
		});