Demo: Asynchronous
Example code: Asynchronous
$(function(){
// some build handler to call asynchronously
function createSomeMenu() {
return {
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"edit": {name: "Edit", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"copy": {name: "Copy", icon: "copy"}
}
};
}
// some asynchronous click handler
$('.context-menu-one').on('mouseup', function(e){
var $this = $(this);
// store a callback on the trigger
$this.data('runCallbackThingie', createSomeMenu);
var _offset = $this.offset(),
position = {
x: _offset.left + 10,
y: _offset.top + 10
}
// open the contextMenu asynchronously
setTimeout(function(){ $this.contextMenu(position); }, 1000);
});
// setup context menu
$.contextMenu({
selector: '.context-menu-one',
trigger: 'none',
build: function($trigger, e) {
// pull a callback from the trigger
return $trigger.data('runCallbackThingie')();
}
});
});
Example HTML: Asynchronous
<div class="context-menu-one box menu-1">
<strong>right click me</strong>
</div>
jQuery Context Menu Demo Gallery