Created
February 29, 2020 12:11
-
-
Save fuzzypawzz/7c25d3c2ea05df52e7e74952fd718da6 to your computer and use it in GitHub Desktop.
SVG Constructor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* SVG ICON CONSTRUCTOR | |
* @constructor | |
* @param {string} svgId The reference ID for the SVG (for use with the 'use' svg) | |
* @param {string} className Class of the SVG's parent element | |
*/ | |
function Svg(svgId, className) { | |
this.svgId = svgId; | |
this.className = className; | |
this.createSvg = function () { | |
// Create the parent namespace SVG element | |
var namespace = document.createElementNS("http://www.w3.org/2000/svg", "svg"); | |
namespace.setAttribute("class", className); | |
// namespace.className = this.className; | |
// Create the SVG use (shadow) | |
var use = document.createElementNS("http://www.w3.org/2000/svg", "use"); | |
use.setAttributeNS(null, "href", "#".concat(svgId)); | |
// Append element as child of the parent | |
namespace.appendChild(use); | |
return namespace; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment