Skip to main content

Search and Top Navigation

#14912 open feature ()

Opened January 30, 2016 09:29AM UTC

Last modified February 03, 2016 05:46PM UTC

Draggable: Allow setting containment during drag

Reported by: Mrten Owned by:
Priority: minor Milestone: none
Component: ui.draggable Version: 1.11.4
Keywords: Cc:
Blocked by: Blocking:
Description

If you set a containment in the start event instead of in the default options, like this:

https://jsfiddle.net/8wzdt8z5/8/

the intended containment between cell 2 and 4 only works the second time you drag cell 3.

If you add an (obvious internal) call to _setContainment it works the first time (see fiddle).

Attachments (0)
Change History (3)

Changed January 30, 2016 09:32AM UTC by Mrten comment:1

An obvious fix for this is:

Index: draggable.js
===================================================================
--- draggable.js	(revision 29006)
+++ draggable.js	(working copy)
@@ -202,15 +202,15 @@
 		//Adjust the mouse offset relative to the helper if "cursorAt" is supplied
 		(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));

-		//Set a containment if given in the options
-		this._setContainment();
-
 		//Trigger event + callbacks
 		if (this._trigger("start", event) === false) {
 			this._clear();
 			return false;
 		}

+		//Set a containment if given in the options
+		this._setContainment();
+
 		//Recache the helper size
 		this._cacheHelperProportions();

Changed February 02, 2016 02:18AM UTC by scottgonzalez comment:2

summary: Setting containment in start works only the second timeDraggable: Allow setting containment in the start event
type: bugfeature

It's not that this works the second time, it's that the call from the first time has been applied.

This option is not meant to be updated during a drag. I'm not sure if we want to add support for this either. We'll have to discuss this within the team.

In the meantime, you can accomplish this with a custom containment via the drag event. See https://jsfiddle.net/8wzdt8z5/9/

Changed February 03, 2016 05:46PM UTC by scottgonzalez comment:3

status: newopen
summary: Draggable: Allow setting containment in the start eventDraggable: Allow setting containment during drag

We're tentatively accepting this feature for the rewrite. However, the proposed patch is too limited since it only supports one specific time that the option can be changed. A proper implementation would handle changes to containment at any point.