Skip to content

Commit 3a5b1ff

Browse files
author
Piotr Jasiun
committed
Merge branch 't/13533b'
2 parents 8cb575d + a0bc69e commit 3a5b1ff

File tree

10 files changed

+384
-195
lines changed

10 files changed

+384
-195
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Fixed Issues:
99
* [#13142](http://dev.ckeditor.com/ticket/13142): [Edge] Fixed: CTRL+A, backspace results in an empty div.
1010
* [#13599](http://dev.ckeditor.com/ticket/13599): Fixed: Cross-editor D&D of inline widget ends up in error/artifacts.
1111
* [#13640](http://dev.ckeditor.com/ticket/13640): [IE] Fixed: Dropping a widget outside body is not handled correctly.
12+
* [#13533](http://dev.ckeditor.com/ticket/13533): Fixed: No progress during upload.
1213

1314
Other Changes:
1415

plugins/filetools/plugin.js

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@
276276
}
277277

278278
this.uploaded = 0;
279+
this.uploadTotal = null;
279280

280281
this.status = 'created';
281282

@@ -343,6 +344,23 @@
343344
* @property {Number} total
344345
*/
345346

347+
/**
348+
* The total size of upload data in bytes.
349+
* If `xhr.upload` object is present this value will indicate total size of the request payload, not only the file
350+
* size itself. If `xhr.upload` object is not available and real upload size cannot be obtained - this value will
351+
* be equal to {@link #total}. It has null value until upload size is known.
352+
*
353+
* loader.on( 'update', function() {
354+
* // Wait till uploadTotal is present.
355+
* if ( loader.uploadTotal ) {
356+
* console.log( 'uploadTotal: ' + loader.uploadTotal );
357+
* }
358+
* });
359+
*
360+
* @readonly
361+
* @property {Number} uploadTotal
362+
*/
363+
346364
/**
347365
* The error message or additional information received from the server.
348366
*
@@ -518,22 +536,43 @@
518536
xhr.abort();
519537
};
520538

521-
xhr.onabort = function() {
522-
loader.changeStatus( 'abort' );
523-
};
539+
xhr.onerror = onError;
540+
xhr.onabort = onAbort;
541+
542+
// #13533 - When xhr.upload is present attach onprogress, onerror and onabort functions to get actual upload
543+
// information.
544+
if ( xhr.upload ) {
545+
xhr.upload.onprogress = function( evt ) {
546+
if ( evt.lengthComputable ) {
547+
// Set uploadTotal with correct data.
548+
if ( !loader.uploadTotal ) {
549+
loader.uploadTotal = evt.total;
550+
}
551+
loader.uploaded = evt.loaded;
552+
loader.update();
553+
}
554+
};
524555

525-
xhr.onerror = function() {
526-
loader.message = loader.lang.filetools.networkError;
527-
loader.changeStatus( 'error' );
528-
};
556+
xhr.upload.onerror = onError;
557+
xhr.upload.onabort = onAbort;
529558

530-
xhr.onprogress = function( evt ) {
531-
loader.uploaded = evt.loaded;
559+
} else {
560+
// #13533 - If xhr.upload is not supported - fire update event anyway and set uploadTotal to file size.
561+
loader.uploadTotal = loader.total;
532562
loader.update();
533-
};
563+
}
534564

535565
xhr.onload = function() {
536-
loader.uploaded = loader.total;
566+
// #13433 - Call update at the end of the upload. When xhr.upload object is not supported there will be
567+
// no update events fired during the whole process.
568+
loader.update();
569+
570+
// #13433 - Check if loader was not aborted during last update.
571+
if ( loader.status == 'abort' ) {
572+
return;
573+
}
574+
575+
loader.uploaded = loader.uploadTotal;
537576

538577
if ( xhr.status < 200 || xhr.status > 299 ) {
539578
loader.message = loader.lang.filetools[ 'httpError' + xhr.status ];
@@ -563,6 +602,24 @@
563602
}
564603
}
565604
};
605+
606+
function onError() {
607+
// Prevent changing status twice, when HHR.error and XHR.upload.onerror could be called together.
608+
if ( loader.status == 'error' ) {
609+
return;
610+
}
611+
612+
loader.message = loader.lang.filetools.networkError;
613+
loader.changeStatus( 'error' );
614+
}
615+
616+
function onAbort() {
617+
// Prevent changing status twice, when HHR.onabort and XHR.upload.onabort could be called together.
618+
if ( loader.status == 'abort' ) {
619+
return;
620+
}
621+
loader.changeStatus( 'abort' );
622+
}
566623
},
567624

568625
/**

plugins/uploadwidget/plugin.js

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -442,33 +442,16 @@
442442
* @param {CKEDITOR.fileTools.fileLoader} loader The file loader instance.
443443
*/
444444
function bindNotifications( editor, loader ) {
445-
var aggregator = editor._.uploadWidgetNotificaionAggregator;
446-
447-
// Create one notification agregator for all types of upload widgets for the editor.
448-
if ( !aggregator || aggregator.isFinished() ) {
449-
aggregator = editor._.uploadWidgetNotificaionAggregator = new CKEDITOR.plugins.notificationAggregator(
450-
editor, editor.lang.uploadwidget.uploadMany, editor.lang.uploadwidget.uploadOne );
451-
452-
aggregator.once( 'finished', function() {
453-
var tasks = aggregator.getTaskCount();
454-
455-
if ( tasks === 0 ) {
456-
aggregator.notification.hide();
457-
} else {
458-
aggregator.notification.update( {
459-
message: tasks == 1 ?
460-
editor.lang.uploadwidget.doneOne :
461-
editor.lang.uploadwidget.doneMany.replace( '%1', tasks ),
462-
type: 'success',
463-
important: 1
464-
} );
465-
}
466-
} );
467-
}
468-
469-
var task = aggregator.createTask( { weight: loader.total } );
445+
var aggregator,
446+
task = null;
470447

471448
loader.on( 'update', function() {
449+
// Value of uploadTotal is known after upload start. Task will be created when uploadTotal is present.
450+
if ( !task && loader.uploadTotal ) {
451+
createAggregator();
452+
task = aggregator.createTask( { weight: loader.uploadTotal } );
453+
}
454+
472455
if ( task && loader.status == 'uploading' ) {
473456
task.update( loader.uploaded );
474457
}
@@ -487,6 +470,32 @@
487470
task && task.cancel();
488471
editor.showNotification( editor.lang.uploadwidget.abort, 'info' );
489472
} );
473+
474+
function createAggregator() {
475+
aggregator = editor._.uploadWidgetNotificaionAggregator;
476+
477+
// Create one notification aggregator for all types of upload widgets for the editor.
478+
if ( !aggregator || aggregator.isFinished() ) {
479+
aggregator = editor._.uploadWidgetNotificaionAggregator = new CKEDITOR.plugins.notificationAggregator(
480+
editor, editor.lang.uploadwidget.uploadMany, editor.lang.uploadwidget.uploadOne );
481+
482+
aggregator.once( 'finished', function() {
483+
var tasks = aggregator.getTaskCount();
484+
485+
if ( tasks === 0 ) {
486+
aggregator.notification.hide();
487+
} else {
488+
aggregator.notification.update( {
489+
message: tasks == 1 ?
490+
editor.lang.uploadwidget.doneOne :
491+
editor.lang.uploadwidget.doneMany.replace( '%1', tasks ),
492+
type: 'success',
493+
important: 1
494+
} );
495+
}
496+
} );
497+
}
498+
}
490499
}
491500

492501
// Two plugins extend this object.

0 commit comments

Comments
 (0)