Created
May 24, 2011 12:05
-
-
Save louisremi/988592 to your computer and use it in GitHub Desktop.
Fake XMLHttpRequest producing slow progress events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fakeXMLHttpRequest() { | |
var self = this; | |
this.upload = { | |
addEventListener: function(evt, cb) { | |
self.progressListener = cb; | |
} | |
} | |
this.open = function() {}; | |
this.overrideMimeType = function() {}; | |
this.loaded = 0; | |
this.total = 100; | |
this.send = function() { | |
var interval = setInterval(function() { | |
self.loaded += 10 + Math.random()*10; | |
self.progressListener({ | |
loaded: Math.min(self.loaded, 100), | |
total: self.total | |
}); | |
if ( self.loaded >= 100 ) { | |
self.loaded = 0; | |
clearInterval(interval); | |
} | |
}, 250); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment