functional browser based parsing + css node creation

This commit is contained in:
cloudhead 2010-03-23 01:16:59 -04:00
parent 3287a6ce2c
commit a2133e4b78

View File

@ -4,11 +4,18 @@
var sheets = document.querySelectorAll("link[rel=less]");
for (var i = 0; i < sheets.length; i++) {
xhr(sheets[i].href, function (data) {
new(less.Parser)({ optimization: 3 }).parse(data, function (e, root) {
document.styleSheets[0].insertRule(root.toCSS());
(function (sheet) { // Because the functions here are async, we need to create a closure
xhr(sheet.href, function (data) {
new(less.Parser)({ optimization: 3 }).parse(data, function (e, root) {
var css = document.createElement('style');
css.type = 'text/css';
css.media = 'screen';
css.title = sheet.title || sheet.href.match(/\/([-\w]+)\.[a-z]+$/i)[1];
css.innerHTML = root.toCSS();
document.getElementsByTagName('head')[0].appendChild(css);
});
});
});
})(sheets[i]);
}
function xhr(url, callback, errback) {