I'm trying to get a click event to go off manual for a plug-in that uses a selector.
plug-in set up.
$( function ()
{
$.contextMenu( {
selector: '.context-menu-one',
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" },
"paste": { name: "Paste", icon: "paste" },
"delete": { name: "Delete", icon: "delete" },
"sep1": "---------",
"quit": { name: "Quit", icon: "quit" }
}
} );
$( '.context-menu-one' ).on( 'click', function ( e )
{
alert( 'clicked', this );
} )
} );
I tried two ways to fire but I'm not able to make it work.
$( '.context-menu-one' ).trigger( 'click' );
or
$( '.context-menu-one' ).click();
Is there a special way to fire on a selector. I figured this was explained somewhere but my searching has reached its end.
--------- update adding more of the surrounding code -----------
//local functions
$( function ()
{//override right click.
$( this ).bind( "contextmenu", function ( e )
{
alert( 1 );// users right clicked
var overRide = true;
//set up the right click menu
$( function ()
{
$.contextMenu( {
selector: '.context-menu-one',
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" },
"paste": { name: "Paste", icon: "paste" },
"delete": { name: "Delete", icon: "delete" },
"sep1": "---------",
"quit": { name: "Quit", icon: "quit" }
}
} );
$( '.context-menu-one' ).on( 'click', function ( e )
{
alert( 'clicked', this );
} )
} );
//bring up the menu
$( '.context-menu-one' ).trigger( {
type: 'mousedown',
which: 1
} );
if (overRide) e.preventDefault();
} );
} );
My intent here is simply to trigger a right click so that the menu comes up manually not based on an event.