Skip to content

Option to customize right click event #67

@zoulayabd

Description

@zoulayabd

Thanks for your help earlier!

we need to open context menu of edges by left click event , and we would like to have an option evtType to customise cxttap event

cy.on('cxttap', eCxtTap = function (event) {
var target = event.target || event.cyTarget;
var targetIsEdge = false;
try{
targetIsEdge = target.isEdge();
}
catch(err){
// this is here just to suppress the error
}
var edge, type;
if(targetIsEdge){
edge = target;
type = anchorPointUtilities.getEdgeType(edge);
}
else{
edge = anchorManager.edge;
type = anchorManager.edgeType;
}
var menus = cy.contextMenus('get'); // get context menus instance
if(!edgeToHighlight || edgeToHighlight.id() != edge.id() || anchorPointUtilities.isIgnoredEdge(edge) ||
edgeToHighlight !== edge) {
menus.hideMenuItem(removeBendPointCxtMenuId);
menus.hideMenuItem(addBendPointCxtMenuId);
menus.hideMenuItem(removeControlPointCxtMenuId);
menus.hideMenuItem(addControlPointCxtMenuId);
return;
}
var cyPos = event.position || event.cyPosition;
var selectedIndex = getContainingShapeIndex(cyPos.x, cyPos.y, edge);
// not clicked on an anchor
if (selectedIndex == -1) {
menus.hideMenuItem(removeBendPointCxtMenuId);
menus.hideMenuItem(removeControlPointCxtMenuId);
if(type === 'control' && targetIsEdge){
menus.showMenuItem(addControlPointCxtMenuId);
menus.hideMenuItem(addBendPointCxtMenuId);
}
else if(type === 'bend' && targetIsEdge){
menus.showMenuItem(addBendPointCxtMenuId);
menus.hideMenuItem(addControlPointCxtMenuId);
}
else if (targetIsEdge){
menus.showMenuItem(addBendPointCxtMenuId);
menus.showMenuItem(addControlPointCxtMenuId);
}
else {
menus.hideMenuItem(addBendPointCxtMenuId);
menus.hideMenuItem(addControlPointCxtMenuId);
}
anchorPointUtilities.currentCtxPos = cyPos;
}
// clicked on an anchor
else {
menus.hideMenuItem(addBendPointCxtMenuId);
menus.hideMenuItem(addControlPointCxtMenuId);
if(type === 'control'){
menus.showMenuItem(removeControlPointCxtMenuId);
menus.hideMenuItem(removeBendPointCxtMenuId);
if (opts.enableMultipleAnchorRemovalOption &&
edge.hasClass('edgecontrolediting-hasmultiplecontrolpoints')) {
menus.showMenuItem(removeAllControlPointCtxMenuId);
}
}
else if(type === 'bend'){
menus.showMenuItem(removeBendPointCxtMenuId);
menus.hideMenuItem(removeControlPointCxtMenuId);
}
else{
menus.hideMenuItem(removeBendPointCxtMenuId);
menus.hideMenuItem(removeControlPointCxtMenuId);
menus.hideMenuItem(removeAllControlPointCtxMenuId);
}
anchorPointUtilities.currentAnchorIndex = selectedIndex;
}
anchorPointUtilities.currentCtxEdge = edge;
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions