From: Trevor Parscal Date: Wed, 15 Sep 2010 22:07:15 +0000 (+0000) Subject: Added importScriptURI/importStylesheetURI-like functionality. X-Git-Tag: 1.31.0-rc.0~34904 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/pie.php?a=commitdiff_plain;h=aaf1fdf3e976daa0d0b261e50a1077ca6a0b8b45;p=lhc%2Fweb%2Fwiklou.git Added importScriptURI/importStylesheetURI-like functionality. --- diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index 24e07878af..feba5764f9 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -652,15 +652,36 @@ window.mediaWiki = new ( function( $ ) { }; /** - * Loads one or more modules for future use + * Loads an external script or one or more modules for future use + * + * @param {mixed} modules either the name of a module, array of modules, or a URL of an external script or style + * @param {string} type mime-type to use if calling with a URL of an external script or style; acceptable values + * are "text/css" and "text/javascript"; if no type is provided, text/javascript is assumed */ - this.load = function( modules ) { + this.load = function( modules, type ) { // Validate input if ( typeof modules !== 'object' && typeof modules !== 'string' ) { throw new Error( 'dependencies must be a string or an array, not a ' + typeof dependencies ) } - // Allow calling with a single dependency as a string + // Allow calling with an external script or single dependency as a string if ( typeof modules === 'string' ) { + // Support adding arbitrary external scripts + if ( modules.substr( 0, 7 ) == 'http://' || modules.substr( 0, 8 ) == 'https://' ) { + if ( type === 'text/css' ) { + setTimeout( function() { + $( 'head' ).append( '' ); + }, 0 ); + return true; + } else if ( type === 'text/javascript' || typeof type === 'undefined' ) { + setTimeout( function() { + $( 'body' ).append( '' ); + }, 0 ); + return true; + } + // Unknown type + return false; + } + // Called with single module modules = [modules]; } // Resolve entire dependency map