From 2fccd229d2e8ba11c37b5d5c25a65751a714f3f6 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 7 Mar 2017 20:31:10 -0800 Subject: [PATCH] Skin: Preload jquery.tablesorter based on rough heuristics Whenever a page contains table.sortable, mediawiki/page/ready.js will lazy-load the module. However this can create a significant delay and hides the entire prodecure from our module loader. Instead, do a rough check (similarl to mw-ui-button) and preload the module based on that. Bug: T159911 Change-Id: I87600f968241c723e6bead3ef96c34f1021e1164 --- includes/skins/Skin.php | 8 ++++++++ resources/src/mediawiki/page/ready.js | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 3ef646aec9..c61f5e9c12 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -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() diff --git a/resources/src/mediawiki/page/ready.js b/resources/src/mediawiki/page/ready.js index d228f3e302..860fcf5f22 100644 --- a/resources/src/mediawiki/page/ready.js +++ b/resources/src/mediawiki/page/ready.js @@ -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 ) { @@ -22,11 +22,11 @@ // 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(); } ); } -- 2.20.1