From: Fomafix Date: Fri, 13 Sep 2019 08:08:20 +0000 (+0200) Subject: Integrate module 'jquery.checkboxShiftClick' into 'mediawiki.page.ready' X-Git-Tag: 1.34.0-rc.0~197^2~1 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/membres//%22%7B%24url%7D?a=commitdiff_plain;h=1490e9dac828af097f0a15eca63eaa89e2d2bc50;p=lhc%2Fweb%2Fwiklou.git Integrate module 'jquery.checkboxShiftClick' into 'mediawiki.page.ready' This reduces the number of modules. Bug: T232688 Change-Id: Id63592d8f674b994adccf5f7f6bbda50d84d0edb --- diff --git a/resources/Resources.php b/resources/Resources.php index 180ed65a43..bcbe96d68e 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -163,7 +163,10 @@ return [ 'targets' => [ 'mobile', 'desktop' ], ], 'jquery.checkboxShiftClick' => [ - 'scripts' => 'resources/src/jquery/jquery.checkboxShiftClick.js', + 'deprecated' => 'Please use "mediawiki.page.ready" instead.', + 'dependencies' => [ + 'mediawiki.page.ready', + ], 'targets' => [ 'desktop', 'mobile' ], ], 'jquery.chosen' => [ @@ -1663,9 +1666,11 @@ return [ ] ], 'mediawiki.page.ready' => [ - 'scripts' => 'resources/src/mediawiki.page.ready.js', + 'scripts' => [ + 'resources/src/mediawiki.page.ready/checkboxShift.js', + 'resources/src/mediawiki.page.ready/ready.js', + ], 'dependencies' => [ - 'jquery.checkboxShiftClick', 'mediawiki.util', 'mediawiki.notify', 'mediawiki.api' diff --git a/resources/src/jquery/jquery.checkboxShiftClick.js b/resources/src/jquery/jquery.checkboxShiftClick.js deleted file mode 100644 index 435e23f55e..0000000000 --- a/resources/src/jquery/jquery.checkboxShiftClick.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * @class jQuery.plugin.checkboxShiftClick - */ -( 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 - */ - -}() ); diff --git a/resources/src/mediawiki.page.ready.js b/resources/src/mediawiki.page.ready.js deleted file mode 100644 index 0e59da624b..0000000000 --- a/resources/src/mediawiki.page.ready.js +++ /dev/null @@ -1,82 +0,0 @@ -( function () { - 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(); - } ); - } - - $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(); - } ); - - // Things outside the wikipage content - $( function () { - var $nodes; - - // 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 ); - } - - $( '#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(); - } ); - } ); - -}() ); diff --git a/resources/src/mediawiki.page.ready/checkboxShift.js b/resources/src/mediawiki.page.ready/checkboxShift.js new file mode 100644 index 0000000000..435e23f55e --- /dev/null +++ b/resources/src/mediawiki.page.ready/checkboxShift.js @@ -0,0 +1,43 @@ +/** + * @class jQuery.plugin.checkboxShiftClick + */ +( 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 + */ + +}() ); diff --git a/resources/src/mediawiki.page.ready/ready.js b/resources/src/mediawiki.page.ready/ready.js new file mode 100644 index 0000000000..0e59da624b --- /dev/null +++ b/resources/src/mediawiki.page.ready/ready.js @@ -0,0 +1,82 @@ +( function () { + 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(); + } ); + } + + $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(); + } ); + + // Things outside the wikipage content + $( function () { + var $nodes; + + // 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 ); + } + + $( '#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(); + } ); + } ); + +}() );