diff --git a/README.md b/README.md index e5a7dfd..3e2c305 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Option | Description `visible` | Show/hide item (result must be boolean). `action` | Item method, mandatory if not url defined. `disabled` | Disable menu item. +`submenu` | Sub menu items. Example: @@ -58,6 +59,12 @@ Example: "visible": someMethod() == '1', "action": $root.someAction }, + "Sub menu": { + submenu: { + "Sub Option one": function() { alert("submenu,oh, you clicked me"); }, + "Sub Option two": { action: function() { alert("submenu,you are on fire"); } } + } + }, "One method": $root.test } ``` diff --git a/render/index.html b/render/index.html index e363ca1..9a914a3 100644 --- a/render/index.html +++ b/render/index.html @@ -11,9 +11,16 @@ var menu = { 'Option one': function() { alert('oh, you clicked me'); }, 'Option two': { action: function() { alert('you are on fire'); } }, + 'Option 3': { action: function() { alert('you are on fire'); } }, 'a separator': { separator: true }, + 'Sub menu': { submenu: { + 'Sub Option one': function() { alert('submenu,oh, you clicked me'); }, + 'Sub Option two': { action: function() { alert('submenu,you are on fire'); } } + } }, 'Some boolean': ko.observable(true), - 'Option three': { text: 'Final action', action: function() { /* nothing to do */ } } + '2ed separator': { separator: true }, + 'Option 4': { action: function() { alert('you are on fire'); } }, + 'Option three': { text: 'Final action', action: function() { /* nothing to do */ } }, }; ko.applyBindings({}); diff --git a/src/knockout.contextmenu.js b/src/knockout.contextmenu.js index 38aa8c0..fafdc92 100644 --- a/src/knockout.contextmenu.js +++ b/src/knockout.contextmenu.js @@ -154,12 +154,15 @@ function bindContextMenu(ko) { ); props.forEach(function (eventNameOutsideClosure) { - pushItem(eventNameOutsideClosure); + pushItem(eventNameOutsideClosure, eventsToHandle, elements, items, actions); }); if (elements.length) { menu = document.createElement('div'); menu.className = defaultClass; + items.forEach(function (item) { + hasChecks = hasChecks || (item.isBoolean && item.isVisible); + }); // you may need padding to menus that has checks menu.innerHTML = '