Strip legacy xhr code out of lib/net

This commit is contained in:
DanyaPostfactum 2013-02-06 13:01:44 +10:00
commit 62b7d8c1ea
4 changed files with 9 additions and 41 deletions

View file

@ -34,7 +34,6 @@ define(function(require, exports, module) {
var config = require("./config");
var oop = require("./lib/oop");
var lang = require("./lib/lang");
var net = require("./lib/net");
var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Selection = require("./selection").Selection;
var TextMode = require("./mode/text").Mode;

View file

@ -301,10 +301,10 @@ if (window.postMessage && !useragent.isOldIE) {
exports.nextFrame = window.requestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame;
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame;
if (exports.nextFrame)
exports.nextFrame = exports.nextFrame.bind(window);

View file

@ -8,12 +8,10 @@
define(function(require, exports, module) {
"use strict";
var useragent = require("./useragent");
exports.get = function (url, callback) {
var xhr = exports.createXhr();
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function (evt) {
xhr.onreadystatechange = function () {
//Do not explicitly handle errors, those should be
//visible via console output in the browser.
if (xhr.readyState === 4) {
@ -23,47 +21,19 @@ exports.get = function (url, callback) {
xhr.send(null);
};
var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
exports.createXhr = function() {
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
var xhr, i, progId;
if (typeof XMLHttpRequest !== "undefined") {
return new XMLHttpRequest();
} else {
for (i = 0; i < 3; i++) {
progId = progIds[i];
try {
xhr = new ActiveXObject(progId);
} catch (e) {}
if (xhr) {
progIds = [progId]; // so faster next time
break;
}
}
}
if (!xhr) {
throw new Error("createXhr(): XMLHttpRequest not available");
}
return xhr;
};
exports.loadScript = function(path, callback) {
var head = document.getElementsByTagName('head')[0];
var head = document.head || document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.src = path;
head.appendChild(s);
if (useragent.isOldIE)
if (s.onload !== undefined)
s.onload = callback;
else
s.onreadystatechange = function () {
this.readyState == 'loaded' && callback();
};
else
s.onload = callback;
};
});

View file

@ -36,7 +36,6 @@ var dom = require("./lib/dom");
var event = require("./lib/event");
var useragent = require("./lib/useragent");
var config = require("./config");
var net = require("./lib/net");
var GutterLayer = require("./layer/gutter").Gutter;
var MarkerLayer = require("./layer/marker").Marker;
var TextLayer = require("./layer/text").Text;