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)
Registers a menu item. With the option.targetTemplate you can specify where to put the menu item and it will show up by default at the bottom of the menu. Without that option, it will be added to the plugin menu and can be moved in the editor.
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
- (removed) 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
jancyMade
- used internally to hide it from the plugin menuinsertBefore
- specify the id of the menu item you would like to insert this menu item before. Makes it so that users can have their menu item show up without having to edit the menu manually after the menu item is createdcanMove
- allows the menu item to be moved in the editorcanDelete
- allows the menu item to be deleted in the editorhasIcons
- allows the showing of icons on the menu editor (no add button, delete button, drag, or collapse icons)
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', 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', editorLabel:'Hi I am a test menu > item'} } )