From 97fffb3fd0b345db0a8999eda1ffa672311da9f1 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 14 Sep 2019 02:00:55 +0100 Subject: [PATCH] mediawiki.page.ready: Convert to packageFiles, remove jquery.checkboxShiftClick * Remove redundant closures around the two files. * Export checkboxShiftClick as a regular function. This jQuery plugin is not used anywhere in Wikimedia Gerrit, nor elsewhere indexed by Codesearch, nor anywhere on-wiki in User, Project or MediaWiki namespaces. As such, remove the deprecated module alias as well. Change-Id: I6bc41036829964080abf1ab0bbd306356bb8fe57 --- RELEASE-NOTES-1.34 | 2 + resources/Resources.php | 15 +- .../src/mediawiki.page.ready/.eslintrc.json | 5 + .../src/mediawiki.page.ready/checkboxShift.js | 72 ++++----- resources/src/mediawiki.page.ready/ready.js | 143 +++++++++--------- 5 files changed, 113 insertions(+), 124 deletions(-) create mode 100644 resources/src/mediawiki.page.ready/.eslintrc.json diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index 07f52d0c1b..b7eab26c41 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -303,6 +303,8 @@ because of Phabricator reports. * mw.language.specialCharacters, deprecated in 1.33, has been removed. Use require( 'mediawiki.language.specialCharacters' ) instead. * The jquery.colorUtil module was removed. Use jquery.color instead. +* The jquery.checkboxShiftClick module was removed. The functionality + is provided by mediawiki.page.ready instead (T232688). * EditPage::submit(), deprecated in 1.29, has been removed. Use $this->edit() directly. * HTMLForm::getErrors(), deprecated in 1.28, has been removed. Use diff --git a/resources/Resources.php b/resources/Resources.php index bcbe96d68e..c414c7ba9e 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -162,13 +162,6 @@ return [ ], 'targets' => [ 'mobile', 'desktop' ], ], - 'jquery.checkboxShiftClick' => [ - 'deprecated' => 'Please use "mediawiki.page.ready" instead.', - 'dependencies' => [ - 'mediawiki.page.ready', - ], - 'targets' => [ 'desktop', 'mobile' ], - ], 'jquery.chosen' => [ 'scripts' => 'resources/lib/jquery.chosen/chosen.jquery.js', 'styles' => 'resources/lib/jquery.chosen/chosen.css', @@ -1666,9 +1659,11 @@ return [ ] ], 'mediawiki.page.ready' => [ - 'scripts' => [ - 'resources/src/mediawiki.page.ready/checkboxShift.js', - 'resources/src/mediawiki.page.ready/ready.js', + 'localBasePath' => "$IP/resources/src/mediawiki.page.ready", + 'remoteBasePath' => "$wgResourceBasePath/resources/src/mediawiki.page.ready", + 'packageFiles' => [ + 'ready.js', + 'checkboxShift.js', ], 'dependencies' => [ 'mediawiki.util', diff --git a/resources/src/mediawiki.page.ready/.eslintrc.json b/resources/src/mediawiki.page.ready/.eslintrc.json new file mode 100644 index 0000000000..ad8dbb3e85 --- /dev/null +++ b/resources/src/mediawiki.page.ready/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "parserOptions": { + "sourceType": "module" + } +} diff --git a/resources/src/mediawiki.page.ready/checkboxShift.js b/resources/src/mediawiki.page.ready/checkboxShift.js index 435e23f55e..86e0ec2360 100644 --- a/resources/src/mediawiki.page.ready/checkboxShift.js +++ b/resources/src/mediawiki.page.ready/checkboxShift.js @@ -1,43 +1,33 @@ /** - * @class jQuery.plugin.checkboxShiftClick + * @private + * @class mw.plugin.pageready */ -( function () { - - /** - * Enable checkboxes to be checked or unchecked in a row by clicking one, - * holding shift and clicking another one. - * - * @return {jQuery} - * @chainable - */ - $.fn.checkboxShiftClick = function () { - var prevCheckbox = null, - $box = this; - // When our boxes are clicked.. - $box.on( 'click', function ( e ) { - // And one has been clicked before... - if ( prevCheckbox !== null && e.shiftKey ) { - // Check or uncheck this one and all in-between checkboxes, - // except for disabled ones - $box - .slice( - Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ), - Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1 - ) - .filter( function () { - return !this.disabled; - } ) - .prop( 'checked', !!e.target.checked ); - } - // Either way, update the prevCheckbox variable to the one clicked now - prevCheckbox = e.target; - } ); - return $box; - }; - - /** - * @class jQuery - * @mixins jQuery.plugin.checkboxShiftClick - */ - -}() ); +/** + * Enable checkboxes to be checked or unchecked in a row by clicking one, + * holding shift and clicking another one. + * + * @method checkboxShift + * @param {jQuery} $box + */ +module.exports = function ( $box ) { + var prev; + // When our boxes are clicked.. + $box.on( 'click', function ( e ) { + // And one has been clicked before... + if ( prev && e.shiftKey ) { + // Check or uncheck this one and all in-between checkboxes, + // except for disabled ones + $box + .slice( + Math.min( $box.index( prev ), $box.index( e.target ) ), + Math.max( $box.index( prev ), $box.index( e.target ) ) + 1 + ) + .filter( function () { + return !this.disabled; + } ) + .prop( 'checked', e.target.checked ); + } + // Either way, remember this as the last clicked one + prev = e.target; + } ); +}; diff --git a/resources/src/mediawiki.page.ready/ready.js b/resources/src/mediawiki.page.ready/ready.js index 0e59da624b..3226165474 100644 --- a/resources/src/mediawiki.page.ready/ready.js +++ b/resources/src/mediawiki.page.ready/ready.js @@ -1,82 +1,79 @@ -( function () { - mw.hook( 'wikipage.content' ).add( function ( $content ) { - var $sortable, $collapsible; +var checkboxShift = require( './checkboxShift.js' ); +mw.hook( 'wikipage.content' ).add( function ( $content ) { + var $sortable, $collapsible; - $collapsible = $content.find( '.mw-collapsible' ); - if ( $collapsible.length ) { - // Preloaded by Skin::getDefaultModules() - mw.loader.using( 'jquery.makeCollapsible', function () { - $collapsible.makeCollapsible(); - } ); - } + $collapsible = $content.find( '.mw-collapsible' ); + if ( $collapsible.length ) { + // Preloaded by Skin::getDefaultModules() + mw.loader.using( 'jquery.makeCollapsible', function () { + $collapsible.makeCollapsible(); + } ); + } - $sortable = $content.find( 'table.sortable' ); - if ( $sortable.length ) { - // Preloaded by Skin::getDefaultModules() - mw.loader.using( 'jquery.tablesorter', function () { - $sortable.tablesorter(); - } ); - } + $sortable = $content.find( 'table.sortable' ); + if ( $sortable.length ) { + // Preloaded by Skin::getDefaultModules() + mw.loader.using( 'jquery.tablesorter', function () { + $sortable.tablesorter(); + } ); + } - // Run jquery.checkboxShiftClick - $content.find( 'input[type="checkbox"]:not(.noshiftselect)' ).checkboxShiftClick(); - } ); + checkboxShift( $content.find( 'input[type="checkbox"]:not(.noshiftselect)' ) ); +} ); - // Things outside the wikipage content - $( function () { - var $nodes; +// Things outside the wikipage content +$( function () { + var $nodes; - // Add accesskey hints to the tooltips - $( '[accesskey]' ).updateTooltipAccessKeys(); + // Add accesskey hints to the tooltips + $( '[accesskey]' ).updateTooltipAccessKeys(); - $nodes = $( '.catlinks[data-mw="interface"]' ); - if ( $nodes.length ) { - /** - * Fired when categories are being added to the DOM - * - * It is encouraged to fire it before the main DOM is changed (when $content - * is still detached). However, this order is not defined either way, so you - * should only rely on $content itself. - * - * This includes the ready event on a page load (including post-edit loads) - * and when content has been previewed with LivePreview. - * - * @event wikipage_categories - * @member mw.hook - * @param {jQuery} $content The most appropriate element containing the content, - * such as .catlinks - */ - mw.hook( 'wikipage.categories' ).fire( $nodes ); - } + $nodes = $( '.catlinks[data-mw="interface"]' ); + if ( $nodes.length ) { + /** + * Fired when categories are being added to the DOM + * + * It is encouraged to fire it before the main DOM is changed (when $content + * is still detached). However, this order is not defined either way, so you + * should only rely on $content itself. + * + * This includes the ready event on a page load (including post-edit loads) + * and when content has been previewed with LivePreview. + * + * @event wikipage_categories + * @member mw.hook + * @param {jQuery} $content The most appropriate element containing the content, + * such as .catlinks + */ + mw.hook( 'wikipage.categories' ).fire( $nodes ); + } - $( '#t-print a' ).on( 'click', function ( e ) { - window.print(); - e.preventDefault(); - } ); - - // Turn logout to a POST action - $( '#pt-logout a' ).on( 'click', function ( e ) { - var api = new mw.Api(), - returnUrl = $( '#pt-logout a' ).attr( 'href' ); - mw.notify( - mw.message( 'logging-out-notify' ), - { tag: 'logout', autoHide: false } - ); - api.postWithToken( 'csrf', { - action: 'logout' - } ).then( - function () { - location.href = returnUrl; - }, - function ( e ) { - mw.notify( - mw.message( 'logout-failed', e ), - { type: 'error', tag: 'logout', autoHide: false } - ); - } - ); - e.preventDefault(); - } ); + $( '#t-print a' ).on( 'click', function ( e ) { + window.print(); + e.preventDefault(); } ); -}() ); + // Turn logout to a POST action + $( '#pt-logout a' ).on( 'click', function ( e ) { + var api = new mw.Api(), + returnUrl = $( '#pt-logout a' ).attr( 'href' ); + mw.notify( + mw.message( 'logging-out-notify' ), + { tag: 'logout', autoHide: false } + ); + api.postWithToken( 'csrf', { + action: 'logout' + } ).then( + function () { + location.href = returnUrl; + }, + function ( e ) { + mw.notify( + mw.message( 'logout-failed', e ), + { type: 'error', tag: 'logout', autoHide: false } + ); + } + ); + e.preventDefault(); + } ); +} ); -- 2.20.1