Fix twitter bug

- Closes #347
main
Mike Fix 7 years ago
parent 3bbb98a3a2
commit dd5a996e72

@ -73,7 +73,7 @@ class Editor extends React.Component {
this.props.onUpdate(this.state) this.props.onUpdate(this.state)
} }
getCarbonImage({ format } = { format: 'png' }) { getCarbonImage({ format, type } = { format: 'png' }) {
// if safari, get image from api // if safari, get image from api
if ( if (
navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Safari') !== -1 &&
@ -112,16 +112,21 @@ class Editor extends React.Component {
height height
} }
if (format === 'svg') { if (type === 'blob') {
return domtoimage if (format === 'svg') {
return domtoimage
.toSvg(node, config) .toSvg(node, config)
.then(dataUrl => dataUrl.split(' ').join(' ')) .then(dataUrl => dataUrl.split(' ').join(' '))
.then(uri => uri.slice(uri.indexOf(',') + 1)) .then(uri => uri.slice(uri.indexOf(',') + 1))
.then(data => new Blob([data], { type: 'image/svg+xml' })) .then(data => new Blob([data], { type: 'image/svg+xml' }))
.then(data => window.URL.createObjectURL(data)) .then(data => window.URL.createObjectURL(data))
}
return domtoimage.toBlob(node, config).then(blob => window.URL.createObjectURL(blob))
} }
return domtoimage.toBlob(node, config).then(blob => window.URL.createObjectURL(blob)) // Twitter needs regular dataurls
return domtoimage.toPng(node, config)
} }
updateSetting(key, value) { updateSetting(key, value) {
@ -131,7 +136,7 @@ class Editor extends React.Component {
save({ id: format = 'png' }) { save({ id: format = 'png' }) {
const link = document.createElement('a') const link = document.createElement('a')
return this.getCarbonImage({ format }).then(url => { return this.getCarbonImage({ format, type: 'blob' }).then(url => {
link.download = `carbon.${format}` link.download = `carbon.${format}`
link.href = url link.href = url
document.body.appendChild(link) document.body.appendChild(link)

Loading…
Cancel
Save