Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uploaddebugger.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or http://ckeditor.com/license
  4. */
  5. 'use strict';
  6. // Slow down the upload process.
  7. // This trick works only on Chrome.
  8. ( function() {
  9. XMLHttpRequest.prototype.baseSend = XMLHttpRequest.prototype.send;
  10. XMLHttpRequest.prototype.send = function( data ) {
  11. var baseOnProgress = this.onprogress,
  12. baseOnLoad = this.onload;
  13. this.onprogress = function() {};
  14. this.onload = function( evt ) {
  15. // Total file size.
  16. var total = 1163,
  17. step = Math.round( total / 10 ),
  18. loaded = 0,
  19. xhr = this;
  20. function progress() {
  21. setTimeout( function() {
  22. if ( xhr.aborted ) {
  23. return;
  24. }
  25. loaded += step;
  26. if ( loaded > total ) {
  27. loaded = total;
  28. }
  29. if ( loaded > step * 4 && xhr.responseText.indexOf( 'incorrectFile' ) > 0 ) {
  30. xhr.aborted = true;
  31. xhr.onerror();
  32. } else if ( loaded < total ) {
  33. evt.loaded = loaded;
  34. baseOnProgress( { loaded: loaded } );
  35. progress();
  36. } else {
  37. baseOnLoad( evt );
  38. }
  39. }, 300 );
  40. }
  41. progress();
  42. };
  43. this.abort = function() {
  44. this.aborted = true;
  45. this.onabort();
  46. };
  47. this.baseSend( data );
  48. };
  49. } )();