From 93edde50d251fdea7d90d3cd57ecc467193db5fd Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 23 May 2010 12:11:14 +0800 Subject: [PATCH] Fix for IE6 compatibility --- lib/less/browser.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/less/browser.js b/lib/less/browser.js index 64f67b9f..e09008ba 100644 --- a/lib/less/browser.js +++ b/lib/less/browser.js @@ -62,7 +62,7 @@ function createCSS(styles, sheet, lastModified) { } function xhr(url, callback, errback) { - var xhr = new(XMLHttpRequest); + var xhr = getXMLHttpRequest(); if (window.location.protocol === "file:") { xhr.open('GET', url, false); @@ -75,12 +75,12 @@ function xhr(url, callback, errback) { } else { xhr.open('GET', url, true); xhr.onreadystatechange = function () { - if (this.readyState == 4) { - if (this.status >= 200 && this.status < 300) { - callback(this.responseText, - this.getResponseHeader("Last-Modified")); + if (xhr.readyState == 4) { + if (xhr.status >= 200 && xhr.status < 300) { + callback(xhr.responseText, + xhr.getResponseHeader("Last-Modified")); } else if (typeof(errback) === 'function') { - errback(this.responseText); + errback(xhr.responseText); } } }; @@ -88,6 +88,18 @@ function xhr(url, callback, errback) { } } +function getXMLHttpRequest() { + if (window.XMLHttpRequest) { + return new(XMLHttpRequest); + } else { + try { + return new(ActiveXObject)("MSXML2.XMLHTTP.3.0"); + } catch(ex) { + return null; + } + } +} + function log(str) { if (less.env == 'development' && typeof(console) !== "undefined") { console.log(str) } }