Skip to content

Instantly share code, notes, and snippets.

@maasha
Created May 13, 2016 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maasha/3730979cb6e5cbf2b86f7bb72b859ca1 to your computer and use it in GitHub Desktop.
Save maasha/3730979cb6e5cbf2b86f7bb72b859ca1 to your computer and use it in GitHub Desktop.
/**
* 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