mirror of
https://github.com/less/less.js.git
synced 2026-01-21 05:08:10 -05:00
Merge pull request #2575 from chipx86/fix-sync-loading
Fix synchronously loading/applying stylesheets on page load.
This commit is contained in:
11
lib/less-browser/bootstrap.js
vendored
11
lib/less-browser/bootstrap.js
vendored
@@ -13,14 +13,13 @@ require("./add-default-options")(window, options);
|
||||
|
||||
var less = module.exports = require("./index")(window, options);
|
||||
|
||||
window.less = less;
|
||||
|
||||
if (options.onReady) {
|
||||
if (/!watch/.test(window.location.hash)) {
|
||||
less.watch();
|
||||
}
|
||||
|
||||
less.pageLoadFinished = less.registerStylesheets().then(
|
||||
function () {
|
||||
return less.refresh(less.env === 'development');
|
||||
}
|
||||
);
|
||||
}
|
||||
less.registerStylesheetsImmediately();
|
||||
less.pageLoadFinished = less.refresh(less.env === 'development');
|
||||
}
|
||||
|
||||
@@ -187,20 +187,28 @@ module.exports = function(window, options) {
|
||||
less.unwatch = function () {clearInterval(less.watchTimer); this.watchMode = false; return false; };
|
||||
|
||||
//
|
||||
// Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
|
||||
// Synchronously get all <link> tags with the 'rel' attribute set to
|
||||
// "stylesheet/less".
|
||||
//
|
||||
less.registerStylesheetsImmediately = function() {
|
||||
var links = document.getElementsByTagName('link');
|
||||
less.sheets = [];
|
||||
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
|
||||
(links[i].type.match(typePattern)))) {
|
||||
less.sheets.push(links[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Asynchronously get all <link> tags with the 'rel' attribute set to
|
||||
// "stylesheet/less", returning a Promise.
|
||||
//
|
||||
less.registerStylesheets = function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var links = document.getElementsByTagName('link');
|
||||
less.sheets = [];
|
||||
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
|
||||
(links[i].type.match(typePattern)))) {
|
||||
less.sheets.push(links[i]);
|
||||
}
|
||||
}
|
||||
|
||||
less.registerStylesheetsImmediately();
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user