Skip to content

Commit

Permalink
Merge pull request #51 from robbykraft/develop
Browse files Browse the repository at this point in the history
replace innerHTML with createTextNode for nodejs compatibility
  • Loading branch information
mayakraft authored Mar 24, 2020
2 parents 7046275 + 2657ddc commit 4f9cf34
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
10 changes: 9 additions & 1 deletion examples/code/examples/bezier.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
svg.size(800, 800);

// create a layer behind everything
var back = svg.g();

// shapes on top
var curve = svg.path();
var l1 = svg.line().stroke("black");
var l2 = svg.line().stroke("black");
var curve = svg.path();

// these are persistent control points
// 1.create an svg element to track with each point
// 2.assign a position
// 3.append to a parent
// 4.onChange event handler with "this" bound to the controls
svg.controls(4)
.svg(function () { return SVG.circle(0, 0, svg.getWidth() * 0.05).fill("#e53"); })
.position(function () { return [random(svg.getWidth()), random(svg.getHeight())]; })
Expand Down
7 changes: 6 additions & 1 deletion src/nodes/spec/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* SVG (c) Robby Kraft
*/

import window from "../../environment/window"
import flatten from "../../arguments/flatten";
import coordinates from "../../arguments/coordinates";
import K from "../../environment/keys";
Expand All @@ -13,7 +14,11 @@ export default {
init: (element, a, b, c, d) => {
const text = [a,b,c,d].filter(a => typeof a === K.string).shift();
if (text) {
element.innerHTML = text;
if (element.firstChild) {
element.firstChild.nodeValue = text;
} else {
element.appendChild(window.document.createTextNode(text));
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,11 @@
return _typeof(a) === Keys.string;
}).shift();
if (text) {
element.innerHTML = text;
if (element.firstChild) {
element.firstChild.nodeValue = text;
} else {
element.appendChild(win.document.createTextNode(text));
}
}
}
}
Expand Down
Loading

0 comments on commit 4f9cf34

Please sign in to comment.