sydcanem / bootstrap-contextmenu

Context menu plugin for Twitter's Bootstrap framework
http://sydcanem.com/bootstrap-contextmenu/
645 stars 193 forks source link

Left-click? #24

Closed unclemopp closed 10 years ago

unclemopp commented 11 years ago

I'm loving this context menu, but I can't figure out how to trigger it on a left mouse click. I figure someone has probably asked for/developed a solution for this, but I am unable to see it in the documentation/examples. Have I missed something?

sydcanem commented 11 years ago

hi, I'm glad you find this plugin useful. Currently, the context menu is triggered by the browser 'contextmenu' event. Right now I don't have any idea on how to make it open on left clicks. If you find a solution please feel free to share it. Thanks. On May 18, 2013 4:57 PM, "unclemopp" notifications@github.com wrote:

I'm loving this context menu, but I can't figure out how to trigger it on a left mouse click. I figure someone has probably asked for/developed a solution for this, but I am unable to see it in the documentation/examples. Have I missed something?

— Reply to this email directly or view it on GitHubhttps://github.com/sydcanem/bootstrap-contextmenu/issues/24 .

Sayayin commented 11 years ago

Hi, i was working on this last week and solve this adding "click.context.data-api" to the $elements events list:

93 : .on('click.context.data-api contextmenu.context.data-api', $.proxy(this.show, this));

and

190: .on('click.context.data-api contextmenu.context.data-api', '[data-toggle=context]', function(e) {

this two changes work fine to me

mauvm commented 11 years ago

This piece of code worked for me:

$( ... )
    .on( 'click', function( e ) {
        e.stopPropagation();
        $(this).contextmenu( 'show', e );
    } )
    .contextmenu( { ... } );

Note the e.stopPropagation() which is key here, because it stops line 95 from triggering:

$('html').on('click.context.data-api', $.proxy(this.closemenu, this));

@sydcanem Adding if (e.type==='click') e.stopPropagation(); to line ~65 would make the manual e.stopPropagation() unnecessary. I'd recommend adding the left-click trigger snippet to the readme.md (because .contextmenu( 'show', e ); also requires the original event to be passed along). Thanks for the great plugin though, keep it up!

tarim commented 10 years ago

Hi Sayayin,

I did same as you did. And, it open context menu, but, It couldn't pick up table tr data value. Do you have any idea?

Thanks,

markudevelop commented 9 years ago

@mauvm awesome. seems to work. I have already noticed I had to use e.stopPropagation() before. Atleast it works :)