Last active
August 29, 2015 14:25
-
-
Save svecon/8e8a179a54ca42c08992 to your computer and use it in GitHub Desktop.
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 (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