},
/**
- * Add (does not replace) parameters for `N$` placeholder values.
+ * Add (does not replace) parameters for `$N` placeholder values.
*
* @param {Array} parameters
* @chainable
cssBuffer = '',
cssBufferTimer = null,
cssCallbacks = $.Callbacks(),
- isIEto9 = 'documentMode' in document && document.documentMode <= 9,
isIE9 = document.documentMode === 9;
function getMarker() {
*/
function newStyleTag( text, nextNode ) {
var s = document.createElement( 'style' );
- // Support: IE
- // Must attach style element to the document before setting cssText (T35305)
+
+ s.appendChild( document.createTextNode( text ) );
if ( nextNode && nextNode.parentNode ) {
nextNode.parentNode.insertBefore( s, nextNode );
} else {
document.getElementsByTagName( 'head' )[ 0 ].appendChild( s );
}
- if ( s.styleSheet ) {
- // Support: IE6-10
- // Old IE ignores appended text nodes, access stylesheet directly.
- s.styleSheet.cssText = text;
- } else {
- // Standard behaviour
- s.appendChild( document.createTextNode( text ) );
- }
+
return s;
}
* @param {Function} [callback]
*/
function addEmbeddedCSS( cssText, callback ) {
- var $style, styleEl, newCssText;
+ var $style, styleEl;
function fireCallbacks() {
var oldCallbacks = cssCallbacks;
//
// Support: IE 6-9
// Try to re-use existing <style> tags due to the IE stylesheet limit (T33676).
- if ( isIEto9 ) {
+ if ( isIE9 ) {
$style = $( getMarker() ).prev();
// Verify that the element before the marker actually is a <style> tag created
// by mw.loader (not some other style tag, or e.g. a <meta> tag).
if ( $style.data( 'ResourceLoaderDynamicStyleTag' ) ) {
styleEl = $style[ 0 ];
- // Support: IE 6-10
- if ( styleEl.styleSheet ) {
- try {
- // Support: IE 9
- // We can't do styleSheet.cssText += cssText in IE9 because it mangles cssText on
- // write (removes @media queries). If we read it and used its value, we'd
- // accidentally apply @media-specific styles to all media. (T108727)
- if ( isIE9 ) {
- newCssText = $style.data( 'ResourceLoaderDynamicStyleTag' ) + cssText;
- styleEl.styleSheet.cssText = newCssText;
- $style.data( 'ResourceLoaderDynamicStyleTag', newCssText );
- } else {
- styleEl.styleSheet.cssText += cssText;
- }
- } catch ( e ) {
- mw.track( 'resourceloader.exception', { exception: e, source: 'stylesheet' } );
- }
- } else {
- styleEl.appendChild( document.createTextNode( cssText ) );
- }
+ styleEl.appendChild( document.createTextNode( cssText ) );
fireCallbacks();
return;
}
$style = $( newStyleTag( cssText, getMarker() ) );
- if ( isIEto9 ) {
- if ( isIE9 ) {
- $style.data( 'ResourceLoaderDynamicStyleTag', cssText );
- } else {
- $style.data( 'ResourceLoaderDynamicStyleTag', true );
- }
+ if ( isIE9 ) {
+ $style.data( 'ResourceLoaderDynamicStyleTag', true );
}
fireCallbacks();
*/
function addLink( media, url ) {
var el = document.createElement( 'link' );
- // Support: IE
- // Insert in document *before* setting href
- $( getMarker() ).before( el );
+
el.rel = 'stylesheet';
if ( media && media !== 'all' ) {
el.media = media;
// If you end up here from an IE exception "SCRIPT: Invalid property value.",
// see #addEmbeddedCSS, bug 31676, and bug 47277 for details.
el.href = url;
+
+ $( getMarker() ).before( el );
}
/**
}
return;
}
- // Validate input
- if ( typeof module !== 'string' ) {
- throw new Error( 'module must be a string, not a ' + typeof module );
- }
if ( hasOwn.call( registry, module ) ) {
throw new Error( 'module already registered: ' + module );
}
* @param {Object} [templates] List of key/value pairs to be added to mw#templates.
*/
implement: function ( module, script, style, messages, templates ) {
- // Validate input
- if ( typeof module !== 'string' ) {
- throw new Error( 'module must be of type string, not ' + typeof module );
- }
- if ( script && !$.isFunction( script ) && !$.isArray( script ) && typeof script !== 'string' ) {
- throw new Error( 'script must be of type function, array, or script; not ' + typeof script );
- }
- if ( style && !$.isPlainObject( style ) ) {
- throw new Error( 'style must be of type object, not ' + typeof style );
- }
- if ( messages && !$.isPlainObject( messages ) ) {
- throw new Error( 'messages must be of type object, not a ' + typeof messages );
- }
- if ( templates && !$.isPlainObject( templates ) ) {
- throw new Error( 'templates must be of type object, not a ' + typeof templates );
- }
// Automatically register module
if ( !hasOwn.call( registry, module ) ) {
mw.loader.register( module );
* OO.compare( [ 1 ], [ 1 ] );
* } );
*
- * @param {string|Array} dependencies Module name or array of modules names the callback
- * dependends on to be ready before executing
+ * @param {string|Array} dependencies Module name or array of modules names the
+ * callback depends on to be ready before executing
* @param {Function} [ready] Callback to execute when all dependencies are ready
* @param {Function} [error] Callback to execute if one or more dependencies failed
* @return {jQuery.Promise}
// Allow calling with a single dependency as a string
if ( typeof dependencies === 'string' ) {
dependencies = [ dependencies ];
- } else if ( !$.isArray( dependencies ) ) {
- // Invalid input
- throw new Error( 'Dependencies must be a string or an array' );
}
if ( ready ) {
load: function ( modules, type ) {
var filtered, l;
- // Validate input
- if ( typeof modules !== 'object' && typeof modules !== 'string' ) {
- throw new Error( 'modules must be a string or an array, not a ' + typeof modules );
- }
// Allow calling with a url or single dependency as a string
if ( typeof modules === 'string' ) {
// "https://example.org/x.js", "http://example.org/x.js", "//example.org/x.js", "/x.js"
require: function ( moduleName ) {
var state = mw.loader.getState( moduleName );
- // Only ready mudules can be required
+ // Only ready modules can be required
if ( state !== 'ready' ) {
// Module may've forgotten to declare a dependency
throw new Error( 'Module "' + moduleName + '" is not loaded.' );