js/imgtosvg.js
// Replace the images for the URL
Replace the images for the URL
Replace the images for the URL
function replaceImg(svgURL, attr) {
                var xhr = new XMLHttpRequest();
                var s = new XMLSerializer();
                xhr.open('GET', svgURL, true);
                xhr.responseType = 'document';
                xhr.onload = function(e) {
                    var doc = this.response;
                    if(e.target.status === 404)
                        return;
                    var matches = document.querySelectorAll('[' + attr + ']');
                    var len = matches.length
                    for (var i = 0; i < len; i++) {
                        var src = matches[i].getAttribute(attr);
                        var htmlString = s.serializeToString(doc);
                        if (src.localeCompare(svgURL) === 0) {
                            if (attr.localeCompare('src') === 0) {
                                if(matches[i].tagName.localeCompare('svg') != 0){
                                    $img = document.createElement('svg');
                                    $img.innerHTML = htmlString;
                                    var svgHTML = $img.getElementsByTagName('svg')[0];
                                    if (matches[i].className)
                                        svgHTML.className.baseVal = matches[i].className;
                                    if (matches[i].id)
                                        svgHTML.id = matches[i].id;
                                    matches[i].parentNode.replaceChild(svgHTML, matches[i]);
                                } else {
                                    $img = matches[i];
                                    $img.innerHTML = htmlString;
                                    var svgHTML = $img.getElementsByTagName('svg')[0];
                                }
                            } else if (attr.localeCompare('background-src') === 0)
                                matches[i].style.backgroundImage = "url(" + src + ")";
                        }
                    }
                    delete fetchedURL[svgURL]; 
                };
                xhr.send();
            }
function replaceImg ( svgURL , attr ) { var xhr = new XMLHttpRequest ( ) ; var s = new XMLSerializer ( ) ; xhr . open ( 'GET' , svgURL , true ) ; xhr . responseType = 'document' ; xhr . onload = function ( e ) { var doc = this . response ; if ( e . target . status === 404 ) return ; var matches = document . querySelectorAll ( '[' + attr + ']' ) ; var len = matches . length for ( var i = 0 ; i < len ; i ++ ) { var src = matches [ i ] . getAttribute ( attr ) ; var htmlString = s . serializeToString ( doc ) ; if ( src . localeCompare ( svgURL ) === 0 ) { if ( attr . localeCompare ( 'src' ) === 0 ) { if ( matches [ i ] . tagName . localeCompare ( 'svg' ) != 0 ) { $img = document . createElement ( 'svg' ) ; $img . innerHTML = htmlString ; var svgHTML = $img . getElementsByTagName ( 'svg' ) [ 0 ] ; if ( matches [ i ] . className ) svgHTML . className . baseVal = matches [ i ] . className ; if ( matches [ i ] . id ) svgHTML . id = matches [ i ] . id ; matches [ i ] . parentNode . replaceChild ( svgHTML , matches [ i ] ) ; } else { $img = matches [ i ] ; $img . innerHTML = htmlString ; var svgHTML = $img . getElementsByTagName ( 'svg' ) [ 0 ] ; } } else if ( attr . localeCompare ( 'background-src' ) === 0 ) matches [ i ] . style . backgroundImage = "url(" + src + ")" ; } } delete fetchedURL [ svgURL ] ; } ; xhr . send ( ) ; }
Replace the images for the URL
Replace the images for the URL
// If the request fails // Replace all the images for the src // Pass values onto svg tag // Replace img with svg //Remove the fetched url