Skip to content

Instantly share code, notes, and snippets.

@vedovelli
Created July 15, 2016 13:13
Show Gist options
  • Save vedovelli/308fc20fc6bdc728d9d4e1905894bf4c to your computer and use it in GitHub Desktop.
Save vedovelli/308fc20fc6bdc728d9d4e1905894bf4c to your computer and use it in GitHub Desktop.
getChartsContents () {
const domEls = jQuery('.oct-chart svg') // acesso todos os SVG da pagina
const quantity = domEls.length
let i = 0
let contents = []
for (i; i < quantity; i++) { // neste loop pegarei o conteudo dos SVG e transformarei para Base64
/**
* Serialize SVG to String
*/
let svg = (new XMLSerializer).serializeToString(domEls[i])
/**
* This will ensure non-Latin chars are properly escaped
*/
svg = unescape(encodeURIComponent(svg))
/**
* Add to array to be returned encoded as Base64
*/
contents.unshift(window.btoa(svg))
}
return contents
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment