swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.25k stars 744 forks source link

html5 & callback is not actually working #564 #757

Open daveherman71 opened 2 years ago

daveherman71 commented 2 years ago

To preserve legacy compatibility when building the menu from a HTML5 menu element I propose that you check for the existence of the onclick property on the button, menuitem or command tag and if one does not exist then call the root callback function as a fallback:

    callback: (function () {
        return function () {
            $node.get(0).click();
        };
    })()

Therefore becomes:

    callback: (function () {
        return function (itemKey, opt, ev) {
            if ($node.get(0).onclick !== null) {
                $node.get(0).click();
            } else {
                opt.callback(itemKey, opt, ev);
            }
        };
    })()

I have no need for legacy compatibility in my app but this works well for me especially when building large menus using the suckerfish methodology.