Let mw.util.addCSS also return a CSSStyleSheet in IE8
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.util.js
index 9c3a8b3..cfc717f 100644 (file)
@@ -13,7 +13,7 @@
                 * (don't call before document ready)
                 */
                init: function () {
-                       var profile, $tocTitle, $tocToggleLink, hideTocCookie;
+                       var profile;
 
                        /* Set tooltipAccessKeyPrefix */
                        profile = $.client.profile();
                        } )();
 
                        // Table of contents toggle
-                       $tocTitle = $( '#toctitle' );
-                       $tocToggleLink = $( '#togglelink' );
-                       // Only add it if there is a TOC and there is no toggle added already
-                       if ( $( '#toc' ).length && $tocTitle.length && !$tocToggleLink.length ) {
-                               hideTocCookie = $.cookie( 'mw_hidetoc' );
+                       mw.hook( 'wikipage.content' ).add( function () {
+                               var $tocTitle, $tocToggleLink, hideTocCookie;
+                               $tocTitle = $( '#toctitle' );
+                               $tocToggleLink = $( '#togglelink' );
+                               // Only add it if there is a TOC and there is no toggle added already
+                               if ( $( '#toc' ).length && $tocTitle.length && !$tocToggleLink.length ) {
+                                       hideTocCookie = $.cookie( 'mw_hidetoc' );
                                        $tocToggleLink = $( '<a href="#" class="internal" id="togglelink"></a>' )
                                                .text( mw.msg( 'hidetoc' ) )
                                                .click( function ( e ) {
                                                        e.preventDefault();
                                                        util.toggleToc( $(this) );
                                                } );
-                               $tocTitle.append(
-                                       $tocToggleLink
-                                               .wrap( '<span class="toctoggle"></span>' )
-                                               .parent()
-                                                       .prepend( '&nbsp;[' )
-                                                       .append( ']&nbsp;' )
-                               );
-
-                               if ( hideTocCookie === '1' ) {
-                                       util.toggleToc( $tocToggleLink );
+                                       $tocTitle.append(
+                                               $tocToggleLink
+                                                       .wrap( '<span class="toctoggle"></span>' )
+                                                       .parent()
+                                                               .prepend( '&nbsp;[' )
+                                                               .append( ']&nbsp;' )
+                                       );
+
+                                       if ( hideTocCookie === '1' ) {
+                                               util.toggleToc( $tocToggleLink );
+                                       }
                                }
-                       }
+                       } );
                },
 
                /* Main body */
                 *     e.g. { action: 'edit' }. Optional.
                 * @return {string} Location for a page with name of `str` or boolean false on error.
                 */
-               wikiGetlink: function ( str, params ) {
+               getUrl: function ( str, params ) {
                        var url = mw.config.get( 'wgArticlePath' ).replace( '$1',
                                util.wikiUrlencode( typeof str === 'string' ? str : mw.config.get( 'wgPageName' ) ) );
                        if ( params && !$.isEmptyObject( params ) ) {
                 */
                addCSS: function ( text ) {
                        var s = mw.loader.addStyleTag( text );
-                       return s.sheet || s;
+                       return s.sheet || s.styleSheet || s;
                },
 
                /**
                }
        };
 
+       /**
+        * @method wikiGetlink
+        * @inheritdoc #getUrl
+        * @deprecated since 1.23 Use #getUrl instead.
+        */
+       mw.log.deprecate( util, 'wikiGetlink', util.getUrl, 'Use mw.util.getUrl instead.' );
+
        mw.util = util;
 
 }( mediaWiki, jQuery ) );