browser.js init -- very basic browser support - Makefile also builds for browser now

This commit is contained in:
cloudhead
2010-03-22 23:12:58 -04:00
parent 05044028cf
commit 823d69fd67
3 changed files with 39 additions and 3 deletions

View File

@@ -21,9 +21,11 @@ VERSION = `cat VERSION`
less:
@@mkdir -p build
@@cat ${SRC}/parser.js\
@@cat lib/ext/*.js\
${SRC}/parser.js\
${SRC}/functions.js\
${SRC}/tree/*.js > ${BUILD}
${SRC}/tree/*.js\
${SRC}/browser.js > ${BUILD}
@@echo ${BUILD} built.
min: less

32
lib/less/browser.js Normal file
View File

@@ -0,0 +1,32 @@
//
// Select all links with the 'rel' attribute set to "less"
//
var sheets = document.querySelectorAll("link[rel=less]");
for (var i = 0; i < sheets.length; i++) {
xhr(sheets[i].href, function (data) {
new(less.Parser)({ optimizations: 3 }).parse(data, function (e, root) {
document.styleSheets[0].insertRule(root.toCSS());
});
});
}
function xhr(url, callback, errback) {
var xhr = new(XMLHttpRequest);
var headers = {
'X-Requested-With': 'XMLHttpRequest',
'Accept': 'text/*'
};
xhr.open('get', url, true);
xhr.onreadystatechange = function () {
if (this.readyState != 4) { return }
if (this.status >= 200 && this.status < 300) {
callback(this.responseText);
} else if (typeof(errback) === 'function') {
errback(this.responseText);
}
};
xhr.send();
}

View File

@@ -1,6 +1,8 @@
if (typeof(require) !== 'undefined') {
var less = exports || {};
var less = exports;
var tree = require('less/tree');
} else {
var less = tree = {};
}
//
// less.js - parser