diff --git a/lib/less/browser.js b/lib/less/browser.js index 8e2141a4..a1bb3acf 100644 --- a/lib/less/browser.js +++ b/lib/less/browser.js @@ -10,15 +10,14 @@ less.env = location.hostname == '127.0.0.1' || location.protocol == 'file:' ? 'development' : 'production'; +less.watch = function () { return this.watchMode = true }; +less.unwatch = function () { return this.watchMode = false }; // Load the stylesheets when the body is ready var readyTimer = setInterval(function () { if (document.body) { - if (!document.querySelectorAll && typeof(jQuery) === "undefined") { - log("No selector method found"); - } else { - sheets = (document.querySelectorAll || jQuery).call(document, 'link[rel="stylesheet/less"]'); - } + sheets = select('link[rel="stylesheet/less"]'); + clearInterval(readyTimer); loadStyleSheets(function (root, sheet, env) { @@ -32,12 +31,16 @@ var readyTimer = setInterval(function () { } }, 10); +if (less.env === 'development' && /!refresh/.test(location.hash)) { + less.watchMode = true; +} + // // Auto-refresh // if (less.env === 'development') { refreshTimer = setInterval(function () { - if (/!refresh/.test(location.hash)) { + if (less.watchMode) { loadStyleSheets(function (root, sheet, lastModified) { if (root) { createCSS(root.toCSS(), sheet, lastModified); @@ -47,6 +50,14 @@ if (less.env === 'development') { }, 1000); } +function select(str) { + if (!document.querySelectorAll && typeof(jQuery) === "undefined") { + log("No selector method found"); + } else { + return (document.querySelectorAll || jQuery).call(document, str); + } +} + function loadStyleSheets(callback) { for (var i = 0; i < sheets.length; i++) { loadStyleSheet(sheets[i], callback);