Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Add context menus.
*/
function addContextMenus () {
$(document).contextmenu({
delegate: '.hasmenu',
autoFocus: true, // keyboard navigation
taphold: true, // mobile devices
preventSelect: true, // prevent text selcting of menu text
preventContextMenuForPopup: true, // prevent browsers context menu
menu: [
{title: 'Edit', cmd: 'nodeEdit', uiIcon: 'ui-icon-pencil'},
{title: 'Delete', cmd: 'nodeDelete', uiIcon: 'ui-icon-trash'},
{title: '----'},
{title: 'Unfold', uiIcon: 'ui-icon-folder-open', children: [
{title: 'This node', cmd: 'nodeUnfold'},
{title: 'Sub-nodes', cmd: 'nodeUnfoldAll'}
]},
{title: 'Fold', uiIcon: 'ui-icon-folder-collapsed', children: [
{title: 'This node', cmd: 'nodeFold'},
{title: 'Sub-nodes', cmd: 'nodeFoldAll'}
]},
{title: 'Pivot', uiIcon: 'ui-icon-arrowreturnthick-1-e', children: [
{title: 'This node', cmd: 'nodePivot'},
{title: 'Sub-nodes', cmd: 'nodePivotAll', disabled: true}
]},
{title: 'Unpivot', uiIcon: 'ui-icon-arrowreturnthick-1-s', disabled: true, children: [
{title: 'This node', cmd: 'nodeUnPivot'},
{title: 'Sub-nodes', cmd: 'nodeUnPivotAll'}
]}
],
select: function (event, ui) {
switch (ui.cmd) {
case 'nodeEdit':
nodeEdit(ui)
break
case 'nodeDelete':
nodeDelete(ui)
break
case 'nodeUnfold':
nodeUnfold(ui)
break
case 'nodeUnfoldAll':
nodeUnfoldAll(ui)
break
case 'nodeFold':
nodeFold(ui)
break
case 'nodeFoldAll':
nodeFoldAll(ui)
break
case 'nodePivot':
nodePivot(ui)
break
case 'nodePivotAll':
nodePivotAll(ui)
break
case 'nodeUnPivot':
nodeUnpivot(ui)
break
case 'nodeUnPivotAll':
nodeUnpivotAll(ui)
break
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment