Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -391,21 +391,34 @@ |
392 | 392 | } |
393 | 393 | |
394 | 394 | function addInlineCSS( css, media ) { |
395 | | - var $style = getMarker().prev(); |
| 395 | + var $style = getMarker().prev(), |
| 396 | + $newStyle, |
| 397 | + attrs = { 'type': 'text/css', 'media': media }; |
396 | 398 | if ( $style.is( 'style' ) && $style.data( 'ResourceLoaderDynamicStyleTag' ) === true ) { |
397 | 399 | // There's already a dynamic <style> tag present, append to it |
398 | 400 | // This recycling of <style> tags is for bug 31676 (can't have |
399 | 401 | // more than 32 <style> tags in IE) |
400 | 402 | |
401 | | - // Do cdata sanitization on the provided CSS, and prepend a double newline |
402 | | - css = $( mw.html.element( 'style', {}, new mw.html.Cdata( "\n\n" + css ) ) ).html(); |
403 | | - $style.append( css ); |
| 403 | + // Also, calling .append() on a <style> tag explodes with a JS error in IE, |
| 404 | + // so if the .append() fails we fall back to building a new <style> tag and |
| 405 | + // replacing the existing one |
| 406 | + try { |
| 407 | + // Do cdata sanitization on the provided CSS, and prepend a double newline |
| 408 | + css = $( mw.html.element( 'style', {}, new mw.html.Cdata( "\n\n" + css ) ) ).html(); |
| 409 | + $style.append( css ); |
| 410 | + } catch ( e ) { |
| 411 | + // Generate a new tag with the combined CSS |
| 412 | + css = $style.html() + "\n\n" + css; |
| 413 | + $newStyle = $( mw.html.element( 'style', attrs, new mw.html.Cdata( css ) ) ) |
| 414 | + .data( 'ResourceLoaderDynamicStyleTag', true ); |
| 415 | + // Prevent a flash of unstyled content by inserting the new tag |
| 416 | + // before removing the old one |
| 417 | + $style.after( $newStyle ); |
| 418 | + $style.remove(); |
| 419 | + } |
404 | 420 | } else { |
405 | 421 | // Create a new <style> tag and insert it |
406 | | - $style = $( mw.html.element( 'style', { |
407 | | - 'type': 'text/css', |
408 | | - 'media': media |
409 | | - }, new mw.html.Cdata( css ) ) ); |
| 422 | + $style = $( mw.html.element( 'style', attrs, new mw.html.Cdata( css ) ) ); |
410 | 423 | $style.data( 'ResourceLoaderDynamicStyleTag', true ); |
411 | 424 | getMarker().before( $style ); |
412 | 425 | } |