diff --git a/lib/less/browser.js b/lib/less/browser.js index 2811b868..ae5e8b3e 100644 --- a/lib/less/browser.js +++ b/lib/less/browser.js @@ -20,7 +20,10 @@ var readyTimer = setInterval(function () { sheets = (document.querySelectorAll || jQuery).call(document, 'link[rel="stylesheet/less"]'); } clearInterval(readyTimer); - loadStyleSheets(function (sheet, env) { + + loadStyleSheets(function (root, sheet, env) { + createCSS(root.toCSS(), sheet, env.lastModified); + if (env.local) { log("less: loading " + sheet.href + " from local storage."); } else { @@ -36,7 +39,9 @@ var readyTimer = setInterval(function () { if (less.env === 'development') { refreshTimer = setInterval(function () { if (/!refresh/.test(location.hash)) { - loadStyleSheets(function () {}); + loadStyleSheets(function (root, sheet, lastModified) { + createCSS(root.toCSS(), sheet, lastModified); + }); } }, 1000); } @@ -56,19 +61,20 @@ function loadStyleSheet(sheet, callback) { new(Date)(styles.timestamp).valueOf())) { // Use local copy createCSS(styles.css, sheet); - callback(sheet, {local: true}) + callback(null, sheet, { local: true }); } else { // Use remote copy (re-parse) new(less.Parser)({ optimization: 3 }).parse(data, function (e, root) { if (e) { return error(e, sheet.href) } try { - createCSS(root.toCSS(), sheet, lastModified); - callback(sheet, {local: false}) + callback(root, sheet, { local: false, lastModified: lastModified }); } catch (e) { error(e, sheet.href); } }); } + }, function (status) { + throw new(Error)("Couldn't load " + sheet.href + " (" + status + ")"); }); } @@ -104,7 +110,7 @@ function xhr(url, callback, errback) { if (xhr.status === 0) { callback(xhr.responseText); } else { - errback(xhr.responseText); + errback(xhr.status); } } else { xhr.open('GET', url, true); @@ -114,7 +120,7 @@ function xhr(url, callback, errback) { callback(xhr.responseText, xhr.getResponseHeader("Last-Modified")); } else if (typeof(errback) === 'function') { - errback(xhr.responseText); + errback(xhr.status); } } }; @@ -207,4 +213,10 @@ function error(e, href) { } } +less.Parser.importer = function (path, paths, callback) { + loadStyleSheet({ href: path, title: path }, function (root) { + callback(root); + }); +}; + })();