javascript - Use both "d3.event.preventDefault" and "d3.event.which" -
this code works perfect - except in internet explorer 11. deletenode(d) calls if "mousedown" handler commented out.
circle.enter().append("circle") .on("contextmenu", function (d) { deletenode(d) }) .on("mousedown", function (d) { setnode(d); }); that's why try catch right click mousedown, context menu still appears.
circle.enter().append("circle") .on("mousedown", function (d) { d3.event.preventdefault(); if (d3.event.which == 3) { deletenode(d); } setnode(d); }); how fix not showing context menu or catching both "contextmenu" , "mousedown" events?
you close own solution problem. needed there, need rearrange bit:
circle.enter().append("circle") .on("contextmenu", function(d) { d3.event.preventdefault(); }) .on("mousedown", function (d) { if (d3.event.which == 3) { deletenode(d); // <-- d needs replaced } else { setnode(d); // <-- d needs replaced } }); this works me in ie11 in ff , chrome.
as aside, please note d refers datum bound node, not node itself. within event listener this refer current node.
var svg = d3.select("svg"); svg.append("circle") .attr({ "cx": 100, "cy": 100, "r": 100 }) .on("contextmenu", function(e) { d3.event.preventdefault(); }) .on("mousedown", function (e) { if (d3.event.which == 3) { //console.log("deletenode(d)"); } else { //console.log("setnode(d)"); } }); <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script> <svg width="400" height="400"> </svg>
Comments
Post a Comment