mirror of
https://github.com/less/less.js.git
synced 2026-02-03 19:45:00 -05:00
(new) set watch mode with less.watch() and .unwatch()
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user