@@ -223,16 +223,23 @@ if (/!watch/.test(location.hash)) {
223
223
//
224
224
// Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
225
225
//
226
- var links = document . getElementsByTagName ( 'link' ) ;
227
-
228
- 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 ( / s t y l e s h e e t / ) &&
233
+ ( links [ i ] . type . match ( typePattern ) ) ) ) {
234
+ less . sheets . push ( links [ i ] ) ;
235
+ }
229
236
230
- for ( var i = 0 ; i < links . length ; i ++ ) {
231
- if ( links [ i ] . rel === 'stylesheet/less' || ( links [ i ] . rel . match ( / s t y l e s h e e t / ) &&
232
- ( links [ i ] . type . match ( typePattern ) ) ) ) {
233
- less . sheets . push ( links [ i ] ) ;
234
- }
235
- }
237
+ if ( i === links . length - 1 ) {
238
+ resolve ( ) ;
239
+ }
240
+ }
241
+ } ) ;
242
+ } ;
236
243
237
244
//
238
245
// With this function, it's possible to alter variables and re-render
@@ -273,7 +280,7 @@ less.refresh = function (reload, modifyVars) {
273
280
}
274
281
endTime = new Date ( ) ;
275
282
} , reload , modifyVars ) ;
276
-
283
+
277
284
loadStyles ( modifyVars ) ;
278
285
} ) ;
279
286
@@ -282,4 +289,8 @@ less.refresh = function (reload, modifyVars) {
282
289
283
290
less . refreshStyles = loadStyles ;
284
291
285
- less . refresh ( less . env === 'development' ) ;
292
+ less . registerStylesheets ( ) . then (
293
+ function ( ) {
294
+ less . refresh ( less . env === 'development' ) ;
295
+ }
296
+ ) ;
0 commit comments