Does Raphael support having right click menu?? I'm looking into how to best visualise a UML like diagram, but also have the ability for the user to hover over one fo the items and say "create relationship" or "create new node" (so a right click menu would be good). I'm trying to understand if Raphael would help me out.
my question Similar to the above.
i hava javascript support right click menu about svg demo.
svgmenu.js file:
var CurveControl = null;
var SvgMainMapDoc = null;
function winLoad(){
CurveControl = document.getElementById('NavigateControl');
if(CurveControl==null)
return;
SvgMainMapDoc = CurveControl.getSVGDocument();
faireMenus("menu1");
}
function faireMenus(udefMenuID){//== udefMenuID:svg预定义的菜单编码
var udef_menu = udefMenuID;
var mydoc = SvgMainMapDoc;
var contextMenu = CurveControl.window.contextMenu;
var menuXml = CurveControl.window.printNode(mydoc.getElementById(udef_menu));
//alert(menuXml);
CurveControl.window.Titi = Titi;
CurveControl.window.printit = printit;
CurveControl.window.colorit = colorit;
CurveControl.window.showmsg = showmsg;
changeMenus(menuXml);
}
function changeMenus(menuXml){//== xml格式的菜单字符串
var contextMenu = CurveControl.window.contextMenu;
var newMenuRoot = CurveControl.window.parseXML(menuXml, contextMenu);
contextMenu.replaceChild(newMenuRoot, contextMenu.firstChild);
}
function Titi()
{
var msg = "test";
alert(msg);
}
function printit(){
if (confirm('确定打印吗?')){
try {
if(parent) parent.print();
}
catch(e){}
}
}
function colorit(clr){ //背景色函数
var myob = SvgMainMapDoc.getElementById("rect_back");
if(myob) myob.setAttribute("fill", clr);
}
function showmsg(msg){
alert(msg);
}
svgmenu.svg file:
<?xml version="1.0" encoding="utf-8" ?>
<svg id="cont" viewBox="0 0 450 320" width="450" height="320"
xm开发者_开发问答lns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
xml:space="preserve" preserveAspectRatio="none">
<defs>
<menu id='menu1'>
<header>Menu utilisateur</header>
<item action="CopySVG" id="CopySVG">复制图形</item>
<separator/>
<menu>
<header>背景颜色</header>
<item onactivate="colorit('white')">白色</item>
<item onactivate="colorit('black')">黑色</item>
<item onactivate="colorit('#D0D063')">黄色</item>
<item onactivate="colorit('green')">绿色</item>
<separator/>
<item onactivate="colorit('#008083')">默认</item>
</menu>
<separator/>
<item action="Pause" id="Pause">暂停</item>
<separator/>
<item id='Menu1.2' onactivate='printit(this)'>打印</item>
<separator/>
<item id='Menu1.1' onactivate='Titi()'>操作说明</item>
</menu>
<menu id='menu2'>
<item id='Menu1.2' onactivate="showmsg('控件ID')">控件ID</item>
</menu>
</defs>
<g id="elements">
<rect id="rect_back" class="Gas" x="0" y="0" width ="450" height="320" fill="#ffff33">
</rect>
<rect id="gas_1" class="Gas" x="0" y="0" width ="145" height="145" fill="#00ff33" onmouseover="faireMenus('menu2')" onmouseout="faireMenus('menu1')">
</rect>
</g>
</svg>
svgmenu.html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script language="JavaScript" src="svgmenu.js"></script>
</head>
<body onload="winLoad()">
<embed id="NavigateControl" width="100%" height="100%" src="svgmenu.svg" type="image/svg+xml" >
</body>
</html>
but.... i want to use RaphaelJs to create svg gragh.
some raphael(reference:http://raphaeljs.com/reference.html) code:
var c = R.circle(100, 100, 50).attr({
fill: "hsb(.8, 1, 1)",
stroke: "none",
opacity: .5
});
var start = function () {
// storing original coordinates
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.attr({opacity: 1});
},
move = function (dx, dy) {
// move will be called with dx and dy
this.attr({cx: this.ox + dx, cy: this.oy + dy});
},
up = function () {
// restoring state
this.attr({opacity: .5});
};
c.drag(move, start, up);
now... i hava raphaelJs move function. i hava javascript right menu Redefinition function. i want Combining these two functions. how can i do? if you hava any idea. leave your answer. Thank you very much. by the way: if the source code has some wrong also can be pointed out that
$(c.node).bind("contextmenu", function(){
alert(0);
});
Please try the code above, $ == jQuery.
This is how you could add a context menu to an svg element using DOJO. It will appear on right click.
var contextMenu = new dijit.Menu();
contextMenu.addChild(
new dijit.MenuItem( {
label:"Menu item",
onClick:function(e){ log.debug("Clicked"); }
}));
contextMenu.bindDomNode(raphaelElement[0] );
RaphaelElement is a your raphael element, like a circle or ellipse.
精彩评论