Created
November 25, 2014 16:30
-
-
Save kfox/f10abf8da83e0bb70e12 to your computer and use it in GitHub Desktop.
Replace SVG images loaded via img tags with inlined svg elements
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
inline_svg_images = (svg) -> | |
svg_selector = if svg? and $(svg)? then svg else 'img.svg' | |
$(svg_selector).each -> | |
$img = $(@) | |
$.get $img.attr('src'), (data) -> | |
$svg = $(data).find 'svg' | |
for attribute in [ 'id', 'class', 'height', 'width' ] | |
if $img.attr(attribute)? | |
$svg = $svg.attr attribute, $img.attr attribute | |
$svg = $svg.removeAttr 'xmlns:a' | |
$img.replaceWith $svg | |
, 'xml' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment