title: different custom contentmenu in different nodes in d3
body: <p>On right clicking the node title is not returning the return value but the complete function as a title. I want only to show the what i pass in return. I am not able to understand how to solve this. Can any1 help me on this. The answer was not working as the function with parameter d was not referring to node. It giving the error as commented below the answer.</p>
  
  <pre><code>var content = [
              {
                  title: function(d) {
               if(d.url) {
              return 'Item 1';
  }
                  },
                  action: function(elm, d, i) {
                      window.open(d.url, '_blank');
                  }
              },
              {
                  title: function(d) {
              if(d.url1) {
              return 'Item 2';
  }
                  },
                  action: function(elm, d, i) {
                          if(d.url1){
                      window.open(d.url1, '_blank');
                          }
                  }
              },
              {
                  title: function(d) {
              if(d.url2) {
              return 'Item 3';
  }
                  },
                  action: function(elm, d, i) {
                      window.open(d.url2, '_blank');
                  }
              }
          ];
  function collapse(d) {
      if (d.children) {
        d._children = d.children;
        d._children.forEach(collapse);
        d.children = null;
      }
    }
   collapse(root);
    update(root);
  
  d3.select(self.frameElement).style("height", "800px");
  
  function update(source) {
  
    // Compute the new tree layout.
    var nodes = tree.nodes(root).reverse(),
        links = tree.links(nodes);
  
    // Normalize for fixed-depth.
    nodes.forEach(function(d) { d.y = d.depth * 180; });
  text = source;
    // Update the nodes…
    var node = svg.selectAll("g.node")
        .data(nodes, function(d) { return d.id || (d.id = ++i); });
  
    // Enter any new nodes at the parent's previous position.
     var nodeEnter = node.enter().append("g")
        .attr("class", "node")
        .attr("transform", function(d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
        .on('contextmenu', d3.contextMenu(content))
        .on("click", click);
  
    nodeEnter.append("circle")
        .attr("r", 1e-6)
        .style("fill", function(d) { return d._children ? (d.status ? d.status : "#f77a03") : "#fff";
      });//changed
  
    nodeEnter.append("text")
        .attr("x", function(d) { return d.children || d._children ? -10 : 10; })
        .attr("dy", function(d) { return d.children || d._children ? -10 : 10; })
        .style('fill',function(d) { return d.status ? d.status : "white"; })//added
        .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; })
        .text(function(d) { return d.name; })
        .style("fill-opacity", 1e-6);
  
      nodeEnter.append("image")
          .attr("xlink:href", function(d) { img = filter_click(r);return eval(img);})
        .attr("x", "-9px")
        .attr("y", "-20px")
        .attr("width", "20px")
        .attr("height", "40px");
    // Transition nodes to their new position.
    var nodeUpdate = node.transition()
        .duration(duration)
        .attr("transform", function(d) { return "translate(" + d.y + "," + d.x + ")"; });
  
    nodeUpdate.select("circle")
        .attr("r", 4.5)
        .style("fill", function(d) { return d._children ? (d.status ? d.status : "#f77a03") : "#fff"; });//changed
  
    nodeUpdate.select("text")
        .style('fill',function(d) { return d.status ? d.status : "black"; })//added
        .style("fill-opacity", 1);
  
    // Transition exiting nodes to the parent's new position.
    var nodeExit = node.exit().transition()
        .duration(duration)
        .attr("transform", function(d) { return "translate(" + source.y + "," + source.x + ")"; })
        .remove();
  
    nodeExit.select("circle")
        .attr("r", 1e-6);
  
    nodeExit.select("text")
        .style("fill-opacity", 1e-6);
  
    // Update the links…
    var link = svg.selectAll("path.link")
        .data(links, function(d) { return d.target.id; });
  
    // Enter any new links at the parent's previous position.
    link.enter().insert("path", "g")
        .attr("class", "link")
        .attr("d", function(d) {
          var o = {x: source.x0, y: source.y0};
          return diagonal({source: o, target: o});
        });
  
    // Transition links to their new position.
    link.transition()
        .duration(duration)
        .attr("d", diagonal);
  
    // Transition exiting nodes to the parent's new position.
    link.exit().transition()
        .duration(duration)
        .attr("d", function(d) {
          var o = {x: source.x, y: source.y};
          return diagonal({source: o, target: o});
        })
        .remove();
  
    // Stash the old positions for transition.
    nodes.forEach(function(d) {
      d.x0 = d.x;
      d.y0 = d.y;
    });
  }
  </code></pre>
  
  <p>Here is a <a href="http://plnkr.co/edit/o4AZIKf5auRiZfOC2Bo3?p=preview" rel="nofollow">plunker</a>, which is showing exactly what I am facing and here is the <a href="http://plnkr.co/edit/cZ56PW5MyHLGyMrhzbUs?p=preview" rel="nofollow">plunker</a> in which script.js has the code which is working what I want my script to work.</p>
  
  <p>I am trying to make a custom contentmenu which can be done if I am able to solve the problem described above. Any Help will be appreciated.</p>