timple-c
11/29/2017 - 8:09 PM

convertir automaticamente img a svg

convertir automaticamente img a svg

$(function(){function a(a){jQuery(a).each(function(){var a=jQuery(this),b=a.attr("id"),c=a.attr("class"),d=a.attr("src");a.hide(),jQuery.get(d,function(d){var e=jQuery(d).find("svg");"undefined"!=typeof b&&(e=e.attr("id",b)),"undefined"!=typeof c&&(e=e.attr("class",c+" replaced-svg")),e=e.removeAttr("xmlns:a"),a.replaceWith(e)},"xml")})}a('img[src*=".svg"]')});
/*
 * Replace all SVG images with inline SVG
 */
$(function(){
    activate('img[src*=".svg"]');

    function activate(string){
        jQuery(string).each(function(){
            var $img = jQuery(this);
            var imgID = $img.attr('id');
            var imgClass = $img.attr('class');
            var imgURL = $img.attr('src');
			
			$img.hide();

            jQuery.get(imgURL, function(data) {
                // Get the SVG tag, ignore the rest
                var $svg = jQuery(data).find('svg');

                // Add replaced image's ID to the new SVG
                if(typeof imgID !== 'undefined') {
                    $svg = $svg.attr('id', imgID);
                }
                // Add replaced image's classes to the new SVG
                if(typeof imgClass !== 'undefined') {
                    $svg = $svg.attr('class', imgClass+' replaced-svg');
                }

                // Remove any invalid XML tags as per http://validator.w3.org
                $svg = $svg.removeAttr('xmlns:a');

                // Replace image with new SVG
                $img.replaceWith($svg);

            }, 'xml');
        });
    }
});