Created
May 19, 2017 15:04
-
-
Save EWhite613/454c20fce836e48b20000c57cdc5de50 to your computer and use it in GitHub Desktop.
Convert SVG4Everybody (svg `use` tags) to inline
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
function convertSVG4Everbody () { | |
var items = Array.from(document.querySelectorAll('use')) | |
items.map(function (use) { | |
var svgParent = use.parentNode | |
var url = use.href.baseVal | |
var id = /#\S*/.exec(url)[0].replace('#', '') | |
console.log('url: ', url) | |
var xml = httpGetXML(url) | |
var symbol = xml.getElementById(id) | |
// Grab all of the original's attributes, and pass them to the replacement | |
svgParent.innerHTML = symbol.innerHTML | |
for (var i = 0, l = symbol.attributes.length; i < l; ++i) { | |
var nodeName = symbol.attributes.item(i).nodeName | |
var nodeValue = symbol.attributes.item(i).nodeValue | |
if (nodeName !== 'id' && nodeName !== 'class') { | |
svgParent.setAttribute(nodeName, nodeValue) | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment