Skip to content

Instantly share code, notes, and snippets.

@gsmartagence
Last active November 18, 2019 13:55
Show Gist options
  • Select an option

  • Save gsmartagence/0a34036e782b3a977a3a222ed406e8fa to your computer and use it in GitHub Desktop.

Select an option

Save gsmartagence/0a34036e782b3a977a3a222ed406e8fa to your computer and use it in GitHub Desktop.
/**
* inline svg store
* https://github.com/w0rm/gulp-svgstore#user-content-using-svg-as-external-file
*/
export const inlineSvgStore = (function (doc) {
'use strict'
const iconPath = doc.getElementById('iconPath').dataset.path
const scripts = doc.getElementsByTagName('script')
const script = scripts[scripts.length - 1]
const xhr = new XMLHttpRequest()
xhr.onload = function () {
var div = doc.createElement('div')
div.innerHTML = this.responseText
div.style.width = 0
div.style.height = 0
div.classList.add('visually-hidden')
div.setAttribute('aria-hidden', true)
script.parentNode.insertBefore(div, script)
}
xhr.open('get', iconPath, true)
xhr.send()
}(document))
{
"name": "inlineSvgStore.js",
"version": "0.1.1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment