Coder Social home page Coder Social logo

Comments (14)

rodneyrehm avatar rodneyrehm commented on May 24, 2024

I'm not sure I understand what you are trying to achieve here. Do you want to prevent the menu from being triggered by mouse, so it can only be shown through your AJAX response handler? If so, why are you adding that mouseup handler?

from jquery-contextmenu.

jpimag avatar jpimag commented on May 24, 2024

Sorry if didn't explain correctly my problem.

My mouseup handler look likes this:


$(selector).bind('mouseup', function(e) {
    if (e.button == 2) {
        // An asynchronous AJAX call wich will execute '$(selector).contextmenu();' in the response.
    }
}

This code doesn't work if I don't perform the fix describes in my first post.

To understant why, I tried to simplify my handler like this :


$(selector).bind('mouseup', function(e) {
    if (e.button == 2) {
        $(selector).contextmenu();
    }
}

With this handler, the contextmenu is shown. But, the trigger take into account by the plugin is the standard right click trigger even if I have set ignoreRightClick=true option.
Indeed, the contextmenu code ignore my custom trigger because it is the first to call the event contextmenu and so the first to reach the test fixed in my first post (jquery.contextmenu.js line 190).

from jquery-contextmenu.

rodneyrehm avatar rodneyrehm commented on May 24, 2024

I still don't understand your problem. Setting the trigger to 'right' (which is default) and setting ignoreRightClick to true will prevent the contextMenu to ever be shown by a mouse click.

Here's a little demo - just pretend the setTimeout() would be some asynchronous ajax call.

from jquery-contextmenu.

jpimag avatar jpimag commented on May 24, 2024

I can't reproduce my AJAX problem using window.setTimeout(). I don't find why.

Nevertheless, I isolated what I suspect to be the problem in this demo http://jsfiddle.net/jpimag/CKw86/
In this demo, right or left click should trigger the menu at the top left.

It is not the case : right click trigger the menu on the mouse pointer.
This behavior shows that ignoreRightClick property ignore my custom trigger instead of ignoring default right click trigger.

Note : I don't find exactly why my AJAX code is different of a window.setTimeout() but fixing this demo fix also my AJAX code.

from jquery-contextmenu.

bganov avatar bganov commented on May 24, 2024

@jpimag - Your JSFiddle allows context menu on left click too ;-)

from jquery-contextmenu.

jpimag avatar jpimag commented on May 24, 2024

@bganov Yes, it was to illustrate that both click should have the same behavior.(open the menu on the left corner)

from jquery-contextmenu.

rodneyrehm avatar rodneyrehm commented on May 24, 2024

Awesome. For the future: If you're experiencing any kind of weird behavior with a fucked up browser like Internet Explorer, please state that in your bug report.

I can reproduce your problem (only) with Internet Explorer. And I believe I know why. For some reason the window.event of your mousup handler bleeds through .trigger() to the internal contextmenu handler.

Wrapping the contextMenu call in setTimeout() leads to the window.event being null.

I have yet to identify the source of this leak. But since contextMenu doesn't know of window.event, I'm guessing we hit a bug in jQuery (or at least an unexpected behavior).

For the time being wrap your call in a setTimeout() to prevent window.event of bleeding through: http://jsfiddle.net/rodneyrehm/CKw86/40/

from jquery-contextmenu.

jpimag avatar jpimag commented on May 24, 2024

I experienced the problem on Firefox 12, Chrome and IE 8 (windows XP). I will try your workaround. I keep you in touch.

from jquery-contextmenu.

rodneyrehm avatar rodneyrehm commented on May 24, 2024

Your demo works fine in my Firefox, Chrome, Safari. It fails in Internet Explorer and Opera 11.62.
As Opera doesn't know about window.event I'm back to square one. I'll keep investigating.

from jquery-contextmenu.

rodneyrehm avatar rodneyrehm commented on May 24, 2024

Wow, what a ride… as it turns out, the order of contextmenu events is different (and causing this problem). This fiddle shows that Firefox, Safari, Chrome run the sequence [mouse, manually], while Opera and Internet Explorer run the sequence [manually, mouse].

I'm not sure how I'm going to tackle this… but at least I now know what's going on.

from jquery-contextmenu.

jpimag avatar jpimag commented on May 24, 2024

Finally, I tried another way to trigger my menu.
I don't use ignoreRightClick parameter anymore. I simply intercept 'contextmenu' event before menucontext plugin.


$(document).on('contextmenu', selector, function(e) {
// interception of all classic contextmenu event
// Only custom contextmenu event are propagated to contextmenu plugin.
if (e.which != 'custom') {
// Open menu
e.preventDefault();
e.stopImmediatePropagation();
// An ajax request with $(selector).trigger(jQuery.Event('contextmenu', { which: 'custom', pageX: e.pageX, pageY: e.pageY})); in the response
}
});

It works fine on IE 7,8, Firefox 12, Chrome and Safari
Tell me if I you want I close the issue

Thanks for your time

from jquery-contextmenu.

rodneyrehm avatar rodneyrehm commented on May 24, 2024

Are you sure that event.which is the thing to roll with? Your solution is another workaround.

I think I know how to solve the problem within contextMenu. I'll look into it in the next couple of days.

You are free to close the issue, if you believe your workaround fixes things for you.

from jquery-contextmenu.

rodneyrehm avatar rodneyrehm commented on May 24, 2024

"next couple of days" came early.

I just released contextMenu 1.5.13, which should fix your problem. Note that the ignoreRightClick option was dropped as it didn't do anything anymore.

from jquery-contextmenu.

jpimag avatar jpimag commented on May 24, 2024

I've just tested new version with success, thanks

from jquery-contextmenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.