mirror of
https://github.com/less/less.js.git
synced 2026-02-03 19:45:00 -05:00
decoupled single stylesheet loading
This commit is contained in:
@@ -43,31 +43,33 @@ if (less.env === 'development') {
|
||||
|
||||
function loadStyleSheets(callback) {
|
||||
for (var i = 0; i < sheets.length; i++) {
|
||||
(function (sheet) { // Because the functions here are async, we need to create a closure
|
||||
var css = typeof(localStorage) !== "undefined" && localStorage.getItem(sheet.href);
|
||||
var styles = css && JSON.parse(css);
|
||||
loadStyleSheet(sheets[i], callback);
|
||||
}
|
||||
}
|
||||
|
||||
xhr(sheet.href, function (data, lastModified) {
|
||||
if (styles && (new(Date)(lastModified).valueOf() ===
|
||||
new(Date)(styles.timestamp).valueOf())) {
|
||||
// Use local copy
|
||||
createCSS(styles.css, sheet);
|
||||
callback(sheet, {local: true})
|
||||
} else {
|
||||
// Use remote copy (re-parse)
|
||||
new(less.Parser)({ optimization: 3 }).parse(data, function (e, root) {
|
||||
if (e) { return error(e, sheet.href) }
|
||||
try {
|
||||
createCSS(root.toCSS(), sheet, lastModified);
|
||||
callback(sheet, {local: false})
|
||||
} catch (e) {
|
||||
error(e, sheet.href);
|
||||
}
|
||||
});
|
||||
function loadStyleSheet(sheet, callback) {
|
||||
var css = typeof(localStorage) !== "undefined" && localStorage.getItem(sheet.href);
|
||||
var styles = css && JSON.parse(css);
|
||||
|
||||
xhr(sheet.href, function (data, lastModified) {
|
||||
if (styles && (new(Date)(lastModified).valueOf() ===
|
||||
new(Date)(styles.timestamp).valueOf())) {
|
||||
// Use local copy
|
||||
createCSS(styles.css, sheet);
|
||||
callback(sheet, {local: true})
|
||||
} else {
|
||||
// Use remote copy (re-parse)
|
||||
new(less.Parser)({ optimization: 3 }).parse(data, function (e, root) {
|
||||
if (e) { return error(e, sheet.href) }
|
||||
try {
|
||||
createCSS(root.toCSS(), sheet, lastModified);
|
||||
callback(sheet, {local: false})
|
||||
} catch (e) {
|
||||
error(e, sheet.href);
|
||||
}
|
||||
});
|
||||
})(sheets[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createCSS(styles, sheet, lastModified) {
|
||||
|
||||
Reference in New Issue
Block a user