Add download image button
Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
@@ -392,4 +392,29 @@ enableViewer = function() {
|
||||
previewMv[0].disableTap = false
|
||||
previewMv[0].toggleAttribute('camera-controls', true)
|
||||
return previewMv[0]
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the model viewer methods to get image
|
||||
* of current view and download
|
||||
*
|
||||
* @param {string} defName wiki page name to use as base file name
|
||||
*/
|
||||
downloadImage = function(defName) {
|
||||
const imgName = defName.substring(5).split('.')[0]
|
||||
const mView = $('model-viewer')[0]
|
||||
|
||||
const dlA = document.createElement('a')
|
||||
dlA.setAttribute('download',imgName + '.png')
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.addEventListener("load", () => {
|
||||
dlA.setAttribute('href',reader.result)
|
||||
dlA.click()
|
||||
},{once: true})
|
||||
|
||||
mView.toBlob(null, null, true)
|
||||
.then(imgBlob => {
|
||||
reader.readAsDataURL(imgBlob)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user