Created
December 16, 2015 04:00
-
-
Save jpdevries/af5eeb6ed0261098a1de to your computer and use it in GitHub Desktop.
PoC for a SVG "polyfill"
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 class="icon" data-png-fallback="assets/img/src/icons/black/png/icon-modx"> | |
<title>Best CMS Ever</title> | |
<use xlink:href="assets/img/icons.svg#icon-modx"></use> | |
</svg> | |
*/ | |
var hasSVG = false; //your feature detection here | |
(function(hasSVG){ | |
if(!hasSVG) { | |
var icons = document.querySelectorAll('svg.icons'); // ES6 because it's almost 2016 | |
for(var i = 0; i < icons.length; i++) { | |
var icon = icon[i]; | |
var src = icon.getAttribute('data-png-fallback'); | |
var alt = icon.querySelector('title').innerHTML; | |
var img = document.createElement('img'); | |
img.setAttribute('alt',alt); | |
img.setAttribute('src',src); | |
img.addClass('icon'); | |
icon.outerHTML = img.outerHTML; | |
} | |
} | |
})(hasSVG); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.no-js support?
What about if we can't rely on JavaScript? Try using
<noscript>
like this: