@@ -26,6 +26,7 @@ require("./log-listener")(less, options);
26
26
var errors = require ( "./error-reporting" ) ( window , less , options ) ;
27
27
var browser = require ( "./browser" ) ;
28
28
var cache = options . cache || require ( "./cache" ) ( window , options , less . logger ) ;
29
+ var PromiseConstructor = typeof Promise === 'undefined' ? require ( 'promise' ) : Promise ;
29
30
30
31
options . env = options . env || ( window . location . hostname == '127.0.0.1' ||
31
32
window . location . hostname == '0.0.0.0' ||
@@ -222,16 +223,23 @@ if (/!watch/.test(location.hash)) {
222
223
//
223
224
// Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
224
225
//
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 ( / s t y l e s h e e t / ) &&
233
+ ( links [ i ] . type . match ( typePattern ) ) ) ) {
234
+ less . sheets . push ( links [ i ] ) ;
235
+ }
228
236
229
- for ( var i = 0 ; i < links . length ; i ++ ) {
230
- if ( links [ i ] . rel === 'stylesheet/less' || ( links [ i ] . rel . match ( / s t y l e s h e e t / ) &&
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
+ } ;
235
243
236
244
//
237
245
// With this function, it's possible to alter variables and re-render
@@ -269,4 +277,8 @@ less.refresh = function (reload, modifyVars) {
269
277
270
278
less . refreshStyles = loadStyles ;
271
279
272
- less . refresh ( less . env === 'development' ) ;
280
+ less . registerStylesheets ( ) . then (
281
+ function ( ) {
282
+ less . refresh ( less . env === 'development' ) ;
283
+ }
284
+ ) ;
0 commit comments