From 95173d11f1e9048b2d9b761d469d15622d53315f Mon Sep 17 00:00:00 2001 From: Krinkle Date: Wed, 22 Jun 2011 21:27:12 +0000 Subject: [PATCH] New mediawiki.page modules First step towards cleaning up mw.util.init and removing bugus dependancies on mediawiki.util which are just added there in order to load them on every page and do something on-load. Introducing mediawiki.page.startup (in the head) and mediawiki.page.ready (on the bottom) Moved the following to them: * document.ready from jquery.cient -- Shouldn't have been in the plugin itself in the first place * jquery.placeholder * jquery.makeCollapsible * mediawiki.action.view.tablesorting * jquery.checkboxShiftClick (This also solves part of bug 26799) --- includes/OutputPage.php | 7 ++++++- resources/Resources.php | 21 +++++++++++++------ resources/jquery/jquery.client.js | 10 --------- .../mediawiki.action.view.tablesorting.js | 9 -------- .../mediawiki.page/mediawiki.page.ready.js | 21 +++++++++++++++++++ .../mediawiki.page/mediawiki.page.startup.js | 13 ++++++++++++ resources/mediawiki/mediawiki.util.js | 11 ---------- tests/qunit/index.html | 15 +++++++------ 8 files changed, 64 insertions(+), 43 deletions(-) delete mode 100644 resources/mediawiki.action/mediawiki.action.view.tablesorting.js create mode 100644 resources/mediawiki.page/mediawiki.page.ready.js create mode 100644 resources/mediawiki.page/mediawiki.page.startup.js diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 48ee31d3d7..36b17aba86 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2359,7 +2359,12 @@ $templates $wgUseAjax, $wgAjaxWatch, $wgEnableMWSuggest; // Add base resources - $this->addModules( array( 'mediawiki.user', 'mediawiki.util', 'mediawiki.action.view.tablesorting' ) ); + $this->addModules( array( + 'mediawiki.user', + 'mediawiki.util', + 'mediawiki.page.startup', + 'mediawiki.page.ready', + ) ); if ( $wgIncludeLegacyJavaScript ){ $this->addModules( 'mediawiki.legacy.wikibits' ); } diff --git a/resources/Resources.php b/resources/Resources.php index 25c13cec2b..38965c5e40 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -448,16 +448,28 @@ return array( 'jquery.cookie', ), ), + 'mediawiki.page.startup' => array( + 'scripts' => 'resources/mediawiki.page/mediawiki.page.startup.js', + 'dependencies' => array( + 'jquery.client', + ), + 'position' => 'top', + ), + 'mediawiki.page.ready' => array( + 'scripts' => 'resources/mediawiki.page/mediawiki.page.ready.js', + 'dependencies' => array( + 'jquery.checkboxShiftClick', + 'jquery.makeCollapsible', + 'jquery.placeholder', + ), + ), 'mediawiki.util' => array( 'scripts' => 'resources/mediawiki/mediawiki.util.js', 'dependencies' => array( - 'jquery.checkboxShiftClick', 'jquery.client', 'jquery.cookie', 'jquery.messageBox', - 'jquery.makeCollapsible', 'jquery.mwPrototypes', - 'jquery.placeholder', ), ), 'mediawiki.libs.jpegmeta' => array( @@ -482,9 +494,6 @@ return array( 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.metadata.js', 'messages' => array( 'metadata-expand', 'metadata-collapse' ), ), - 'mediawiki.action.view.tablesorting' => array( - 'scripts' => 'resources/mediawiki.action/mediawiki.action.view.tablesorting.js', - ), 'mediawiki.action.watch.ajax' => array( 'scripts' => 'resources/mediawiki.action/mediawiki.action.watch.ajax.js', 'messages' => array( diff --git a/resources/jquery/jquery.client.js b/resources/jquery/jquery.client.js index 2681b60f29..c6edff53b5 100644 --- a/resources/jquery/jquery.client.js +++ b/resources/jquery/jquery.client.js @@ -202,14 +202,4 @@ return true; } }; - - $( document ).ready( function() { - var profile = $.client.profile(); - $( 'html' ) - .addClass( 'client-' + profile.name ) - .addClass( 'client-' + profile.name + '-' + profile.versionBase ) - .addClass( 'client-' + profile.layout ) - .addClass( 'client-' + profile.platform ); - } ); - } )( jQuery ); diff --git a/resources/mediawiki.action/mediawiki.action.view.tablesorting.js b/resources/mediawiki.action/mediawiki.action.view.tablesorting.js deleted file mode 100644 index 09aefc0974..0000000000 --- a/resources/mediawiki.action/mediawiki.action.view.tablesorting.js +++ /dev/null @@ -1,9 +0,0 @@ -// Lazy load jquery.tablesorter - -( function( $ ) { - if ( $( 'table.sortable' ).length ) { - mw.loader.using( 'jquery.tablesorter', function() { - $( 'table.sortable' ).tablesorter(); - } ); - } -} )( jQuery ); \ No newline at end of file diff --git a/resources/mediawiki.page/mediawiki.page.ready.js b/resources/mediawiki.page/mediawiki.page.ready.js new file mode 100644 index 0000000000..c9f4ad4077 --- /dev/null +++ b/resources/mediawiki.page/mediawiki.page.ready.js @@ -0,0 +1,21 @@ +jQuery( document ).ready( function( $ ) { + + /* Emulate placeholder if not supported by browser */ + if ( !( 'placeholder' in document.createElement( 'input' ) ) ) { + $( 'input[placeholder]' ).placeholder(); + } + + /* Enable makeCollapse */ + $( '.mw-collapsible' ).makeCollapsible(); + + /* Lazy load jquery.tablesorter */ + if ( $( 'table.sortable' ).length ) { + mw.loader.using( 'jquery.tablesorter', function() { + $( 'table.sortable' ).tablesorter(); + }); + } + + /* Enable CheckboxShiftClick */ + $( 'input[type=checkbox]:not(.noshiftselect)' ).checkboxShiftClick(); + +} ); diff --git a/resources/mediawiki.page/mediawiki.page.startup.js b/resources/mediawiki.page/mediawiki.page.startup.js new file mode 100644 index 0000000000..0a8cabf47e --- /dev/null +++ b/resources/mediawiki.page/mediawiki.page.startup.js @@ -0,0 +1,13 @@ +( function( $ ) { + + /* Client profile classes for */ + + var prof = $.client.profile(); + $( 'html' ).addClass( + 'client-' + prof.name + + ' client-' + prof.name + '-' + prof.versionBase + + ' client-' + prof.layout + + ' client-' + prof.platform + ); + +} )( jQuery ); diff --git a/resources/mediawiki/mediawiki.util.js b/resources/mediawiki/mediawiki.util.js index 4eb322464f..1f4d95f693 100644 --- a/resources/mediawiki/mediawiki.util.js +++ b/resources/mediawiki/mediawiki.util.js @@ -57,14 +57,6 @@ mw.util.tooltipAccessKeyPrefix = 'alt-shift-'; } - /* Enable CheckboxShiftClick */ - $( 'input[type=checkbox]:not(.noshiftselect)' ).checkboxShiftClick(); - - /* Emulate placeholder if not supported by browser */ - if ( !( 'placeholder' in document.createElement( 'input' ) ) ) { - $( 'input[placeholder]' ).placeholder(); - } - /* Fill $content var */ if ( $( '#bodyContent' ).length ) { // Vector, Monobook, Chick etc. @@ -86,9 +78,6 @@ mw.util.$content = $( '#content' ); } - /* Enable makeCollapse */ - $( '.mw-collapsible' ).makeCollapsible(); - /* Table of Contents toggle */ var $tocContainer = $( '#toc' ), $tocTitle = $( '#toctitle' ), diff --git a/tests/qunit/index.html b/tests/qunit/index.html index a5a020024d..e3804239c7 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -16,17 +16,20 @@ - - - + + + + + + - + + + - -