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

Add ability to specify where the menu is appended #6

Merged

Conversation

schinazi
Copy link
Contributor

@schinazi schinazi commented Nov 1, 2016

Currently the context menu DOM element (#cy-context-menus-cxt-menu) is
appended to the document's body element.

When the menu is positioned at the time of the user's click, the "left"
and "right" positions are calculated based on the rendered graph's
container's location plus the cilck position within the graph.

If the graph was rendered in a container which was moved away from the
normal flow position in the body (such as for the purpose of containing
it in a "slide- in" animation), then the calculated position for the
context menu might not be correct based on the current positioning of
elements in the browser.

To accommodate this, add an option that allows for supplying a CSS
selector that the #cy-context-menus-cxt-menu element should be appended
to instead of the body.

Currently the context menu DOM element (#cy-context-menus-cxt-menu) is
appended to the document's body element.

When the menu is positioned at the time of the user's click, the "left"
and "right" positions are calculated based on the rendered graph's
container's location plus the cilck position within the graph.

If the graph was rendered in a container which was moved away from the
normal flow position in the body (such as for the purpose of containing
it in a "slide- in" animation), then the calculated position for the
context menu might not be correct based on the current positioning of
elements in the browser.

To accommodate this, add an option that allows for supplying a CSS
selector that the #cy-context-menus-cxt-menu element should be appended
to instead of the body.
@metincansiper
Copy link
Collaborator

@schinazi I think that you are right. How about using '.offsetParent()' (http://api.jquery.com/offsetparent/) instead of having 'componentParentSelector' option?

As an alternative to appending the context menu’s element to a different parent
than the body, instead change the way its position is calculated, by using as the
origin the graph’s container’s position relative to the document (which is what is
returned by the $.offset() function).
@schinazi
Copy link
Contributor Author

@metincansiper Thanks for the suggestion. I tried out simplifying it by just replacing where you were using $(cy.container()).position() and instead using $(cy.container()).offset(), which gives the container's position relative to the document (http://api.jquery.com/offset/).

This works for my use case, and it looks like it works in demo.html as well.

If you think this works, I can squash the commits in this branch if you like.

Thanks,
Brian

@metincansiper metincansiper merged commit 86a65c8 into iVis-at-Bilkent:master Dec 5, 2016
@metincansiper
Copy link
Collaborator

@schinazi Thanks. I merged this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants