Skip to content

Commit fe474d3

Browse files
committed
fixes rebase conflicts
1 parent c40069e commit fe474d3

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

lib/less-browser/index.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require("./log-listener")(less, options);
2626
var errors = require("./error-reporting")(window, less, options);
2727
var browser = require("./browser");
2828
var cache = options.cache || require("./cache")(window, options, less.logger);
29+
var PromiseConstructor = typeof Promise === 'undefined' ? require('promise') : Promise;
2930

3031
options.env = options.env || (window.location.hostname == '127.0.0.1' ||
3132
window.location.hostname == '0.0.0.0' ||
@@ -222,16 +223,23 @@ if (/!watch/.test(location.hash)) {
222223
//
223224
// Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
224225
//
225-
var links = document.getElementsByTagName('link');
226-
227-
less.sheets = [];
226+
less.registerStylesheets = function(callback) {
227+
return new PromiseConstructor(function(resolve, reject) {
228+
var links = document.getElementsByTagName('link');
229+
less.sheets = [];
230+
231+
for (var i = 0; i < links.length; i++) {
232+
if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
233+
(links[i].type.match(typePattern)))) {
234+
less.sheets.push(links[i]);
235+
}
228236

229-
for (var i = 0; i < links.length; i++) {
230-
if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
231-
(links[i].type.match(typePattern)))) {
232-
less.sheets.push(links[i]);
233-
}
234-
}
237+
if (i === links.length - 1) {
238+
resolve();
239+
}
240+
}
241+
});
242+
};
235243

236244
//
237245
// With this function, it's possible to alter variables and re-render
@@ -269,4 +277,8 @@ less.refresh = function (reload, modifyVars) {
269277

270278
less.refreshStyles = loadStyles;
271279

272-
less.refresh(less.env === 'development');
280+
less.registerStylesheets().then(
281+
function () {
282+
less.refresh(less.env === 'development');
283+
}
284+
);

0 commit comments

Comments
 (0)