From 8a08e52a549efcf4814938f94201be3e8504dfc2 Mon Sep 17 00:00:00 2001 From: Oliver Farrell Date: Mon, 21 Sep 2015 16:33:02 +0100 Subject: [PATCH] Version bump. --- README.md | 1 + bower.json | 2 +- package.json | 2 +- src/inlineSVG.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2024f9b..ec891d5 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ If you're using NPM to manage your dependencies you can include this plugin as a ## Changelog +- **26/08/15:** 2.1.3 – Version bump. - **26/08/15:** 2.1.2 – Removed localStorage. It just doesn't work that well when SVG's change etc. - **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. diff --git a/bower.json b/bower.json index 2af44f3..8d8df4b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "inline-svg", - "version": "2.1.2", + "version": "2.1.3", "homepage": "https://github.com/jonnyhaynes/inline-svg", "authors": [ "Jonny Haynes ", diff --git a/package.json b/package.json index 1ea364c..edb8b93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "inline-svg", - "version": "2.1.2", + "version": "2.1.3", "devDependencies": { "grunt": "0.4.5", "grunt-cli": "0.1.13", diff --git a/src/inlineSVG.js b/src/inlineSVG.js index 091f387..f573a7c 100755 --- a/src/inlineSVG.js +++ b/src/inlineSVG.js @@ -13,6 +13,7 @@ // Variables var inlineSVG = {}, supports = !!document.querySelector && !!root.addEventListener, + cache = {}, settings; // Defaults @@ -69,7 +70,7 @@ /** * Grab all the SVGs that match the selector - * @public + * @private */ var getAll = function () { @@ -78,6 +79,58 @@ }; + /** + * Grab the source of the SVG + * @private + */ + var getSource = function (svgURL) { + + // if the browser supports the fetch api + if (self.fetch) { + + fetch(svgURL).then(function (response) { + if(response.ok) { + console.log(response); + } else { + console.log('There was an error with response.'); + } + }).catch(function (error) { + console.error('There has been a problem getting the source of the SVG: ' + error.message); + }); + + } + + // the browser doesn't support the fetch api + else { + + var request = new XMLHttpRequest(); + request.open('GET', src, true); + + request.onload = function () { + + } + + request.onerror = function () { + console.error('There was an error connecting to the origin server.'); + }; + + request.send(); + + } + + }; + + /** + * + */ + var parseAsXML = function (response) { + + var parser = new DOMParser(), + result = parser.parseFromString(response.responseText, 'text/xml'), + inlinedSVG = result.getElementsByTagName('svg')[0]; + + }; + /** * Inline all the SVGs in the array * @public @@ -92,6 +145,10 @@ var src = svg.src || svg.getAttribute('data-src'), attributes = svg.attributes; + cache[src] = ""; + + getSource(src); + // Get the contents of the SVG var request = new XMLHttpRequest(); request.open('GET', src, true);