Skip to content

Commit 056dc0f

Browse files
committed
Merge pull request #21 from bytespider/master
Fixed missing colon in package.json, add beginnings of addEventListener
2 parents e165ad1 + ba0a309 commit 056dc0f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/XMLHttpRequest.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ exports.XMLHttpRequest = function() {
128128
/**
129129
* Gets all the response headers.
130130
*
131-
* @return string
131+
* @return string
132132
*/
133133
this.getAllResponseHeaders = function() {
134134
if (this.readyState < this.HEADERS_RECEIVED || errorFlag) {
@@ -349,6 +349,14 @@ exports.XMLHttpRequest = function() {
349349
this.readyState = this.UNSENT;
350350
};
351351

352+
var listeners = {};
353+
this.addEventListener = function(event, callback) {
354+
if (!(event in listeners)) {
355+
listeners[event] = [];
356+
}
357+
listeners[event].push(callback);
358+
};
359+
352360
/**
353361
* Changes readyState and calls onreadystatechange.
354362
*
@@ -359,5 +367,12 @@ exports.XMLHttpRequest = function() {
359367
if (typeof self.onreadystatechange === "function") {
360368
self.onreadystatechange();
361369
}
370+
371+
if ("readystatechange" in listeners) {
372+
var count = listeners["readystatechange"].length, i = 0;
373+
for(; i < count; i++) {
374+
listeners["readystatechange"][i].call(self);
375+
}
376+
}
362377
};
363378
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "Dan DeFelippi"
77
, "url": "http://driverdan.com"
88
}
9-
, "keywords" ["xhr", "ajax"]
9+
, "keywords": ["xhr", "ajax"]
1010
, "licenses": [{
1111
"type": "MIT"
1212
, "url": "http://creativecommons.org/licenses/MIT/"

0 commit comments

Comments
 (0)