Last active
August 31, 2015 14:29
-
-
Save adamkudrna/0ee60ea24ee4c780fc10 to your computer and use it in GitHub Desktop.
SVG src fallback by Jobs UI
This file contains hidden or 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
/* | |
* Replaces SVG images in img elements with PNG alternative | |
* | |
* The PNG file must have the same URL as the SVG file, up to the extension. | |
*/ | |
$(function () { | |
'use strict'; | |
function supportsSvg() { | |
return document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1'); | |
} | |
if (!supportsSvg()) { | |
$('img[src$=".svg"], img[src*=".svg?"]').attr('src', function (i, src) { | |
return src.replace(/\.svg(\?|$)/, '.png$1'); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment