Skip to content

Commit

Permalink
Fix for no progress events
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed Aug 9, 2018
1 parent c9d59bf commit 1542eb7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 0 additions & 1 deletion module/ui/image-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export class ImageEditor extends Overlay {

// Create the base image to paste into the canvas
const baseImage = new Image()
baseImage.setAttribute('crossOrigin', 'anonymous')
baseImage.src = this._imageURL

baseImage.onload = () => {
Expand Down
21 changes: 17 additions & 4 deletions module/ui/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function defaultStatusTemplate(progress) {
} else if (progress >= 100) {
return 'Processing'
}
return `Uploading ${progress}%`
return `Uploading ${parseInt(progress)}%`
}


Expand Down Expand Up @@ -96,13 +96,15 @@ export class Uploader {
'reqProgress': (event) => {
// Update the progress bar
if (event.lengthComputable) {
this._progress(event.loaded / event.total)
const total = Math.max(1, event.total)
this._progress(event.loaded / total * 100)
} else {
this._progress(0)
}
},

'reqLoad': (event) => {
console.log(event)
const {response} = this._xhr

// Clear the handle to the request
Expand Down Expand Up @@ -141,10 +143,15 @@ export class Uploader {
{
'abort': this._handlers.reqAbort,
'error': this._handlers.reqError,
'progress': this._handlers.reqProgress,
'load': this._handlers.reqLoad
}
)
$.ignore(
this._xhr.upload,
{
'progress': this._handlers.reqProgress,
}
)
this._xhr.abort()
}

Expand Down Expand Up @@ -260,11 +267,17 @@ export class Uploader {
{
'abort': this._handlers.reqAbort,
'error': this._handlers.reqError,
'progress': this._handlers.reqProgress,
'load': this._handlers.reqLoad
}
)

$.listen(
this._xhr.upload,
{
'progress': this._handlers.reqProgress,
}
)

// Send the request
this._xhr.open('POST', this._url, true)
this._xhr.send(this._formData)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manhattan-assets",
"version": "1.0.0-beta.5",
"version": "1.0.0-beta.6",
"description": "File and image uploads for forms.",
"engines": {
"node": ">=8.9.4"
Expand Down

0 comments on commit 1542eb7

Please sign in to comment.