Index: branches/REL1_18/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -519,28 +519,31 @@ |
520 | 520 | } |
521 | 521 | // Execute script |
522 | 522 | try { |
523 | | - var script = registry[module].script; |
524 | | - var markModuleReady = function() { |
525 | | - registry[module].state = 'ready'; |
526 | | - handlePending( module ); |
527 | | - if ( $.isFunction( callback ) ) { |
528 | | - callback(); |
529 | | - } |
530 | | - }; |
| 523 | + var script = registry[module].script, |
| 524 | + markModuleReady = function() { |
| 525 | + registry[module].state = 'ready'; |
| 526 | + handlePending( module ); |
| 527 | + if ( $.isFunction( callback ) ) { |
| 528 | + callback(); |
| 529 | + } |
| 530 | + }, |
| 531 | + nestedAddScript = function( arr, callback, i ) { |
| 532 | + // Recursively call addScript() in its own callback |
| 533 | + // for each element of arr. |
| 534 | + if ( i >= arr.length ) { |
| 535 | + // We're at the end of the array |
| 536 | + callback(); |
| 537 | + return; |
| 538 | + } |
| 539 | + |
| 540 | + addScript( arr[i], function() { |
| 541 | + nestedAddScript( arr, callback, i + 1 ); |
| 542 | + } ); |
| 543 | + }; |
| 544 | + |
531 | 545 | if ( $.isArray( script ) ) { |
532 | | - var done = 0; |
533 | | - if ( script.length === 0 ) { |
534 | | - // No scripts in this module? Let's dive out early. |
535 | | - markModuleReady(); |
536 | | - } |
537 | | - for ( var i = 0; i < script.length; i++ ) { |
538 | | - registry[module].state = 'loading'; |
539 | | - addScript( script[i], function() { |
540 | | - if ( ++done == script.length ) { |
541 | | - markModuleReady(); |
542 | | - } |
543 | | - } ); |
544 | | - } |
| 546 | + registry[module].state = 'loading'; |
| 547 | + nestedAddScript( script, markModuleReady, 0 ); |
545 | 548 | } else if ( $.isFunction( script ) ) { |
546 | 549 | script( jQuery ); |
547 | 550 | markModuleReady(); |
— | — | @@ -677,7 +680,7 @@ |
678 | 681 | */ |
679 | 682 | function addScript( src, callback ) { |
680 | 683 | if ( ready ) { |
681 | | - // jQuery's getScript method is NOT better than doing this the old-fassioned way |
| 684 | + // jQuery's getScript method is NOT better than doing this the old-fashioned way |
682 | 685 | // because jQuery will eval the script's code, and errors will not have sane |
683 | 686 | // line numbers. |
684 | 687 | var script = document.createElement( 'script' ); |