Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -652,15 +652,36 @@ |
653 | 653 | }; |
654 | 654 | |
655 | 655 | /** |
656 | | - * Loads one or more modules for future use |
| 656 | + * Loads an external script or one or more modules for future use |
| 657 | + * |
| 658 | + * @param {mixed} modules either the name of a module, array of modules, or a URL of an external script or style |
| 659 | + * @param {string} type mime-type to use if calling with a URL of an external script or style; acceptable values |
| 660 | + * are "text/css" and "text/javascript"; if no type is provided, text/javascript is assumed |
657 | 661 | */ |
658 | | - this.load = function( modules ) { |
| 662 | + this.load = function( modules, type ) { |
659 | 663 | // Validate input |
660 | 664 | if ( typeof modules !== 'object' && typeof modules !== 'string' ) { |
661 | 665 | throw new Error( 'dependencies must be a string or an array, not a ' + typeof dependencies ) |
662 | 666 | } |
663 | | - // Allow calling with a single dependency as a string |
| 667 | + // Allow calling with an external script or single dependency as a string |
664 | 668 | if ( typeof modules === 'string' ) { |
| 669 | + // Support adding arbitrary external scripts |
| 670 | + if ( modules.substr( 0, 7 ) == 'http://' || modules.substr( 0, 8 ) == 'https://' ) { |
| 671 | + if ( type === 'text/css' ) { |
| 672 | + setTimeout( function() { |
| 673 | + $( 'head' ).append( '<link rel="stylesheet" type="text/css" href="' + modules + '" />' ); |
| 674 | + }, 0 ); |
| 675 | + return true; |
| 676 | + } else if ( type === 'text/javascript' || typeof type === 'undefined' ) { |
| 677 | + setTimeout( function() { |
| 678 | + $( 'body' ).append( '<script type="text/javascript" src="' + modules + '"></script>' ); |
| 679 | + }, 0 ); |
| 680 | + return true; |
| 681 | + } |
| 682 | + // Unknown type |
| 683 | + return false; |
| 684 | + } |
| 685 | + // Called with single module |
665 | 686 | modules = [modules]; |
666 | 687 | } |
667 | 688 | // Resolve entire dependency map |