mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
initial fix in browser.js and a small test addition
This commit is contained in:
@@ -43,7 +43,7 @@ less.watch = function () {
|
||||
less.env = 'development';
|
||||
initRunningMode();
|
||||
}
|
||||
return this.watchMode = true
|
||||
return this.watchMode = true
|
||||
};
|
||||
|
||||
less.unwatch = function () {clearInterval(less.watchTimer); return this.watchMode = false; };
|
||||
@@ -134,9 +134,18 @@ less.refreshStyles = loadStyles;
|
||||
less.refresh(less.env === 'development');
|
||||
|
||||
function loadStyles(newVars) {
|
||||
var styles = document.getElementsByTagName('style');
|
||||
for (var i = 0; i < styles.length; i++) {
|
||||
// returned list of style tags gets updated automatically. because we track
|
||||
// indexes, we need a non-mutating local copy to work with.
|
||||
var nodeList = document.getElementsByTagName('style');
|
||||
var styles = new Array(nodeList.length);
|
||||
var i;
|
||||
// Array.slice not guaranteed to work on host objects, forcing a manual loop
|
||||
for (i = 0; i < nodeList.length; i++) {
|
||||
styles[i] = nodeList[i];
|
||||
}
|
||||
for (i = 0; i < styles.length; i++) {
|
||||
if (styles[i].type.match(typePattern)) {
|
||||
console.log(i);
|
||||
var env = new less.tree.parseEnv(less),
|
||||
lessText = styles[i].innerHTML || '';
|
||||
env.filename = document.location.href.replace(/#.*$/, '');
|
||||
@@ -145,19 +154,23 @@ function loadStyles(newVars) {
|
||||
lessText += "\n" + newVars;
|
||||
}
|
||||
|
||||
new(less.Parser)(env).parse(lessText, function (e, cssAST) {
|
||||
if (e) {
|
||||
return error(e, "inline");
|
||||
// use closure to store current value of i
|
||||
var callback = (function(i) {
|
||||
return function (e, cssAST) {
|
||||
if (e) {
|
||||
return error(e, "inline");
|
||||
}
|
||||
var css = cssAST.toCSS(less);
|
||||
var style = styles[i];
|
||||
style.type = 'text/css';
|
||||
if (style.styleSheet) {
|
||||
style.styleSheet.cssText = css;
|
||||
} else {
|
||||
style.innerHTML = css;
|
||||
}
|
||||
}
|
||||
var css = cssAST.toCSS(less);
|
||||
var style = styles[i];
|
||||
style.type = 'text/css';
|
||||
if (style.styleSheet) {
|
||||
style.styleSheet.cssText = css;
|
||||
} else {
|
||||
style.innerHTML = css;
|
||||
}
|
||||
});
|
||||
})(i);
|
||||
new(less.Parser)(env).parse(lessText, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,7 +220,7 @@ function extractUrlParts(url, baseUrl) {
|
||||
throw new Error("Could not parse sheet href - '"+url+"'");
|
||||
}
|
||||
|
||||
// Stylesheets in IE don't always return the full path
|
||||
// Stylesheets in IE don't always return the full path
|
||||
if (!urlParts[1] || urlParts[2]) {
|
||||
baseUrlParts = baseUrl.match(urlPartsRegex);
|
||||
if (!baseUrlParts) {
|
||||
@@ -218,7 +231,7 @@ function extractUrlParts(url, baseUrl) {
|
||||
urlParts[3] = baseUrlParts[3] + urlParts[3];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (urlParts[3]) {
|
||||
directories = urlParts[3].replace("\\", "/").split("/");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user