diff --git a/dist/inlineSVG.min.js b/dist/inlineSVG.min.js index df2d32b..5e76ac0 100644 --- a/dist/inlineSVG.min.js +++ b/dist/inlineSVG.min.js @@ -1 +1 @@ -!function(a,b){"function"==typeof define&&define.amd?define([],b(a)):"object"==typeof exports?module.exports=b(a):a.inlineSVG=b(a)}("undefined"!=typeof global?global:this.window||this.global,function(a){var b,c={},d=!!document.querySelector&&!!a.addEventListener,e={initClass:"js-inlinesvg",svgSelector:"img.svg"},f=function(){var a={},b=!1,c=0,d=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(b=arguments[0],c++);for(var e=function(c){for(var d in c)Object.prototype.hasOwnProperty.call(c,d)&&(b&&"[object Object]"===Object.prototype.toString.call(c[d])?a[d]=f(!0,a[d],c[d]):a[d]=c[d])};d>c;c++){var g=arguments[c];e(g)}return a},g=function(){var a=document.querySelectorAll(b.svgSelector);return a},h=function(){var a=g();Array.prototype.forEach.call(a,function(a,b){var c=a.src||a.getAttribute("data-src"),d=a.attributes,e=new XMLHttpRequest;e.open("GET",c,!0),e.onload=function(){if(e.status>=200&&e.status<400){var b=new DOMParser,c=b.parseFromString(e.responseText,"text/xml"),f=c.getElementsByTagName("svg")[0];if(f.removeAttribute("xmlns:a"),f.removeAttribute("width"),f.removeAttribute("height"),f.removeAttribute("x"),f.removeAttribute("y"),f.removeAttribute("enable-background"),f.removeAttribute("xmlns:xlink"),f.removeAttribute("xml:space"),f.removeAttribute("version"),Array.prototype.slice.call(d).forEach(function(a){"src"!==a.name&&"alt"!==a.name&&f.setAttribute(a.name,a.value)}),f.classList?f.classList.add("inlined-svg"):f.className+=" inlined-svg",f.setAttribute("role","img"),d.longdesc){var g=document.createElementNS("http://www.w3.org/2000/svg","desc"),h=document.createTextNode(d.longdesc.value);g.appendChild(h),f.insertBefore(g,f.firstChild)}if(d.alt){f.setAttribute("aria-labelledby","title");var i=document.createElementNS("http://www.w3.org/2000/svg","title"),j=document.createTextNode(d.alt.value);i.appendChild(j),f.insertBefore(i,f.firstChild)}a.parentNode.replaceChild(f,a)}else console.error("There was an error retrieving the source of the SVG.")},e.onerror=function(){console.error("There was an error connecting to the origin server.")},e.send()})};return c.init=function(a){d&&(b=f(e,a||{}),h(),document.documentElement.className+=" "+b.initClass)},c}); \ No newline at end of file +!function(a,b){"function"==typeof define&&define.amd?define([],b(a)):"object"==typeof exports?module.exports=b(a):a.inlineSVG=b(a)}("undefined"!=typeof global?global:this.window||this.global,function(a){var b,c={},d=!!document.querySelector&&!!a.addEventListener,e={},f={initClass:"js-inlinesvg",svgSelector:"img.svg"},g=function(){var a={},b=!1,c=0,d=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(b=arguments[0],c++);for(var e=function(c){for(var d in c)Object.prototype.hasOwnProperty.call(c,d)&&(b&&"[object Object]"===Object.prototype.toString.call(c[d])?a[d]=g(!0,a[d],c[d]):a[d]=c[d])};d>c;c++){var f=arguments[c];e(f)}return a},h=function(){var a=document.querySelectorAll(b.svgSelector);return a},i=function(a){if(self.fetch)fetch(a).then(function(a){a.ok?console.log(a):console.log("There was an error with response.")})["catch"](function(a){console.error("There has been a problem getting the source of the SVG: "+a.message)});else{var b=new XMLHttpRequest;b.open("GET",src,!0),b.onload=function(){},b.onerror=function(){console.error("There was an error connecting to the origin server.")},b.send()}},j=function(){var a=h();Array.prototype.forEach.call(a,function(a,b){var c=a.src||a.getAttribute("data-src"),d=a.attributes;e[c]="",i(c);var f=new XMLHttpRequest;f.open("GET",c,!0),f.onload=function(){if(f.status>=200&&f.status<400){var b=new DOMParser,c=b.parseFromString(f.responseText,"text/xml"),e=c.getElementsByTagName("svg")[0];if(e.removeAttribute("xmlns:a"),e.removeAttribute("width"),e.removeAttribute("height"),e.removeAttribute("x"),e.removeAttribute("y"),e.removeAttribute("enable-background"),e.removeAttribute("xmlns:xlink"),e.removeAttribute("xml:space"),e.removeAttribute("version"),Array.prototype.slice.call(d).forEach(function(a){"src"!==a.name&&"alt"!==a.name&&e.setAttribute(a.name,a.value)}),e.classList?e.classList.add("inlined-svg"):e.className+=" inlined-svg",e.setAttribute("role","img"),d.longdesc){var g=document.createElementNS("http://www.w3.org/2000/svg","desc"),h=document.createTextNode(d.longdesc.value);g.appendChild(h),e.insertBefore(g,e.firstChild)}if(d.alt){e.setAttribute("aria-labelledby","title");var i=document.createElementNS("http://www.w3.org/2000/svg","title"),j=document.createTextNode(d.alt.value);i.appendChild(j),e.insertBefore(i,e.firstChild)}a.parentNode.replaceChild(e,a)}else console.error("There was an error retrieving the source of the SVG.")},f.onerror=function(){console.error("There was an error connecting to the origin server.")},f.send()})};return c.init=function(a){d&&(b=g(f,a||{}),j(),document.documentElement.className+=" "+b.initClass)},c}); \ No newline at end of file