Merge "Skin: Preload jquery.tablesorter based on rough heuristics"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 15 Mar 2017 17:57:59 +0000 (17:57 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 15 Mar 2017 17:57:59 +0000 (17:57 +0000)
includes/skins/Skin.php
resources/src/mediawiki/page/ready.js

index 3ef646a..c61f5e9 100644 (file)
@@ -149,6 +149,9 @@ abstract class Skin extends ContextSource {
         * Defines the ResourceLoader modules that should be added to the skin
         * It is recommended that skins wishing to override call parent::getDefaultModules()
         * and substitute out any modules they wish to change by using a key to look them up
+        *
+        * For style modules, use setupSkinUserCss() instead.
+        *
         * @return array Array of modules with helper keys for easy overriding
         */
        public function getDefaultModules() {
@@ -171,6 +174,11 @@ abstract class Skin extends ContextSource {
                        'user' => [],
                ];
 
+               // Preload jquery.tablesorter for mediawiki.page.ready
+               if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
+                       $modules['content'][] = 'jquery.tablesorter';
+               }
+
                // Add various resources if required
                if ( $wgUseAjax && $wgEnableAPI ) {
                        if ( $wgEnableWriteAPI && $user->isLoggedIn()
index d228f3e..860fcf5 100644 (file)
@@ -12,7 +12,7 @@
        }
 
        mw.hook( 'wikipage.content' ).add( function ( $content ) {
-               var $sortableTables;
+               var $sortable;
 
                // Run jquery.placeholder polyfill if placeholder is not supported
                if ( !supportsPlaceholder ) {
                // Run jquery.makeCollapsible
                $content.find( '.mw-collapsible' ).makeCollapsible();
 
-               // Lazy load jquery.tablesorter
-               $sortableTables = $content.find( 'table.sortable' );
-               if ( $sortableTables.length ) {
+               $sortable = $content.find( 'table.sortable' );
+               if ( $sortable.length ) {
+                       // Preloaded by Skin::getDefaultModules()
                        mw.loader.using( 'jquery.tablesorter', function () {
-                               $sortableTables.tablesorter();
+                               $sortable.tablesorter();
                        } );
                }