diff --git a/README.md b/README.md index bf74ffd..4d00b3d 100644 --- a/README.md +++ b/README.md @@ -41,14 +41,14 @@ For a live demo check out this [example on CodePen](http://codepen.io/jonnyhayne ## Bower -If you're using [Bower](bower.io) to manage your front-end dependencies you can include this plugin as a component. Include `"inline-svg": "2.1.0"` in your `bower.json` file and run `bower install`. +If you're using [Bower](bower.io) to manage your front-end dependencies you can include this plugin as a component. Include `"inline-svg": "2.1.1"` in your `bower.json` file and run `bower install`. ## NPM If you're using NPM to manage your dependencies you can include this plugin as a module. Just run `npm install inline-svg`. ## Changelog -- **31/07/15:** 2.1.0 – Added localStorage support to avoid making fresh HTTP request on every page load. When the contents of the SVG is loaded it is added to localStorage and then on repeat page loads the source is grabbed from localStorage. +- **31/07/15:** 2.1.1 – Added localStorage support to avoid making fresh HTTP request on every page load. When the contents of the SVG is loaded it is added to localStorage and then on repeat page loads the source is grabbed from localStorage. - **31/07/15:** 2.0.1 - Major upgrade. Added AMD support and fixed a long standing issue that would result in a warning in Google Chrome as we weren't handling the GET requests asynchronously. - **18/06/15:** 1.2.0 – Converted to a Node.js module - **19/03/15:** 1.0.5 – Cleaning code to comply with Code Climate diff --git a/bower.json b/bower.json index 4114712..587daf5 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "inline-svg", - "version": "2.1.0", + "version": "2.1.1", "homepage": "https://github.com/jonnyhaynes/inline-svg", "authors": [ "Jonny Haynes ", diff --git a/dist/inlineSVG.min.js b/dist/inlineSVG.min.js index 67d5f7c..9820af7 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){"use strict";var b,c={},d=!!document.querySelector&&!!a.addEventListener,e={initClass:"js-inlinesvg",svgSelector:"img.svg"},f=function(a){var b={},c=!1,d=0,e=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(c=arguments[0],d++);for(var f=function(a){for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&(c&&"[object Object]"===Object.prototype.toString.call(a[d])?b[d]=buoy.extend(!0,b[d],a[d]):b[d]=a[d])};e>d;d++){var g=arguments[d];f(g)}return b};return c.getAll=function(){var a=document.querySelectorAll(b.svgSelector);return a},c.inliner=function(){var a=c.getAll();Array.prototype.forEach.call(a,function(a,b){var c=a.src,d=a.attributes;if(localStorage.getItem(c)){var e=new DOMParser,f=e.parseFromString(localStorage.getItem(c),"text/xml"),g=f.getElementsByTagName("svg")[0];a.parentNode.replaceChild(g,a)}else{var h=new XMLHttpRequest;h.open("GET",c,!0),h.onload=function(){if(h.status>=200&&h.status<400){var b=new DOMParser,e=b.parseFromString(h.responseText,"text/xml"),f=e.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"),i=document.createTextNode(d.longdesc.value);g.appendChild(i),f.insertBefore(g,f.firstChild)}if(d.alt){f.setAttribute("aria-labelledby","title");var j=document.createElementNS("http://www.w3.org/2000/svg","title"),k=document.createTextNode(d.alt.value);j.appendChild(k),f.insertBefore(j,f.firstChild)}var l=document.createElement("div");l.appendChild(f),localStorage.setItem(c,l.innerHTML),a.parentNode.replaceChild(f,a)}else console.error("There was an error retrieving the source of the SVG.")},h.onerror=function(){console.error("There was an error connecting to the origin server.")},h.send()}})},c.init=function(a){d&&(b=f(e,a||{}),c.inliner(),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){"use strict";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};return c.getAll=function(){var a=document.querySelectorAll(b.svgSelector);return a},c.inliner=function(){var a=c.getAll();Array.prototype.forEach.call(a,function(a,b){var c=a.src,d=a.attributes;if(localStorage.getItem(c)){var e=new DOMParser,f=e.parseFromString(localStorage.getItem(c),"text/xml"),g=f.getElementsByTagName("svg")[0];a.parentNode.replaceChild(g,a)}else{var h=new XMLHttpRequest;h.open("GET",c,!0),h.onload=function(){if(h.status>=200&&h.status<400){var b=new DOMParser,e=b.parseFromString(h.responseText,"text/xml"),f=e.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"),i=document.createTextNode(d.longdesc.value);g.appendChild(i),f.insertBefore(g,f.firstChild)}if(d.alt){f.setAttribute("aria-labelledby","title");var j=document.createElementNS("http://www.w3.org/2000/svg","title"),k=document.createTextNode(d.alt.value);j.appendChild(k),f.insertBefore(j,f.firstChild)}var l=document.createElement("div");l.appendChild(f),localStorage.setItem(c,l.innerHTML),a.parentNode.replaceChild(f,a)}else console.error("There was an error retrieving the source of the SVG.")},h.onerror=function(){console.error("There was an error connecting to the origin server.")},h.send()}})},c.init=function(a){d&&(b=f(e,a||{}),c.inliner(),document.documentElement.className+=" "+b.initClass)},c}); \ No newline at end of file diff --git a/package.json b/package.json index fbd0c35..fa2add1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "inline-svg", - "version": "2.1.0", + "version": "2.1.1", "devDependencies": { "grunt": "0.4.5", "grunt-cli": "0.1.13",