lib/gollum/public/gollum/livepreview/js/ace/lib/ace/lib/net.js in gollum-3.1.2 vs lib/gollum/public/gollum/livepreview/js/ace/lib/ace/lib/net.js in gollum-3.1.3

- old
+ new

@@ -5,65 +5,47 @@ * Available via the MIT or new BSD license. * see: http://github.com/jrburke/requirejs for details */ define(function(require, exports, module) { "use strict"; +var dom = require("./dom"); -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) { callback(xhr.responseText); } }; 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 = dom.getDocumentHead(); var s = document.createElement('script'); s.src = path; head.appendChild(s); - if (useragent.isOldIE) - s.onreadystatechange = function () { - this.readyState == 'loaded' && callback(); - }; - else - s.onload = callback; + s.onload = s.onreadystatechange = function(_, isAbort) { + if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") { + s = s.onload = s.onreadystatechange = null; + if (!isAbort) + callback(); + } + }; }; + +/* + * Convert a url into a fully qualified absolute URL + * This function does not work in IE6 + */ +exports.qualifyURL = function(url) { + var a = document.createElement('a'); + a.href = url; + return a.href; +} });