Separate execution from definition (mediawiki.util.init)
authorKrinkle <krinkle@users.mediawiki.org>
Fri, 2 Sep 2011 21:17:54 +0000 (21:17 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Fri, 2 Sep 2011 21:17:54 +0000 (21:17 +0000)
* bug 30710

Also makes it easier to do unit testing, this way the module can be included and the test can initialize it if and when it wants to.

resources/Resources.php
resources/mediawiki.page/mediawiki.page.ready.js
resources/mediawiki/mediawiki.util.js

index ef4fb46..6613cb3 100644 (file)
@@ -647,6 +647,7 @@ return array(
                        'jquery.checkboxShiftClick',
                        'jquery.makeCollapsible',
                        'jquery.placeholder',
+                       'mediawiki.util',
                ),
        ),
        'mediawiki.page.startup' => array(
index 370c3a1..783db3e 100644 (file)
@@ -1,5 +1,8 @@
 jQuery( document ).ready( function( $ ) {
 
+       /* Initialize utilities (messageBoxNew, profile, tooltip access keys, TOC etc.) */
+       mw.util.init();
+
        /* Emulate placeholder if not supported by browser */
        if ( !( 'placeholder' in document.createElement( 'input' ) ) ) {
                $( 'input[placeholder]' ).placeholder();
index e8a1777..b8d4e7f 100644 (file)
@@ -6,17 +6,11 @@
        // Local cache and alias
        var util = mw.util = {
 
-               /* Initialisation */
                /**
-                * @var boolean Wether or not already initialised
+                * Initialisation
+                * (don't call before document ready)
                 */
-               'initialised' : false,
                'init' : function() {
-                       if ( this.initialised === false ) {
-                               this.initialised = true;
-
-                               // Following the initialisation after the DOM is ready
-                               $(document).ready( function() {
 
                                        /* Set up $.messageBox */
                                        $.messageBoxNew( {
                                                        $tocToggleLink.click();
                                                }
                                        }
-                               } );
-
-                               return true;
-                       }
-                       return false;
                },
 
                /* Main body */
 
        };
 
-       util.init();
-
 } )( jQuery );