The Menu Registry Interface
With the Menu Registry you can create menu items for the various menus.
There is only one menu registry interface and it can always be found at jancy.menuRegistry
.
Methods
menuRegistry.registerMenuItem(id, canShow, getItem, options)
id
(string
)canShow
(function
) return aboolean
for circumstances that allow the menu item to show. Returntrue
to always show it.getItem
(function
) return an object withid
,label
, andclick
properties.options
(object
)targetTemplate
- can be ‘tab’, ‘tab-button’, ‘tab-button-multi’, and ‘app’tab
- right clicking the webpagetab-button
- right clicking a tab buttontab-button-multi
- when multiple tabs are selected and the user right clicks themapp
- the menu at the top of the app
editDefault
- a boolean to determine if you want it automatically added to the default menuseditorLabel
- a string that will show in the editor proceeded byMenu Item:
e.g.Menu Item: Hi I am a test menu item
This is an example of registering a single menu item.
jancy.menuRegistry.registerMenuItem( 'tab-test-me', (jancy) => { return true }, (jancy, {tab}) => { return { id: 'test', label: 'Test ME!', click: () => console.log('test clicked'), } }, {targetTemplate:'tab', editDefault: true, editorLabel:'Hi I am a test menu > item'} )
Registering a menu item that returns a sub-menu.
const isShowing = true jancy.menuRegistry.registerMenuItem( 'tab-submenu-of-mine', (jancy) => isShowing, (jancy, {tab}) => { return { id: 'mine-submenu', label: 'Mine Sub', submenu: [ { id: 'pie', label: 'pie', click: () => console.log('chicken, you great lummox') }, { id: 'apples', label: 'apples', click: () => console.log('how bout them?') } ] }, {targetTemplate:'tab', editDefault: true, editorLabel:'Hi I am a test menu > item'} } )