carto/lib/less/browser.js

33 lines
893 B
JavaScript
Raw Normal View History

//
// 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) {
2010-03-23 11:24:05 +08:00
new(less.Parser)({ optimization: 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();
}