@samitouri / QOS-React-2 / commits / 265fdc3eed

Rewrite SVG initialization in getMarkupWrap

Paul O’Shannessy committed Jun 17, 2015 at 10:37 UTC 265fdc3eed9bfebeae062dcff06661900df6e39d
1 file changed +26 -33
src/shared/vendor/core/getMarkupWrap.js
+26 -33
@@ -25,24 +25,8 @@ var dummyNode =
25 *
26 * In IE8, certain elements cannot render alone, so wrap all elements ('*').
27 */
28 -var shouldWrap = {
29 - // Force wrapping for SVG elements because if they get created inside a <div>,
30 - // they will be initialized in the wrong namespace (and will not display).
31 - 'circle': true,
32 - 'clipPath': true,
33 - 'defs': true,
34 - 'ellipse': true,
35 - 'g': true,
36 - 'line': true,
37 - 'linearGradient': true,
38 - 'path': true,
39 - 'polygon': true,
40 - 'polyline': true,
41 - 'radialGradient': true,
42 - 'rect': true,
43 - 'stop': true,
44 - 'text': true
45 -};
28 +
29 +var shouldWrap = {};
30
31 var selectWrap = [1, '<select multiple="true">', '</select>'];
32 var tableWrap = [1, '<table>', '</table>'];
@@ -70,23 +54,32 @@ var markupWrap = {
54
55 'td': trWrap,
56 'th': trWrap,
73 -
74 - 'circle': svgWrap,
75 - 'clipPath': svgWrap,
76 - 'defs': svgWrap,
77 - 'ellipse': svgWrap,
78 - 'g': svgWrap,
79 - 'line': svgWrap,
80 - 'linearGradient': svgWrap,
81 - 'path': svgWrap,
82 - 'polygon': svgWrap,
83 - 'polyline': svgWrap,
84 - 'radialGradient': svgWrap,
85 - 'rect': svgWrap,
86 - 'stop': svgWrap,
87 - 'text': svgWrap
57 };
58
59 +// Initilize the SVG elements since we know they'll always need to be wrapped
60 +// consistently. If they are created inside a <div> they will be initialized in
61 +// the wrong namespace (and will not display).
62 +var svgElements = [
63 + 'circle',
64 + 'clipPath',
65 + 'defs',
66 + 'ellipse',
67 + 'g',
68 + 'line',
69 + 'linearGradient',
70 + 'path',
71 + 'polygon',
72 + 'polyline',
73 + 'radialGradient',
74 + 'rect',
75 + 'stop',
76 + 'text',
77 +];
78 +svgElements.forEach((nodeName) => {
79 + markupWrap[nodeName] = svgWrap;
80 + shouldWrap[nodeName] = true;
81 +});
82 +
83 /**
84 * Gets the markup wrap configuration for the supplied `nodeName`.
85 *