Permalink
Browse files

a package.json all up in this

  • Loading branch information...
1 parent 99fefaa commit f4432b97702f066525af18ec4dddbfccbddfc3d6 @substack committed Aug 20, 2011
Showing with 91 additions and 56 deletions.
  1. +56 −0 browser.js
  2. +1 −56 index.js
  3. +34 −0 package.json
View
56 browser.js
@@ -0,0 +1,56 @@
+var http = module.exports;
+var EventEmitter = require('events').EventEmitter;
+var Request = require('./lib/request');
+
+http.request = function (params, cb) {
+ if (!params) params = {};
+ if (!params.host) params.host = window.location.host.split(':')[0];
+ if (!params.port) params.port = window.location.port;
+
+ var req = new Request(new xhrHttp, params);
+ if (cb) req.on('response', cb);
+ return req;
+};
+
+http.get = function (params, cb) {
+ params.method = 'GET';
+ var req = http.request(params, cb);
+ req.end();
+ return req;
+};
+
+var xhrHttp = (function () {
+ if (typeof window === 'undefined') {
+ throw new Error('no window object present');
+ }
+ else if (window.XMLHttpRequest) {
+ return window.XMLHttpRequest;
+ }
+ else if (window.ActiveXObject) {
+ var axs = [
+ 'Msxml2.XMLHTTP.6.0',
+ 'Msxml2.XMLHTTP.3.0',
+ 'Microsoft.XMLHTTP'
+ ];
+ for (var i = 0; i < axs.length; i++) {
+ try {
+ var ax = new(window.ActiveXObject)(axs[i]);
+ return function () {
+ if (ax) {
+ var ax_ = ax;
+ ax = null;
+ return ax_;
+ }
+ else {
+ return new(window.ActiveXObject)(axs[i]);
+ }
+ };
+ }
+ catch (e) {}
+ }
+ throw new Error('ajax not supported in this browser')
+ }
+ else {
+ throw new Error('ajax not supported in this browser');
+ }
+})();
View
57 index.js
@@ -1,56 +1 @@
-var http = module.exports;
-var EventEmitter = require('events').EventEmitter;
-var Request = require('./lib/request');
-
-http.request = function (params, cb) {
- if (!params) params = {};
- if (!params.host) params.host = window.location.host.split(':')[0];
- if (!params.port) params.port = window.location.port;
-
- var req = new Request(new xhrHttp, params);
- if (cb) req.on('response', cb);
- return req;
-};
-
-http.get = function (params, cb) {
- params.method = 'GET';
- var req = http.request(params, cb);
- req.end();
- return req;
-};
-
-var xhrHttp = (function () {
- if (typeof window === 'undefined') {
- throw new Error('no window object present');
- }
- else if (window.XMLHttpRequest) {
- return window.XMLHttpRequest;
- }
- else if (window.ActiveXObject) {
- var axs = [
- 'Msxml2.XMLHTTP.6.0',
- 'Msxml2.XMLHTTP.3.0',
- 'Microsoft.XMLHTTP'
- ];
- for (var i = 0; i < axs.length; i++) {
- try {
- var ax = new(window.ActiveXObject)(axs[i]);
- return function () {
- if (ax) {
- var ax_ = ax;
- ax = null;
- return ax_;
- }
- else {
- return new(window.ActiveXObject)(axs[i]);
- }
- };
- }
- catch (e) {}
- }
- throw new Error('ajax not supported in this browser')
- }
- else {
- throw new Error('ajax not supported in this browser');
- }
-})();
+module.exports = require('http');
View
34 package.json
@@ -0,0 +1,34 @@
+{
+ "name" : "http-browserify",
+ "version" : "0.0.0",
+ "description" : "http module compatability for browserify",
+ "main" : "index.js",
+ "browserify" : "browser.js",
+ "directories" : {
+ "lib" : ".",
+ "example" : "example",
+ "test" : "test"
+ },
+ "devDependencies" : {
+ "express" : "2.4.x",
+ "browserify" : "1.4.x"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "http://github.com/substack/http-browserify.git"
+ },
+ "keywords" : [
+ "http",
+ "browserify",
+ "compatible",
+ "meatless",
+ "browser"
+ ],
+ "author" : {
+ "name" : "James Halliday",
+ "email" : "mail@substack.net",
+ "url" : "http://substack.net"
+ },
+ "license" : "MIT/X11",
+ "engine" : { "node" : ">=0.4" }
+}

0 comments on commit f4432b9

Please sign in to comment.