From 16c5d8801e465abd4d6ce7f44a516500a10bcb0d Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 1 Sep 2014 05:29:23 +0000 Subject: [PATCH] mediawiki.util: Deprecate mw.util.updateTooltipAccessKeys Use $nodes.updateTooltipAccessKeys() instead of mw.util.updateTooltipAccessKeys( $nodes ) mw.util.updateTooltipAccessKeys() with empty parameter to update all nodes is only needed in mediawiki.page.ready.js. Copy that code to mediawiki.page.ready.js. Adapt wikibits.js Change-Id: I300a23e614e5f91fe2f536d958e91a47f6203021 --- resources/Resources.php | 2 +- resources/src/mediawiki.legacy/wikibits.js | 7 +- .../mediawiki.page/mediawiki.page.ready.js | 16 ++++- resources/src/mediawiki/mediawiki.util.js | 66 ++++++++++--------- 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/resources/Resources.php b/resources/Resources.php index 8e907eee60..2f961e6e76 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1175,11 +1175,11 @@ return array( 'mediawiki.page.ready' => array( 'scripts' => 'resources/src/mediawiki.page/mediawiki.page.ready.js', 'dependencies' => array( + 'jquery.accessKeyLabel', 'jquery.checkboxShiftClick', 'jquery.makeCollapsible', 'jquery.placeholder', 'jquery.mw-jump', - 'mediawiki.util', ), 'targets' => array( 'desktop', 'mobile' ), ), diff --git a/resources/src/mediawiki.legacy/wikibits.js b/resources/src/mediawiki.legacy/wikibits.js index 5c6e63b9ee..a403996699 100644 --- a/resources/src/mediawiki.legacy/wikibits.js +++ b/resources/src/mediawiki.legacy/wikibits.js @@ -144,15 +144,18 @@ mw.log.deprecate( win, 'jsMsg', function ( message ) { /** * Misc. utilities * - * @deprecated since 1.17 Use mediawiki.util instead + * @deprecated since 1.17 Use mediawiki.util or jquery.accessKeyLabel instead */ msg = 'Use mediawiki.util instead.'; -mw.log.deprecate( win, 'updateTooltipAccessKeys', mw.util.updateTooltipAccessKeys, msg ); mw.log.deprecate( win, 'addPortletLink', mw.util.addPortletLink, msg ); mw.log.deprecate( win, 'appendCSS', mw.util.addCSS, msg ); msg = 'Use jquery.accessKeyLabel instead.'; mw.log.deprecate( win, 'tooltipAccessKeyPrefix', 'alt-', msg ); mw.log.deprecate( win, 'tooltipAccessKeyRegexp', /\[(alt-)?(.)\]$/, msg ); +// mw.util.updateTooltipAccessKeys already generates a deprecation message. +win.updateTooltipAccessKeys = function () { + return mw.util.updateTooltipAccessKeys.apply( null, arguments ); +}; /** * Wikipage import methods diff --git a/resources/src/mediawiki.page/mediawiki.page.ready.js b/resources/src/mediawiki.page/mediawiki.page.ready.js index a05a054c76..246cc8172a 100644 --- a/resources/src/mediawiki.page/mediawiki.page.ready.js +++ b/resources/src/mediawiki.page/mediawiki.page.ready.js @@ -36,6 +36,7 @@ // Things outside the wikipage content $( function () { + var $nodes; if ( !supportsPlaceholder ) { // Exclude content to avoid hitting it twice for the (first) wikipage content @@ -43,7 +44,20 @@ } // Add accesskey hints to the tooltips - mw.util.updateTooltipAccessKeys(); + if ( document.querySelectorAll ) { + // If we're running on a browser where we can do this efficiently, + // just find all elements that have accesskeys. We can't use jQuery's + // polyfill for the selector since looping over all elements on page + // load might be too slow. + $nodes = $( document.querySelectorAll( '[accesskey]' ) ); + } else { + // Otherwise go through some elements likely to have accesskeys rather + // than looping over all of them. Unfortunately this will not fully + // work for custom skins with different HTML structures. Input, label + // and button should be rare enough that no optimizations are needed. + $nodes = $( '#column-one a, #mw-head a, #mw-panel a, #p-logo a, input, label, button' ); + } + $nodes.updateTooltipAccessKeys(); } ); diff --git a/resources/src/mediawiki/mediawiki.util.js b/resources/src/mediawiki/mediawiki.util.js index 887885ea50..2662913781 100644 --- a/resources/src/mediawiki/mediawiki.util.js +++ b/resources/src/mediawiki/mediawiki.util.js @@ -169,38 +169,6 @@ return null; }, - /** - * Add the appropriate prefix to the accesskey shown in the tooltip. - * - * If the `$nodes` parameter is given, only those nodes are updated; - * otherwise, depending on browser support, we update either all elements - * with accesskeys on the page or a bunch of elements which are likely to - * have them on core skins. - * - * @param {Array|jQuery} [$nodes] A jQuery object, or array of nodes to update. - */ - updateTooltipAccessKeys: function ( $nodes ) { - if ( !$nodes ) { - if ( document.querySelectorAll ) { - // If we're running on a browser where we can do this efficiently, - // just find all elements that have accesskeys. We can't use jQuery's - // polyfill for the selector since looping over all elements on page - // load might be too slow. - $nodes = $( document.querySelectorAll( '[accesskey]' ) ); - } else { - // Otherwise go through some elements likely to have accesskeys rather - // than looping over all of them. Unfortunately this will not fully - // work for custom skins with different HTML structures. Input, label - // and button should be rare enough that no optimizations are needed. - $nodes = $( '#column-one a, #mw-head a, #mw-panel a, #p-logo a, input, label, button' ); - } - } else if ( !( $nodes instanceof $ ) ) { - $nodes = $( $nodes ); - } - - $nodes.updateTooltipAccessKeys(); - }, - /** * The content wrapper of the skin (e.g. `.mw-body`). * @@ -503,6 +471,40 @@ */ mw.log.deprecate( util, 'tooltipAccessKeyRegexp', /\[(ctrl-)?(option-)?(alt-)?(shift-)?(esc-)?(.)\]$/, 'Use jquery.accessKeyLabel instead.' ); + /** + * Add the appropriate prefix to the accesskey shown in the tooltip. + * + * If the `$nodes` parameter is given, only those nodes are updated; + * otherwise, depending on browser support, we update either all elements + * with accesskeys on the page or a bunch of elements which are likely to + * have them on core skins. + * + * @method updateTooltipAccessKeys + * @param {Array|jQuery} [$nodes] A jQuery object, or array of nodes to update. + * @deprecated since 1.24 Use the module jquery.accessKeyLabel instead. + */ + mw.log.deprecate( util, 'updateTooltipAccessKeys', function ( $nodes ) { + if ( !$nodes ) { + if ( document.querySelectorAll ) { + // If we're running on a browser where we can do this efficiently, + // just find all elements that have accesskeys. We can't use jQuery's + // polyfill for the selector since looping over all elements on page + // load might be too slow. + $nodes = $( document.querySelectorAll( '[accesskey]' ) ); + } else { + // Otherwise go through some elements likely to have accesskeys rather + // than looping over all of them. Unfortunately this will not fully + // work for custom skins with different HTML structures. Input, label + // and button should be rare enough that no optimizations are needed. + $nodes = $( '#column-one a, #mw-head a, #mw-panel a, #p-logo a, input, label, button' ); + } + } else if ( !( $nodes instanceof $ ) ) { + $nodes = $( $nodes ); + } + + $nodes.updateTooltipAccessKeys(); + }, 'Use jquery.accessKeyLabel instead.' ); + /** * Add a little box at the top of the screen to inform the user of * something, replacing any previous message. -- 2.20.1