From 0a70f66c22333fc117f0fa52a4410b4921922876 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Sat, 18 Jun 2016 15:48:45 -0700 Subject: [PATCH] resourceloader: Simplify CSS loading by removing IE8 hacks * Remove 'isIEto9'. Since we blacklist anything before 9, isIE9 is enough. * Set the content of style tags and the href attribute of link tags before inserting them into the DOM. Previously, we did DOM insertion first, due to T35305. I verified that IE9 is not affected. * Use document.head instead of document.getElementsByTagName( 'head' )[ 0 ]. * Set / extend the contents of link tags via node.appendChild( document.createTextNode( ... ) ) this works in IE9, and adding CSS in this way does not strip @media queries in the way that repeat node.styleSheet.cssText += '...' operations will. This means the workarounds put in place to mitigate T108727 can be removed. quirksmode confirms that document.createTextNode() is supported in IE9, and mentions the issue with style tags as IE8-specific: http://quirksmode.org/dom/core/#t01 I created a test page with all the behaviors here: https://people.wikimedia.org/~ori/If51f8303b/index.html It loads correctly in IE9: https://people.wikimedia.org/~ori/If51f8303b/screenshot.png Change-Id: If51f8303b74fdc8001cfa20ea8b016fdc210b1b1 --- resources/src/mediawiki/mediawiki.js | 53 ++++++---------------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/resources/src/mediawiki/mediawiki.js b/resources/src/mediawiki/mediawiki.js index 1203b6a8f7..348b617cdc 100644 --- a/resources/src/mediawiki/mediawiki.js +++ b/resources/src/mediawiki/mediawiki.js @@ -803,7 +803,6 @@ cssBuffer = '', cssBufferTimer = null, cssCallbacks = $.Callbacks(), - isIEto9 = 'documentMode' in document && document.documentMode <= 9, isIE9 = document.documentMode === 9; function getMarker() { @@ -829,21 +828,14 @@ */ 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; } @@ -858,7 +850,7 @@ * @param {Function} [callback] */ function addEmbeddedCSS( cssText, callback ) { - var $style, styleEl, newCssText; + var $style, styleEl; function fireCallbacks() { var oldCallbacks = cssCallbacks; @@ -908,32 +900,13 @@ // // Support: IE 6-9 // Try to re-use existing