This project is archived and is in readonly mode.

#504 ✓wontfix
SchizoDuckie

Drag.move checkAgainst not accurate enough

Reported by SchizoDuckie | November 30th, 2008 @ 05:20 PM

I'm working on some hefty drag&drop stuff and bumped into the limits of the current checkAgainst function.

If there's nesting in the droppables (e.g. you can drop the target inside an element that accepts drops) the first target is taken instead of the most accurate one.

I created a fix:


checkAgainst: function(el){
		el = el.getCoordinates();
		var now = this.mouse.now;
		return (now.x > el.left && now.x < el.right && now.y < el.bottom && now.y > el.top);
	},

	sort: function(el1, el2)
	{
		coord1 = el1.getCoordinates();
		coord2 = el2.getCoordinates();
		var now = this.mouse.now;
		return ({x: now.x - coord1.left,y: now.y - coord1.top} > {x: now.x - coord2.left,y: now.y - coord2.top});
	},

	checkDroppables: function(){
		var overed = this.droppables.filter(this.checkAgainst, this);
		overed = (overed.length > 1) ? overed.sort(this.sort.bind(this))[0] : overed[0];

		if (this.overed != overed){
			if (this.overed) this.fireEvent('leave', [this.element, this.overed]);
			if (overed){
				this.overed = overed;
				this.fireEvent('enter', [this.element, overed]);
			} else {
				this.overed = null;
			}
		}
	},

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages