Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -158,7 +158,7 @@ |
159 | 159 | * Client-side module loader which integrates with the MediaWiki ResourceLoader |
160 | 160 | */ |
161 | 161 | this.loader = new ( function() { |
162 | | - |
| 162 | + |
163 | 163 | /* Private Members */ |
164 | 164 | |
165 | 165 | var that = this; |
— | — | @@ -168,7 +168,7 @@ |
169 | 169 | * Format: |
170 | 170 | * { |
171 | 171 | * 'moduleName': { |
172 | | - * 'needs': ['required module', 'required module', ...], |
| 172 | + * 'needs': ['required module', 'required module', ...], (or) function() {} |
173 | 173 | * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error' |
174 | 174 | * 'script': function() {}, |
175 | 175 | * 'style': 'css code string', |
— | — | @@ -193,6 +193,15 @@ |
194 | 194 | */ |
195 | 195 | function recurse( module, resolved, unresolved ) { |
196 | 196 | unresolved[unresolved.length] = module; |
| 197 | + // Resolves dynamic loader function and replaces it with it's own results |
| 198 | + if ( typeof registry[module].needs === 'function' ) { |
| 199 | + registry[module].needs = registry[module].needs(); |
| 200 | + // Gaurantees the module's needs are always in an array |
| 201 | + if ( typeof registry[module].needs !== 'object' ) { |
| 202 | + registry[module].needs = [registry[module].needs]; |
| 203 | + } |
| 204 | + } |
| 205 | + // Tracks down needs |
197 | 206 | for ( var n = 0; n < registry[module].needs.length; n++ ) { |
198 | 207 | if ( resolved.indexOf( registry[module].needs[n] ) === -1 ) { |
199 | 208 | if ( unresolved.indexOf( registry[module].needs[n] ) !== -1 ) { |
— | — | @@ -449,15 +458,11 @@ |
450 | 459 | } |
451 | 460 | // List the module as registered |
452 | 461 | registry[module] = { 'state': typeof status === 'string' ? status : 'registered', 'needs': [] }; |
453 | | - // Allow needs to be given as a function which returns a string or array |
454 | | - if ( typeof needs === 'function' ) { |
455 | | - needs = needs(); |
456 | | - } |
457 | 462 | if ( typeof needs === 'string' ) { |
458 | | - // Allow needs to be given as a single module module |
| 463 | + // Allow needs to be given as a single module name |
459 | 464 | registry[module].needs = [needs]; |
460 | | - } else if ( typeof needs === 'object' ) { |
461 | | - // Allow needs to be given as an array of module modules |
| 465 | + } else if ( typeof needs === 'object' || typeof needs === 'function' ) { |
| 466 | + // Allow needs to be given as an array of module names or a function which returns an array |
462 | 467 | registry[module].needs = needs; |
463 | 468 | } |
464 | 469 | }; |