Merge "mediawiki.inspect: add method for grepping loaded modules"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.util.js
index 86f06b8..082f807 100644 (file)
                                // Make sure we don't unset util.$content if it was preset and we don't find anything
                                return util.$content;
                        } )();
-
-                       // Table of contents toggle
-                       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 );
-                                       }
-                               }
-                       } );
                },
 
                /* Main body */
                 * This function returns the styleSheet object for convience (due to cross-browsers
                 * difference as to where it is located).
                 *
-                *     var sheet = mw.util.addCSS('.foobar { display: none; }');
-                *     $(foo).click(function () {
+                *     var sheet = mw.util.addCSS( '.foobar { display: none; }' );
+                *     $( foo ).click( function () {
                 *         // Toggle the sheet on and off
                 *         sheet.disabled = !sheet.disabled;
-                *     });
+                *     } );
                 *
                 * @param {string} text CSS to be appended
                 * @return {CSSStyleSheet} Use .ownerNode to get to the `<style>` element.
                 *  completed (including the animation).
                 * @return {Mixed} Boolean visibility of the toc (true if it's visible)
                 * or Null if there was no table of contents.
+                * @deprecated since 1.23 Use jQuery
                 */
                toggleToc: function ( $toggleLink, callback ) {
-                       var $tocList = $( '#toc ul:first' );
+                       var ret, $tocList = $( '#toc ul:first' );
 
                        // This function shouldn't be called if there's no TOC,
                        // but just in case...
-                       if ( $tocList.length ) {
-                               if ( $tocList.is( ':hidden' ) ) {
-                                       $tocList.slideDown( 'fast', callback );
-                                       $toggleLink.text( mw.msg( 'hidetoc' ) );
-                                       $( '#toc' ).removeClass( 'tochidden' );
-                                       $.cookie( 'mw_hidetoc', null, {
-                                               expires: 30,
-                                               path: '/'
-                                       } );
-                                       return true;
-                               } else {
-                                       $tocList.slideUp( 'fast', callback );
-                                       $toggleLink.text( mw.msg( 'showtoc' ) );
-                                       $( '#toc' ).addClass( 'tochidden' );
-                                       $.cookie( 'mw_hidetoc', '1', {
-                                               expires: 30,
-                                               path: '/'
-                                       } );
-                                       return false;
-                               }
-                       } else {
+                       if ( !$tocList.length ) {
                                return null;
                        }
+                       ret = $tocList.is( ':hidden' );
+                       $toggleLink.click();
+                       $tocList.promise().done( callback );
+                       return ret;
                },
 
                /**
 
                /**
                 * Add the appropriate prefix to the accesskey shown in the tooltip.
-                * If the nodeList parameter is given, only those nodes are updated;
-                * otherwise, all the nodes that will probably have accesskeys by
-                * default are updated.
+                *
+                * If the `$nodes` parameter is given, only those nodes are updated;
+                * otherwise, depending on browser support, we update either all elements
+                * with accesskeys on the page or a bunch of elements which are likely to
+                * have them on core skins.
                 *
                 * @param {Array|jQuery} [$nodes] A jQuery object, or array of nodes to update.
                 */
                updateTooltipAccessKeys: function ( $nodes ) {
                        if ( !$nodes ) {
-                               // Rather than going into a loop of all anchor tags, limit to few elements that
-                               // contain the relevant anchor tags.
-                               // Input and label are rare enough that no such optimization is needed
-                               $nodes = $( '#column-one a, #mw-head a, #mw-panel a, #p-logo a, input, label' );
+                               if ( document.querySelectorAll ) {
+                                       // If we're running on a browser where we can do this efficiently,
+                                       // just find all elements that have accesskeys. We can't use jQuery's
+                                       // polyfill for the selector since looping over all elements on page
+                                       // load might be too slow.
+                                       $nodes = $( document.querySelectorAll( '[accesskey]' ) );
+                               } else {
+                                       // Otherwise go through some elements likely to have accesskeys rather
+                                       // than looping over all of them. Unfortunately this will not fully
+                                       // work for custom skins with different HTML structures. Input, label
+                                       // and button should be rare enough that no optimizations are needed.
+                                       $nodes = $( '#column-one a, #mw-head a, #mw-panel a, #p-logo a, input, label, button' );
+                               }
                        } else if ( !( $nodes instanceof $ ) ) {
                                $nodes = $( $nodes );
                        }
                        // the ABNF:
                        //      1 * ( atext / "." ) "@" ldh-str 1*( "." ldh-str )
                        // With:
-                       // - atext      : defined in RFC 5322 section 3.2.3
+                       // - atext   : defined in RFC 5322 section 3.2.3
                        // - ldh-str : defined in RFC 1034 section 3.5
                        //
                        // (see STD 68 / RFC 5234 http://tools.ietf.org/html/std68)
                                // RegExp is case insensitive
                                'i'
                        );
-                       return (null !== mailtxt.match( html5EmailRegexp ) );
+                       return ( null !== mailtxt.match( html5EmailRegexp ) );
                },
 
                /**