mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
browser.js init -- very basic browser support - Makefile also builds for browser now
This commit is contained in:
6
Makefile
6
Makefile
@@ -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
32
lib/less/browser.js
Normal 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();
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user