Skip to content

Method to scan for and register stylesheets #2233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lib/less-browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require("./log-listener")(less, options);
var errors = require("./error-reporting")(window, less, options);
var browser = require("./browser");
var cache = options.cache || require("./cache")(window, options, less.logger);
var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;

options.env = options.env || (window.location.hostname == '127.0.0.1' ||
window.location.hostname == '0.0.0.0' ||
Expand Down Expand Up @@ -222,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.sheets = [];
less.registerStylesheets = function() {
return new PromiseConstructor(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]);
}
}

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
Expand Down Expand Up @@ -269,4 +275,8 @@ less.refresh = function (reload, modifyVars) {

less.refreshStyles = loadStyles;

less.refresh(less.env === 'development');
less.registerStylesheets().then(
function () {
less.refresh(less.env === 'development');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less.refresh does the actual transformation, so does less.refresh need to return a promise and then this line here returns that so the promises are chained?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, my other PR includes the promise for refresh(). Should I merge it and make the changes you propose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heading out, I'll be back on this on Fri.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll Look later, I can't figure this out on my mobile..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeh I got confused between the 2 pull requests.. thought they were 1...

}
);