2

I'm binding a mouse click listener to serveral SVG elements and - on a click- trigger the open method of a kendo context menu. If the menu is already open (I listening to the activate/deactivate events to check if the menu is open), and the user clicks on the same element , it shall close.

The problem is: the context menu closes by default on mouse down. So when it is open, the user clicks on the same element it closes on mousedown and reopen on mouseup - but it shall close on click, not mousedown. Is there a way to tell this to the context menu directly or do I have to control this by the events of the SVG elements? thanks!

Lars Höppner
  • 18,252
  • 2
  • 45
  • 73
Clemens
  • 51
  • 11

1 Answers1

1

Not sure I understand what you're trying to do, but you can influence whether the menu closes when you click outside of the menu like this:

kendo.ui.ContextMenu.fn._closeHandler = function (closeHandler) {
    return function(e) {
        var clickInMenu = $.contains(this.element[0], e.target);

        if (clickInMenu) { // click outside will do nothing
            closeHandler.call(this, e);
        }   
    }
}(kendo.ui.ContextMenu.fn._closeHandler);

var contextMenu  =$("#context-menu").kendoContextMenu({
    target: "#target"
});

(demo)

Lars Höppner
  • 18,252
  • 2
  • 45
  • 73
  • thanks! I will try to implement this in my code. You're right: I wanna control the closure behaviour of the menu when clicking somewhere outside. Because: If u don't define the "target" property but call the open() and close() method directly when listening to a click event of any element (i.e. an SVG element) and if the context menu is already open. it will close on mousedown and open again if you're clicking on the same button (instead of only closing). May be this will not happen if you define the button element as a arget of the menu. – Clemens Mar 11 '15 at 07:51
  • you could also filter the click on the button in the close handler if it is triggered; calling open again wouldn't be an issue since that does nothing if it's already open – Lars Höppner Mar 11 '15 at 09:17
  • This is promising. Can you also override the mouseDown event in the dropdownlist that way? – Nick Mar 27 '15 at 15:46
  • @Nick probably, but not in this question ;) – Lars Höppner Mar 28 '15 at 01:35