Opened 9 years ago

Closed 3 years ago

#11045 closed enhancement (patchwelcome)

[cla][patch] DnD Enhancements

Reported by: Justin Cooley Owned by: Eugene Lazutkin
Priority: high Milestone: 1.13
Component: DnD Version: 1.5.0b1
Keywords: Cc:
Blocked By: Blocking:

Description

The project I've been working on required some features that the DnD didn't quite support so, I've added support for them as best as I could without having to rewrite too much. The key features are: nested DnD, drop widgets, selectors/indicators. I've provided a dirty but simple demo to show these features. Hopefully, this will be helpful.

Attachments (4)

ExtendedDnd.js (17.7 KB) - added by Justin Cooley 9 years ago.
Extended DnD Source
CourseDndDemo.js (7.1 KB) - added by Justin Cooley 9 years ago.
Demo Source
CourseDndDemo.html (1.1 KB) - added by Justin Cooley 9 years ago.
Demo
dnd_nested_targets.html (2.2 KB) - added by Ferdinand Weinberger 9 years ago.

Download all attachments as: .zip

Change History (15)

Changed 9 years ago by Justin Cooley

Attachment: ExtendedDnd.js added

Extended DnD Source

Changed 9 years ago by Justin Cooley

Attachment: CourseDndDemo.js added

Demo Source

Changed 9 years ago by Justin Cooley

Attachment: CourseDndDemo.html added

Demo

comment:1 Changed 9 years ago by Eugene Lazutkin

Milestone: tbdfuture
Status: newassigned
Summary: DnD Enhancements[patch] DnD Enhancements

@justinc: do you have a CLA on file?

comment:2 Changed 9 years ago by Justin Cooley

Yes, it should be under Omnibond Systems, LLC.

comment:3 in reply to:  1 Changed 9 years ago by Justin Cooley

Replying to elazutkin:

@justinc: do you have a CLA on file?

Yes, it should be under Omnibond Systems, LLC.

comment:4 Changed 9 years ago by Eugene Lazutkin

Summary: [patch] DnD Enhancements[cla][patch] DnD Enhancements

comment:5 Changed 9 years ago by Justin Cooley

Just found a bug in the dojo.dnd.Container getAllNodes method. My version messed up the order when selecting multiple DnD items that have already been moved from one container to the one they're being selected in. Here's the fix:

	getAllNodes: function( ) {
		// add support for drop widgets
		if(this.dropWidget && 'getChildren' in this.dropWidget) {
			var t = new dojo.NodeList();
			dojo.forEach(this.dropWidget.getChildren(), function(w) {
				t.push(w.domNode);
			});
			return t;
		}
		return dojo.query("> .dojoDndItem", this.parent);
	},

comment:6 Changed 9 years ago by Ferdinand Weinberger

hi justinc,

thx for the enhancement. did some tests with nested targets. if you try my example and try to drop a dnditem into one of the 3 targets, you'll see some troubles.

e.g. click a dnd-item and move it diagonal to the bottom right corner. it won't work. to reach this corner you have to move around the targets and drop it from the right side.

Changed 9 years ago by Ferdinand Weinberger

Attachment: dnd_nested_targets.html added

comment:7 Changed 9 years ago by Justin Cooley

At first glance, it looks like insertNodes is never being called. Give me a few days to look into it and I'll see if I can figure out what's going on.

comment:8 Changed 9 years ago by Justin Cooley

The problem is that the onOutEvent of the child container. It calls the sourceOut function of the Manager which clears out the target instead of setting it to the parent container. I've kinda fixed it but there still seems to be some issues if you try to drag and drop really fast. I thought I would go ahead and post it and maybe you'll be able to figure out a better way to handle it. I'll continue to work on it though.

dojo.declare("dojo.dnd.Manager", null, {
	// summary:
	//		the manager of DnD operations (usually a singleton)
	constructor: function(){
		this.avatar = null;
		this.source = null;
		this.nodes = [];
		this.copy = true;
		this.target = null;
		this.canDropFlag = false;
		this.events = [];
		this.targets = [];
	},

	// avatar's offset from the mouse
	OFFSET_X: 16,
	OFFSET_Y: 16,
	
	// methods
	overSource: function(source){
		// summary:
		//		called when a source detected a mouse-over condition
		// source: Object
		//		the reporter
		if(this.avatar){
			this.target = (source && source.targetState != "Disabled") ? source : null;
			this.canDropFlag = Boolean(this.target);
			this.avatar.update();
			if(this.target) {
				this.targets.push(this.target);
			}
		}
		dojo.publish("/dnd/source/over", [source]);
	},
	outSource: function(source){
		// summary:
		//		called when a source detected a mouse-out condition
		// source: Object
		//		the reporter
		if(this.avatar){
			if(this.target == source){
				this.targets.pop();
				// if there is a target it will just be pushed back onto the stack
				this.overSource(this.targets.pop());
			}
		}else{
			dojo.publish("/dnd/source/over", [null]);
		}
	},

comment:9 Changed 8 years ago by Justin Cooley

wuhi, we were having a problem where text couldn't be selected for anything inside of dnd containers. There's stuff in there for skipping for elements so, I wouldn't necessarily say this is a bug, but having the ability to copy and paste text within the container was something our users needed to be able to do. I added a for loop to onSelectStart in Container.js which, so far, seems to have solved our problem as long as we add the class dojoDndIgnore to the right element(s). If you're interested here you go:

	onSelectStart: function(e){
		// summary:
		//		event processor for onselectevent and ondragevent
		// e: Event
		//		mouse event
		for(var parent = e.target; parent && parent != this.parent; parent = parent.parentNode) {
			if(dojo.hasClass(parent, "dojoDndIgnore")) { return; }
		}
		
		if(!this.skipForm || !dojo.dnd.isFormElement(e)){
			dojo.stopEvent(e);
		}
	}

comment:10 Changed 6 years ago by rogerbx

Hi every one,

I tried to run the demo but I get the following error :

Error: NotFoundError?: DOM Exception 8

at line 300 in CourseDndDemo?.js :

cPane.dnd.insertNodes( false, data );

I thank you in advance for your answer.

Best regards,

Roger

comment:11 Changed 3 years ago by dylan

Milestone: future1.12
Resolution: patchwelcome
Status: assignedclosed

Unfortunately this patch was never finished. If someone wants to pick this backup and modernize the patch, we would consider it. Closing as patchwelcome.

Note: See TracTickets for help on using tickets.