Converting Image SVG to Inline SVG using javascrip

2019-08-04 11:23发布

Trying to determine how I can include a prefix....such as "tst-" I am trying to prevent this script from interfering with any svg I do not want converted to inline.

This example Works: <img src="image.svg" alt="test image" />

Console.log displays <img src="image.svg" alt="test image" style="display: none;" />

Would like this to work by identifying tst with a .svg: <img src="tst-image.svg" alt="test image" />

Would like console.log to identify any .svg with tst- such as this <img src="tst-image.svg" alt="test image" style="display: none;"/>

    init: function() {
    /* svg to inline */
    (function() {
        $(function() {
            var t;
            return (t = $('img[src$=".svg"]').hide(), t.each(function(t, e) {
            console.log(e);
                var r = this;
                return $.get(this.src).success(function(t) {
                    var e, n, s, i, c, a, u;
                    for (e = $(t).find("svg"), c = r.attributes, $.extend(c, e[0].attributes), a = 0, u = c.length; u > a; a += 1) {
                        n = c[a], s = n.nodeName, i = n.nodeValue, "src" !== s && "style" !== s && e.attr(s, i);
                    }
                    return $(r).replaceWith(e);
                });
            }));
        });
    }).call(this);

}

I hope this makes sense.

0条回答
登录 后发表回答