diff --git a/documentation/demo/async-create.md b/documentation/demo/async-create.md index 3376fc15..050edde6 100644 --- a/documentation/demo/async-create.md +++ b/documentation/demo/async-create.md @@ -13,50 +13,80 @@ currentMenu: async-create +Sometimes the menu items are not known up front, for example because they have to be +fetched from the server first. This demo registers the menu with `trigger: 'none'` and +opens it by hand once the items have arrived. The `setTimeout` below stands in for that +server round trip, so the menu appears about a second after you right click. + +Two things are worth pointing out: + +* The `contextmenu` event is handled directly on the trigger and `preventDefault()` is + called on it, otherwise the browser shows its own context menu while you are still + waiting for the items. +* `$.fn.contextMenu()` opens the menu by triggering a `contextmenu` event on the element, + which runs the very same handler again. The `asyncMenuBusy` flag below makes that + re-entrant call a no-op, and it doubles as a guard against firing a second request while + one is still in flight. + right click me ## Example code