r97275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97274‎ | r97275 | r97276 >
Date:14:31, 16 September 2011
Author:reedy
Status:ok
Tags:
Comment:
REL1_18 MFT r96964
Modified paths:
  • /branches/REL1_18/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/resources/mediawiki/mediawiki.js
@@ -519,28 +519,31 @@
520520 }
521521 // Execute script
522522 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+
531545 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 );
545548 } else if ( $.isFunction( script ) ) {
546549 script( jQuery );
547550 markModuleReady();
@@ -677,7 +680,7 @@
678681 */
679682 function addScript( src, callback ) {
680683 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
682685 // because jQuery will eval the script's code, and errors will not have sane
683686 // line numbers.
684687 var script = document.createElement( 'script' );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96964Address one of the fixmes on r88053: because addScript() is asynchronous, cal...catrope13:55, 13 September 2011

Status & tagging log