mirror of
https://github.com/less/less.js.git
synced 2026-01-22 05:37:56 -05:00
Merge pull request #2233 from levithomason/feature/reload-stylesheets
Method to scan for and register stylesheets
This commit is contained in:
@@ -223,16 +223,21 @@ if (/!watch/.test(location.hash)) {
|
||||
//
|
||||
// Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
|
||||
//
|
||||
var links = document.getElementsByTagName('link');
|
||||
less.registerStylesheets = function() {
|
||||
return new PromiseConstructor(function(resolve, reject) {
|
||||
var links = document.getElementsByTagName('link');
|
||||
less.sheets = [];
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
};
|
||||
|
||||
//
|
||||
// With this function, it's possible to alter variables and re-render
|
||||
@@ -282,4 +287,8 @@ less.refresh = function (reload, modifyVars) {
|
||||
|
||||
less.refreshStyles = loadStyles;
|
||||
|
||||
less.refresh(less.env === 'development');
|
||||
less.registerStylesheets().then(
|
||||
function () {
|
||||
less.refresh(less.env === 'development');
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user