-
Notifications
You must be signed in to change notification settings - Fork 739
Context menu async loading sub-menu's #431
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
Conversation
…e completion build items. TODO: when already hovered over the menu item for the submenu
…e.reject is called.
…eated from a promise.
@@ -1227,7 +1234,7 @@ | |||
createNameNode(item).appendTo($t); | |||
|
|||
item.appendTo = item.$node; | |||
op.create(item, root); | |||
//op.create(item, root); decide later, might be a promise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't the logic for creating the submenu called here but evaluated later, outside the case statement?
I've started on cleanup and docs here. https://github.com/swisnl/jQuery-contextMenu/tree/Ruud-cb-master
|
@Ruud-cb Thank you! Very useful! |
Hi, I need to implement dynamic submenu items based on some properties of the content. Can I use this branch to do this ? Regards, Victor |
You could use this, but it is not finished yet, you could also use the |
To be more specific. Can I use build to construct a list of items that will be of variable size ? Maybe I need to read more the documentation, but I am not sure I can do this. Could you please point me to an example ? |
Sorry i was on mobile and getting a link was a bit hard. https://swisnl.github.io/jQuery-contextMenu/demo/dynamic-create.html |
I think this has a fixed number of subitems:
In my code, I will right click and depending on the properties I find, I will have to create an item for each of those properties. Also, that item's name will be the same as the found property. For example: If i find, dummy1, dummy2, etc. I will create:
And of course, the names will always change as well. Thanks in advance for your patience. I know you take your time and effort to give this great plugin in for other developers. Cheers, |
You could use the arguments from the build option (like $trigger) to figure out what menu items you want to show. The structure isn't set, your can return any menu you like in that function. |
@bbrala Hooray! Thank you! Can you poke me in documentation, how i can use loading icon? |
I think the docs are only updated on release. You could check demo/async-promise.md in the repository for a demo. |
Documentation/demo/async-promise.md I mean |
Hi,
Issue: #429
With this feature it is possible to load sub-menu items AFTER the context menu has been opened. By providing a Jquery promise for the "items". After the promise will be resolved or rejected the items will be shown in the context menu.
Example usage:
working plunker:
https://embed.plnkr.co/iEkk5Ohrja86xf4UKObA/
Implementation
Looking at the code changes, which is commented quite extensively anyway: It checks on create for all sub-items if
item.items
is a promise. If so it will use another functionprocessPromises
within operations to deal with this. There, it will wait for eitherpromise.resolve
orpromise.reject
. If one of these occur it will override theitems
of the current node (opt
) which will now contain actual items. Thereafter it will create the sub-menu.We also call
op.update()
to put the$node
on a correct x and y position, thereafter we can callroot.positionSubmenu()
, which will correctly position the sub-menu, only when the user already is hovering over the menu item.Two more adjustments: inside
positionSubmenu
we have to check if $menu is undefined. BecausefocusItem
calls this function anyway. This just prevents an console error.And: When appending css styles when creating the context (sub) menu, add an extra check if it already has a 'sub' type. This because we call create again with an item that already has
sub
and should not execute the last else-if.TODO: