created addCSS function in mw.util based on legacy.wikibits
authorKrinkle <krinkle@users.mediawiki.org>
Mon, 8 Nov 2010 18:37:04 +0000 (18:37 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Mon, 8 Nov 2010 18:37:04 +0000 (18:37 +0000)
resources/mediawiki.util/mediawiki.util.js

index abf82c4..6b39967 100644 (file)
                                .replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' );
                },
 
+               /**
+                * Append a new style block to the head
+                *
+                * @param text String CSS to be appended
+                * @return the CSS stylesheet
+                */
+               'addCSS' : function( text ) {
+                       var s = document.createElement( 'style' );
+                       s.type = 'text/css';
+                       s.rel = 'stylesheet';
+                       if ( s.styleSheet ) {
+                               s.styleSheet.cssText = text; // IE
+                       } else {
+                               s.appendChild( document.createTextNode( text + '' ) ); // Safari sometimes borks on null
+                       }
+                       document.getElementsByTagName("head")[0].appendChild( s );
+                       return s.sheet || s;
+               },
+
                /**
                 * Get the full URL to a page name
                 *