Title: Intermittent error when embedded  code does not execute
Last modified: August 31, 2016

---

# Intermittent error when embedded code does not execute

 *  Resolved [pwarwick](https://wordpress.org/support/users/pwarwick/)
 * (@pwarwick)
 * [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/)
 * Sometimes when I make a change to the non-embedded code the script doesn’t work.
   I have run the script through jslint and there are no errors (except one strange
   error
    `Expected '/' and instead saw ''.` However, the exact same code executes
   on a Drupal site.
 * The code executes d3.js graphic code.
 * Here is the code:
 *     ```
       <script>
       var w = 450,
       h = 500,
       r = Math.min(w, h) / 2,
       color = d3.scale.category20c();
       function prettyAlert(p_message, p_title) {
       p_title = p_title || "";
       $(p_message).dialog({
          title: p_title,
          width:400,
          height:400,
          resizable: false,
          modal : true,
          overlay: {
            backgroundColor: "#000", opacity: 0.5
            },
          close: function(ev, ui) {
            $(this).remove();
            }
       });
       }
       hoverover=d3.select("body")
       .append("div")
       .attr("class","arcs-hoverover")
       .style("display","none")
       .style("position","absolute");
       var svg = d3.select("#chart").append("svg:svg")
       .attr("width", w)
       .attr("height", h)
       .append("svg:g")
       .attr("transform", "translate(" + w / 2 + "," + h / 2 + ")");
       var partition = d3.layout.partition()
       .sort(null)
       .size([2 * Math.PI, r * r])
       .children(function(d) { return isNaN(d.value) ? d3.entries(d.value) : null })
       .value(function(d) { return d.value });
       var arc = d3.svg.arc()
       .startAngle(function(d) { return d.x })
       .endAngle(function(d) { return d.x + d.dx })
       .innerRadius(function(d) { return Math.sqrt(d.y) })
       .outerRadius(function(d) { return Math.sqrt(d.y + d.dy) })
       ;
       d3.json("http://patriciawarwick.com/drupal/sites/default/d3_files/json/ranking.json", function(json) {
       path = svg.data(d3.entries(json)).selectAll("path")
       .data(partition.nodes)
       .enter().append("svg:path")
       .attr("d", arc)
       .attr("fill", function(d) {
            if (d.key != "Not attributed") {
               return color(d.key)
               }
            else {
               return "transparent"
               } // end else
            }) // end fill
        .style("stroke", function(d) {
            if (d.key == "Not attributed") {
               return "lightgrey";}
            }) // end stroke
       .on("click", magnify)
       .each(stash)
       .on("mouseout",function(d){
         d3.select("body")
         .select(".arcs-hoverover")
         .style("display","none");
         d3.select(this)
         .style("stroke-width","1px")
       }) // end mouseout
       .on("mousemove",function(d){
          var bodyOffsets = document.body.getBoundingClientRect();
          d3.select(this)
            .style("stroke-width","1px");
          d3.select("body")
            .select(".arcs-hoverover")
            .style("display","block")
            .style("top", (d3.event.clientY - bodyOffsets.top -300)+"px")
            .style("left",(d3.event.clientX - bodyOffsets.left -20)+"px")
            .html(function( ){
                 var units=calcUnits(d.key);
                  return d.key + "<br />" + d3.round(d.value/1000, 2)+ units
            }) // end html
         }) // end mousemove
       ; // end append g
       }); // end d3.json
       function calcUnits (type) {
       // str.indexOf("welcome")
       if ((type.indexOf("Production")!=-1) || (type.indexOf("Flaring")!=-1))   { // found
         return " GtCO2"
        }
       else {
         return " GtCO2e"
        };
       };
       function clickAlert (label) {
       };
       // Distort the specified node to 80% of its parent.
       function magnify(node) {
       if (parent = node.parent) {
       var parent,
       x = parent.x,
       k = 0.8;
       parent.children.forEach(function(sibling) {
           x += reposition(sibling, x, sibling === node
           ? parent.dx * k / node.value
           : parent.dx * (1 - k) / (parent.value - node.value));
       });
       } else {
       reposition(node, 0, node.dx / node.value);
       }
       path.transition() // was path - undefined
       .duration(750)
       .attrTween("d", arcTween);
       }; // end magnify
       // Recursively reposition the node at position x with scale k.
       function reposition(node, x, k) {
       node.x = x;
       if (node.children && (n = node.children.length)) {
           var i = -1, n;
           while (++i < n) x += reposition(node.children[i], x, k);
           }
       return node.dx = node.value * k;
       }; // end reposition
       // Stash the old values for transition.
       function stash(d) {
       d.x0 = d.x;
       d.dx0 = d.dx;
       }; // end stash
       // Interpolate the arcs in data space.
       function arcTween(a) {
       var i = d3.interpolate({x: a.x0, dx: a.dx0}, a);
       return function(t) {
           var b = i(t);
           a.x0 = b.x;
           a.dx0 = b.dx;
           return arc(b)
           }
       } // end arcTween
       </script>
       ```
   
 * [https://wordpress.org/plugins/simple-embed-code/](https://wordpress.org/plugins/simple-embed-code/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [David Artiss](https://wordpress.org/support/users/dartiss/)
 * (@dartiss)
 * [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/#post-7265503)
 * Ok, here’s what you need to do… display the page which has the embedded code 
   on it. Now look at the page source and find the script above. Is it the same 
   or is it different (and, if so, how)?
 * David.
 *  Thread Starter [pwarwick](https://wordpress.org/support/users/pwarwick/)
 * (@pwarwick)
 * [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/#post-7265531)
 * I used TextWrangler to compare both embedded script and the source script and
   they are identical.
 *  Plugin Author [David Artiss](https://wordpress.org/support/users/dartiss/)
 * (@dartiss)
 * [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/#post-7265533)
 * In that case the plugin is working fine as it’s output the code exactly as it
   should have done. The issue must be with the script.
 * David.
 *  Thread Starter [pwarwick](https://wordpress.org/support/users/pwarwick/)
 * (@pwarwick)
 * [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/#post-7265534)
 * I understand your point BUT the script works in Drupal and it worked without 
   problem until I made some changes to the non-script code. What do you suggest
   could be the problem?
 *  Thread Starter [pwarwick](https://wordpress.org/support/users/pwarwick/)
 * (@pwarwick)
 * [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/#post-7265537)
 * Forget that … I copied this code back to the Drupal page and it stopped working
   although they were identical to begin with. I’ll see if I can figure out what
   is broken.
 *  Thread Starter [pwarwick](https://wordpress.org/support/users/pwarwick/)
 * (@pwarwick)
 * [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/#post-7265549)
 * Plug-in is working properly now. User error.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Intermittent error when embedded code does not execute’ is closed to 
new replies.

 * ![](https://ps.w.org/simple-embed-code/assets/icon.svg?rev=3073981)
 * [Code Embed](https://wordpress.org/plugins/simple-embed-code/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-embed-code/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-embed-code/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-embed-code/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-embed-code/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-embed-code/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [pwarwick](https://wordpress.org/support/users/pwarwick/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/intermittent-error-when-embedded-code-does-not-execute/#post-7265549)
 * Status: resolved