various improvements to browser.js

This commit is contained in:
cloudhead
2010-06-15 00:56:37 -04:00
parent 0dcc820fe6
commit 3ee89922fc

View File

@@ -15,6 +15,9 @@ less.env = location.hostname == '127.0.0.1' ||
//
less.async = false;
// Interval between watch polls
less.poll = location.protocol == 'file:' ? 1000 : 1500;
//
// Watch mode
//
@@ -29,13 +32,13 @@ if (less.env === 'development') {
}
less.watchTimer = setInterval(function () {
if (less.watchMode) {
loadStyleSheets(function (root, sheet, lastModified) {
loadStyleSheets(function (root, sheet, env) {
if (root) {
createCSS(root.toCSS(), sheet, lastModified);
createCSS(root.toCSS(), sheet, env.lastModified);
}
});
}
}, 1000);
}, less.poll);
} else {
less.optimization = 3;
}
@@ -88,6 +91,7 @@ function loadStyleSheet(sheet, callback, async) {
if (e) { return error(e, sheet.href) }
try {
callback(root, sheet, { local: false, lastModified: lastModified });
removeNode(document.getElementById('less-error-message'));
} catch (e) {
error(e, sheet.href);
}
@@ -122,10 +126,13 @@ function createCSS(styles, sheet, lastModified) {
throw new(Error)("Couldn't reassign styleSheet.cssText.");
}
} else {
if (css.childNodes.length > 0) {
css.removeChild(css.childNodes[0]);
}
css.appendChild(document.createTextNode(styles));
(function (node) {
if (css.childNodes.length > 0) {
css.replaceChild(node, css.firstChild);
} else {
css.appendChild(node);
}
})(document.createTextNode(styles));
}
// Don't update the local store if the file wasn't modified
@@ -175,6 +182,10 @@ function getXMLHttpRequest() {
}
}
function removeNode(node) {
return node && node.parentNode.removeChild(node);
}
function log(str) {
if (less.env == 'development' && typeof(console) !== "undefined") { console.log(str) }
}
@@ -227,13 +238,15 @@ function error(e, href) {
'padding-bottom: 2px;',
'border-bottom: 1px dashed red;',
'}'
].join(''), { title: 'error-message' });
].join('\n'), { title: 'error-message' });
elem.style.cssText = [
"font-family: Arial, sans-serif",
"border: 1px solid #e00",
"background-color: #eee",
"border-radius: 5px",
"-webkit-border-radius: 5px",
"-moz-border-radius: 5px",
"color: #e00",
"padding: 15px",
"margin-bottom: 15px"