8000 browser.js init -- very basic browser support - Makefile also builds … · rusongyu/less.js@823d69f · GitHub
[go: up one dir, main page]

Skip to content

Commit 823d69f

Browse files
author
cloudhead
committed
browser.js init -- very basic browser support - Makefile also builds for browser now
1 parent 0504402 commit 823d69f

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ VERSION = `cat VERSION`
2121

2222
less:
2323
@@mkdir -p build
24-
@@cat ${SRC}/parser.js\
24+
@@cat lib/ext/*.js\
25+
${SRC}/parser.js\
2526
${SRC}/functions.js\
26-
${SRC}/tree/*.js > ${BUILD}
27+
${SRC}/tree/*.js\
28+
${SRC}/browser.js > ${BUILD}
2729
@@echo ${BUILD} built.
2830

2931
min: less

lib/less/browser.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Select all links with the 'rel' attribute set to "less"
3+
//
4+
var sheets = document.querySelectorAll("link[rel=less]");
5+
6+
for (var i = 0; i < sheets.length; i++) {
7+
xhr(sheets[i].href, function (data) {
8+
new(less.Parser)({ optimizations: 3 }).parse(data, function (e, root) {
9+
document.styleSheets[0].insertRule(root.toCSS());
10+
});
11+
});
12+
}
13+
14+
function xhr(url, callback, errback) {
15+
var xhr = new(XMLHttpRequest);
16+
var headers = {
17+
'X-Requested-With': 'XMLHttpRequest',
18+
'Accept': 'text/*'
19+
};
20+
21+
xhr.open('get', url, true);
22+
xhr.onreadystatechange = function () {
23+
if (this.readyState != 4) { return }
24+
25+
if (this.status >= 200 && this.status < 300) {
26+
callback(this.responseText);
27+
} else if (typeof(errback) === 'function') {
28+
errback(this.responseText);
29+
}
30+
};
31+
xhr.send();
32+
}

lib/less/parser.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
if (typeof(require) !== 'undefined') {
2-
var less = exports || {};
2+
var less = exports;
33
var tree = require('less/tree');
4+
} else {
5+
var less = tree = {};
46
}
57
//
68
// less.js - parser

0 commit comments

Comments
 (0)
0