iVis-at-Bilkent / cytoscape.js-context-menus

A Cytoscape.js extension to provide context menu around elements and core instance
MIT License
87 stars 41 forks source link

Add ability to specify where the menu is appended #6

Closed schinazi closed 7 years ago

schinazi commented 8 years ago

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 commented 7 years ago

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

schinazi commented 7 years ago

@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 commented 7 years ago

@schinazi Thanks. I merged this PR.