@@ -223,16 +223,28 @@ 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
+ console . log ( 'called register' ) ;
229
+ var links = document . getElementsByTagName ( 'link' ) ;
230
+ less . sheets = [ ] ;
231
+
232
+ for ( var i = 0 ; i < links . length ; i ++ ) {
233
+ console . log ( links [ i ] . rel ) ;
234
+ if ( links [ i ] . rel === 'stylesheet/less' || ( links [ i ] . rel . match ( / s t y l e s h e e t / ) &&
235
+ ( links [ i ] . type . match ( typePattern ) ) ) ) {
236
+ less . sheets . push ( links [ i ] ) ;
237
+ console . log ( less . sheets ) ;
238
+ }
229
239
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
- }
240
+ if ( i === links . length - 1 ) {
241
+ console . log ( i ) ;
242
+ console . log ( 'resolve register' ) ;
243
+ resolve ( ) ;
244
+ }
245
+ }
246
+ } ) ;
247
+ } ;
236
248
237
249
//
238
250
// With this function, it's possible to alter variables and re-render
@@ -243,7 +255,9 @@ less.modifyVars = function(record) {
243
255
} ;
244
256
245
257
less . refresh = function ( reload , modifyVars ) {
258
+ console . log ( 'called refresh' ) ;
246
259
less . hasFinished = new PromiseConstructor ( function ( resolve , reject ) {
260
+ console . log ( 'promising to refresh' ) ;
247
261
var startTime , endTime , totalMilliseconds ;
248
262
startTime = endTime = new Date ( ) ;
249
263
@@ -273,7 +287,7 @@ less.refresh = function (reload, modifyVars) {
273
287
}
274
288
endTime = new Date ( ) ;
275
289
} , reload , modifyVars ) ;
276
-
290
+
277
291
loadStyles ( modifyVars ) ;
278
292
} ) ;
279
293
@@ -282,4 +296,8 @@ less.refresh = function (reload, modifyVars) {
282
296
283
297
less . refreshStyles = loadStyles ;
284
298
285
- less . refresh ( less . env === 'development' ) ;
299
+ less . registerStylesheets ( ) . then (
300
+ function ( ) {
301
+ less . refresh ( less . env === 'development' ) ;
302
+ }
303
+ ) ;
0 commit comments