Skip to content

Instantly share code, notes, and snippets.

@svecon
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svecon/8e8a179a54ca42c08992 to your computer and use it in GitHub Desktop.
Save svecon/8e8a179a54ca42c08992 to your computer and use it in GitHub Desktop.
(function (doc) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var div = doc.createElement('div');
div.innerHTML = this.responseText;
// div.style.display = 'none'; -- causes gradients not to render!
div.style.visibility = 'hidden';
div.style.position = 'absolute';
div.style.height = 0;
div.style.width = 0;
document.body.insertBefore(div, document.body.childNodes[0]);
var svgs = document.getElementsByTagName('svg');
for(l = svgs.length, i = 0; i<l; i++){
var us = svgs[i].getElementsByTagName('use');
if(us.length === 0) continue;
var xlink = us[0].getAttributeNS('http://www.w3.org/1999/xlink', 'href');
svgs[i].setAttribute('viewBox', document.getElementById(xlink.substr(1)).getAttribute('viewBox'));
}
}
xhr.open('get', '/images/svgicons.svg', true);
xhr.send();
})(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment