Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init error if no source nodes and using extension dnd5 #761

Closed
TimNZ opened this issue Aug 17, 2017 · 8 comments
Closed

Init error if no source nodes and using extension dnd5 #761

TimNZ opened this issue Aug 17, 2017 · 8 comments

Comments

@TimNZ
Copy link

TimNZ commented Aug 17, 2017

Simply I need to render a Fancytree that may have no initial source e.g. no nodes.

When using extension 'dnd5' this results in an error as $scrollParent is empty (no children in $container), and subsequently results in an error in fn.scrollParent trying to access this[0].ownerDocument [triggered by code in dnd5 extension -> treeInit()]

$('#tree').fancytree({extensions: ['dnd5'],source: []})
Uncaught TypeError: Cannot read property 'ownerDocument' of undefined
    at r.fn.init.t.fn.scrollParent (https://xemware.com/jquery.fancytree-all-deps.min.js:16:14255)
    at treeInit (https://xemware.com/jquery.fancytree-all-deps.min.js:29:3669)
    at t.treeInit (https://xemware.com/jquery.fancytree-all-deps.min.js:19:803)
    at t._callHook (https://xemware.com/jquery.fancytree-all-deps.min.js:19:23214)
    at t.(anonymous function).(anonymous function)._init (https://xemware.com/jquery.fancytree-all-deps.min.js:20:17302)
    at t.(anonymous function).(anonymous function)._init (https://xemware.com/jquery.fancytree-all-deps.min.js:16:1111)
    at t.(anonymous function).(anonymous function)._createWidget (https://xemware.com/jquery.fancytree-all-deps.min.js:16:3398)
    at new t.(anonymous function).(anonymous function) (https://xemware.com/jquery.fancytree-all-deps.min.js:16:675)
    at HTMLDivElement.<anonymous> (https://xemware.com/jquery.fancytree-all-deps.min.js:16:2489)
    at Function.each (https://code.jquery.com/jquery-3.2.1.min.js:2:2715)
@TimNZ TimNZ changed the title Init error if no nodes Init error if no source nodes and using extension dnd5 Aug 17, 2017
@TimNZ
Copy link
Author

TimNZ commented Aug 17, 2017

It seems there is no way to drag nodes from one tree and drop onto another tree that has no nodes anyway (I did a quick hack in dnd5 treeInit).

Am always returning true in dragEnter() handler.

@TimNZ
Copy link
Author

TimNZ commented Aug 17, 2017

For context, I am replicating the Chrome bookmark manager, and a folder could have no items in it.
So if someone tries to drag a folder item (left side tree) into an empty tree (right side tree) there is no existing nodes as drop targets and no dnd is allowed.

@mar10
Copy link
Owner

mar10 commented Aug 18, 2017

Thanks, the exception is a bug.

It seems there is no way to drag nodes from one tree and drop onto another tree that has no nodes anyway

Currently true. For this, the container area could accept drop events and delegate them to the invisible root node.
If you open am issue for this feature request,I can look into it some time. I can't promise a fast solution though.

@TimNZ
Copy link
Author

TimNZ commented Aug 18, 2017

Thanks.

I'm going to have a stab at fixing a few things tomorrow, there are some other errors as well.

Was thinking about having the container accept drop events today, and will implement as suggested.

Need the thing working asap and it's either fix this or implement my own in React, and I like a lot of the other features you've built.

Will do a PR next week.

@TimNZ
Copy link
Author

TimNZ commented Aug 18, 2017

@mar10 Making good progress on this.

Initially just getting to work reliably in handling drag enter/over/drop on any empty space, defaulting to display marker at top, controlled by a dnd5.allowDropOnNonNode option (feel free to rename).

Once it's solid, I'll logic to place marker before top node or after last node depending on pointer entering from top or bottom.

I'm only modifying dnd5 as that's my immediate need, I will leave you to roll out changes to dnd to keep in sync.

@TimNZ
Copy link
Author

TimNZ commented Aug 18, 2017

fancytree-dnd

@mar10
Copy link
Owner

mar10 commented Aug 19, 2017

That's great news.

Once it's solid, I'll logic to place marker before top node or after last node depending on pointer entering from top or bottom.

Maybe this is not even required, since above would mean that we already had a node there at the top, that then would already handle the drag events?
So any drop on the free container space would be at the top if the the container was empty or below the last top-level node otherwise?

mar10 added a commit that referenced this issue Aug 19, 2017
@mar10
Copy link
Owner

mar10 commented Aug 19, 2017

I am closing this bug issue since it should be fixed now - would you open a new one for the feature request?

@mar10 mar10 closed this as completed Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants