Skip to content

Commit

Permalink
Request onprogress and onloadstart implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
w00fz committed Sep 4, 2010
1 parent 48f9611 commit 94ee0cc
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Source/Request/Request.js
Expand Up @@ -17,17 +17,21 @@ provides: Request

(function(){

var progressSupport = ('onprogress' in new Browser.Request);

var Request = this.Request = new Class({

Implements: [Chain, Events, Options],

options: {/*
onRequest: nil,
onLoadstart: nil,
onComplete: nil,
onCancel: nil,
onSuccess: nil,
onFailure: nil,
onException: nil,*/
onException: nil,
onProgress: nil,*/
url: '',
data: '',
headers: {
Expand Down Expand Up @@ -94,6 +98,14 @@ var Request = this.Request = new Class({
onFailure: function(){
this.fireEvent('complete').fireEvent('failure', this.xhr);
},

loadstart: function(event) {
this.fireEvent('loadstart', [event, this.xhr]);
},

progress: function(event) {
this.fireEvent('progress', [event, this.xhr]);
},

setHeader: function(name, value){
this.headers[name] = value;
Expand Down Expand Up @@ -162,8 +174,12 @@ var Request = this.Request = new Class({
data = null;
}

if (progressSupport) this.xhr.onprogress = this.progress.bind(this);

this.xhr.open(method.toUpperCase(), url, this.options.async);


if (progressSupport) this.xhr.onloadstart = this.loadstart.bind(this);

this.xhr.onreadystatechange = this.onStateChange.bind(this);

Object.each(this.headers, function(value, key){
Expand All @@ -185,6 +201,10 @@ var Request = this.Request = new Class({
this.running = false;
this.xhr.abort();
this.xhr.onreadystatechange = function(){};
if (progressSupport) {
this.xhr.onprogress = function(){};
this.xhr.onloadstart = function(){};
}
this.xhr = new Browser.Request();
this.fireEvent('cancel');
return this;
Expand Down

0 comments on commit 94ee0cc

Please sign in to comment.