Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -546,22 +546,24 @@ |
547 | 547 | if ( $.isFunction( callback ) ) { |
548 | 548 | callback(); |
549 | 549 | } |
| 550 | + }, |
| 551 | + nestedAddScript = function( arr, callback, i ) { |
| 552 | + // Recursively call addScript() in its own callback |
| 553 | + // for each element of arr. |
| 554 | + if ( i >= arr.length ) { |
| 555 | + // We're at the end of the array |
| 556 | + callback(); |
| 557 | + return; |
| 558 | + } |
| 559 | + |
| 560 | + addScript( arr[i], function() { |
| 561 | + nestedAddScript( arr, callback, i + 1 ); |
| 562 | + } ); |
550 | 563 | }; |
551 | 564 | |
552 | 565 | if ( $.isArray( script ) ) { |
553 | | - var done = 0; |
554 | | - if ( script.length === 0 ) { |
555 | | - // No scripts in this module? Let's dive out early. |
556 | | - markModuleReady(); |
557 | | - } |
558 | | - for ( var i = 0; i < script.length; i++ ) { |
559 | | - registry[module].state = 'loading'; |
560 | | - addScript( script[i], function() { |
561 | | - if ( ++done === script.length ) { |
562 | | - markModuleReady(); |
563 | | - } |
564 | | - } ); |
565 | | - } |
| 566 | + registry[module].state = 'loading'; |
| 567 | + nestedAddScript( script, markModuleReady, 0 ); |
566 | 568 | } else if ( $.isFunction( script ) ) { |
567 | 569 | script( $ ); |
568 | 570 | markModuleReady(); |
— | — | @@ -703,7 +705,7 @@ |
704 | 706 | function addScript( src, callback ) { |
705 | 707 | var done = false, script; |
706 | 708 | if ( ready ) { |
707 | | - // jQuery's getScript method is NOT better than doing this the old-fassioned way |
| 709 | + // jQuery's getScript method is NOT better than doing this the old-fashioned way |
708 | 710 | // because jQuery will eval the script's code, and errors will not have sane |
709 | 711 | // line numbers. |
710 | 712 | script = document.createElement( 'script' ); |