From: jenkins-bot Date: Fri, 6 Sep 2019 17:08:04 +0000 (+0000) Subject: Merge "mediawiki.util: Merge 'jquery.accessKeyLabel' into this module" X-Git-Tag: 1.34.0-rc.0~351 X-Git-Url: http://git.cyclocoop.org//%27http:/jquery.khurshid.com/ifixpng.php/%27?a=commitdiff_plain;h=dd4aa3cfef6c7d28ac94ea199da95e8be8d9414f;hp=ef04853cd7ac35a4e7e4d75d34240657cd9d8c9d;p=lhc%2Fweb%2Fwiklou.git Merge "mediawiki.util: Merge 'jquery.accessKeyLabel' into this module" --- diff --git a/RELEASE-NOTES-1.34 b/RELEASE-NOTES-1.34 index 828d0fb807..a86fa2dd7d 100644 --- a/RELEASE-NOTES-1.34 +++ b/RELEASE-NOTES-1.34 @@ -425,6 +425,8 @@ because of Phabricator reports. * ResourceLoaderContext::getConfig and ResourceLoaderContext::getLogger have been deprecated. Inside ResourceLoaderModule subclasses, use the local methods instead. Elsewhere, use the methods from the ResourceLoader class. +* The 'jquery.accessKeyLabel' module has been deprecated. This jQuery + plugin is now ships as part of the 'mediawiki.util' module bundle. * The Profiler::setTemplated and Profiler::getTemplated methods have been deprecated. Use Profiler::setAllowOutput and Profiler::getAllowOutput instead. diff --git a/resources/Resources.php b/resources/Resources.php index 55bd780a5a..cfcfc19eb3 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -156,12 +156,10 @@ return [ /* jQuery Plugins */ 'jquery.accessKeyLabel' => [ - 'scripts' => 'resources/src/jquery/jquery.accessKeyLabel.js', + 'deprecated' => 'Please use "mediawiki.util" instead.', 'dependencies' => [ - 'jquery.client', - 'mediawiki.RegExp', + 'mediawiki.util', ], - 'messages' => [ 'brackets', 'word-separator' ], 'targets' => [ 'mobile', 'desktop' ], ], 'jquery.checkboxShiftClick' => [ @@ -1252,18 +1250,20 @@ return [ ], 'mediawiki.util' => [ 'localBasePath' => "$IP/resources/src/mediawiki.util/", - 'remoteBasePath' => "$wgResourceBasePath/resources/srcmediawiki.util/", + 'remoteBasePath' => "$wgResourceBasePath/resources/src/mediawiki.util/", 'packageFiles' => [ 'util.js', + 'jquery.accessKeyLabel.js', [ 'name' => 'config.json', 'config' => [ 'FragmentMode', 'LoadScript', ] ], ], 'dependencies' => [ - 'jquery.accessKeyLabel', + 'jquery.client', 'mediawiki.RegExp', ], + 'messages' => [ 'brackets', 'word-separator' ], 'targets' => [ 'desktop', 'mobile' ], ], 'mediawiki.viewport' => [ @@ -1660,8 +1660,8 @@ return [ 'mediawiki.page.ready' => [ 'scripts' => 'resources/src/mediawiki.page.ready.js', 'dependencies' => [ - 'jquery.accessKeyLabel', 'jquery.checkboxShiftClick', + 'mediawiki.util', 'mediawiki.notify', 'mediawiki.api' ], @@ -1699,7 +1699,6 @@ return [ 'mediawiki.util', 'mediawiki.Title', 'mediawiki.jqueryMsg', - 'jquery.accessKeyLabel', 'mediawiki.RegExp', ], 'messages' => [ diff --git a/resources/src/jquery/jquery.accessKeyLabel.js b/resources/src/jquery/jquery.accessKeyLabel.js deleted file mode 100644 index cdc5808ca7..0000000000 --- a/resources/src/jquery/jquery.accessKeyLabel.js +++ /dev/null @@ -1,239 +0,0 @@ -/** - * jQuery plugin to update the tooltip to show the correct access key - * - * @class jQuery.plugin.accessKeyLabel - */ -( function () { - - // Cached access key modifiers for used browser - var cachedAccessKeyModifiers, - - // Whether to use 'test-' instead of correct prefix (used for testing) - useTestPrefix = false, - - // tag names which can have a label tag - // https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Form-associated_content - labelable = 'button, input, textarea, keygen, meter, output, progress, select'; - - /** - * Find the modifier keys that need to be pressed together with the accesskey to trigger the input. - * - * The result is dependant on the ua paramater or the current platform. - * For browsers that support accessKeyLabel, #getAccessKeyLabel never calls here. - * Valid key values that are returned can be: ctrl, alt, option, shift, esc - * - * @private - * @param {Object} [ua] An object with a 'userAgent' and 'platform' property. - * @return {Array} Array with 1 or more of the string values, in this order: ctrl, option, alt, shift, esc - */ - function getAccessKeyModifiers( ua ) { - var profile, accessKeyModifiers; - - // use cached prefix if possible - if ( !ua && cachedAccessKeyModifiers ) { - return cachedAccessKeyModifiers; - } - - profile = $.client.profile( ua ); - - switch ( profile.name ) { - case 'chrome': - case 'opera': - if ( profile.name === 'opera' && profile.versionNumber < 15 ) { - accessKeyModifiers = [ 'shift', 'esc' ]; - } else if ( profile.platform === 'mac' ) { - accessKeyModifiers = [ 'ctrl', 'option' ]; - } else { - // Chrome/Opera on Windows or Linux - // (both alt- and alt-shift work, but alt with E, D, F etc does not - // work since they are browser shortcuts) - accessKeyModifiers = [ 'alt', 'shift' ]; - } - break; - case 'firefox': - case 'iceweasel': - if ( profile.versionBase < 2 ) { - // Before v2, Firefox used alt, though it was rebindable in about:config - accessKeyModifiers = [ 'alt' ]; - } else { - if ( profile.platform === 'mac' ) { - if ( profile.versionNumber < 14 ) { - accessKeyModifiers = [ 'ctrl' ]; - } else { - accessKeyModifiers = [ 'ctrl', 'option' ]; - } - } else { - accessKeyModifiers = [ 'alt', 'shift' ]; - } - } - break; - case 'safari': - case 'konqueror': - if ( profile.platform === 'win' ) { - accessKeyModifiers = [ 'alt' ]; - } else { - if ( profile.layoutVersion > 526 ) { - // Non-Windows Safari with webkit_version > 526 - accessKeyModifiers = [ 'ctrl', profile.platform === 'mac' ? 'option' : 'alt' ]; - } else { - accessKeyModifiers = [ 'ctrl' ]; - } - } - break; - case 'msie': - case 'edge': - accessKeyModifiers = [ 'alt' ]; - break; - default: - accessKeyModifiers = profile.platform === 'mac' ? [ 'ctrl' ] : [ 'alt' ]; - break; - } - - // cache modifiers - if ( !ua ) { - cachedAccessKeyModifiers = accessKeyModifiers; - } - return accessKeyModifiers; - } - - /** - * Get the access key label for an element. - * - * Will use native accessKeyLabel if available (currently only in Firefox 8+), - * falls back to #getAccessKeyModifiers. - * - * @private - * @param {HTMLElement} element Element to get the label for - * @return {string} Access key label - */ - function getAccessKeyLabel( element ) { - // abort early if no access key - if ( !element.accessKey ) { - return ''; - } - // use accessKeyLabel if possible - // https://html.spec.whatwg.org/multipage/interaction.html#dom-accesskeylabel - if ( !useTestPrefix && element.accessKeyLabel ) { - return element.accessKeyLabel; - } - return ( useTestPrefix ? 'test' : getAccessKeyModifiers().join( '-' ) ) + '-' + element.accessKey; - } - - /** - * Update the title for an element (on the element with the access key or it's label) to show - * the correct access key label. - * - * @private - * @param {HTMLElement} element Element with the accesskey - * @param {HTMLElement} titleElement Element with the title to update (may be the same as `element`) - */ - function updateTooltipOnElement( element, titleElement ) { - var oldTitle, parts, regexp, newTitle, accessKeyLabel, - separatorMsg = mw.message( 'word-separator' ).plain(); - - oldTitle = titleElement.title; - if ( !oldTitle ) { - // don't add a title if the element didn't have one before - return; - } - - parts = ( separatorMsg + mw.message( 'brackets' ).plain() ).split( '$1' ); - regexp = new RegExp( parts.map( mw.RegExp.escape ).join( '.*?' ) + '$' ); - newTitle = oldTitle.replace( regexp, '' ); - accessKeyLabel = getAccessKeyLabel( element ); - - if ( accessKeyLabel ) { - // Should be build the same as in Linker::titleAttrib - newTitle += separatorMsg + mw.message( 'brackets', accessKeyLabel ).plain(); - } - if ( oldTitle !== newTitle ) { - titleElement.title = newTitle; - } - } - - /** - * Update the title for an element to show the correct access key label. - * - * @private - * @param {HTMLElement} element Element with the accesskey - */ - function updateTooltip( element ) { - var id, $element, $label, $labelParent; - updateTooltipOnElement( element, element ); - - // update associated label if there is one - $element = $( element ); - if ( $element.is( labelable ) ) { - // Search it using 'for' attribute - id = element.id.replace( /"/g, '\\"' ); - if ( id ) { - $label = $( 'label[for="' + id + '"]' ); - if ( $label.length === 1 ) { - updateTooltipOnElement( element, $label[ 0 ] ); - } - } - - // Search it as parent, because the form control can also be inside the label element itself - $labelParent = $element.parents( 'label' ); - if ( $labelParent.length === 1 ) { - updateTooltipOnElement( element, $labelParent[ 0 ] ); - } - } - } - - /** - * Update the titles for all elements in a jQuery selection. - * - * @return {jQuery} - * @chainable - */ - $.fn.updateTooltipAccessKeys = function () { - return this.each( function () { - updateTooltip( this ); - } ); - }; - - /** - * getAccessKeyModifiers - * - * @method updateTooltipAccessKeys_getAccessKeyModifiers - * @inheritdoc #getAccessKeyModifiers - */ - $.fn.updateTooltipAccessKeys.getAccessKeyModifiers = getAccessKeyModifiers; - - /** - * getAccessKeyLabel - * - * @method updateTooltipAccessKeys_getAccessKeyLabel - * @inheritdoc #getAccessKeyLabel - */ - $.fn.updateTooltipAccessKeys.getAccessKeyLabel = getAccessKeyLabel; - - /** - * getAccessKeyPrefix - * - * @method updateTooltipAccessKeys_getAccessKeyPrefix - * @deprecated since 1.27 Use #getAccessKeyModifiers - * @param {Object} [ua] An object with a 'userAgent' and 'platform' property. - * @return {string} - */ - $.fn.updateTooltipAccessKeys.getAccessKeyPrefix = function ( ua ) { - return getAccessKeyModifiers( ua ).join( '-' ) + '-'; - }; - - /** - * Switch test mode on and off. - * - * @method updateTooltipAccessKeys_setTestMode - * @param {boolean} mode New mode - */ - $.fn.updateTooltipAccessKeys.setTestMode = function ( mode ) { - useTestPrefix = mode; - }; - - /** - * @class jQuery - * @mixins jQuery.plugin.accessKeyLabel - */ - -}() ); diff --git a/resources/src/mediawiki.util/jquery.accessKeyLabel.js b/resources/src/mediawiki.util/jquery.accessKeyLabel.js new file mode 100644 index 0000000000..cdc5808ca7 --- /dev/null +++ b/resources/src/mediawiki.util/jquery.accessKeyLabel.js @@ -0,0 +1,239 @@ +/** + * jQuery plugin to update the tooltip to show the correct access key + * + * @class jQuery.plugin.accessKeyLabel + */ +( function () { + + // Cached access key modifiers for used browser + var cachedAccessKeyModifiers, + + // Whether to use 'test-' instead of correct prefix (used for testing) + useTestPrefix = false, + + // tag names which can have a label tag + // https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Form-associated_content + labelable = 'button, input, textarea, keygen, meter, output, progress, select'; + + /** + * Find the modifier keys that need to be pressed together with the accesskey to trigger the input. + * + * The result is dependant on the ua paramater or the current platform. + * For browsers that support accessKeyLabel, #getAccessKeyLabel never calls here. + * Valid key values that are returned can be: ctrl, alt, option, shift, esc + * + * @private + * @param {Object} [ua] An object with a 'userAgent' and 'platform' property. + * @return {Array} Array with 1 or more of the string values, in this order: ctrl, option, alt, shift, esc + */ + function getAccessKeyModifiers( ua ) { + var profile, accessKeyModifiers; + + // use cached prefix if possible + if ( !ua && cachedAccessKeyModifiers ) { + return cachedAccessKeyModifiers; + } + + profile = $.client.profile( ua ); + + switch ( profile.name ) { + case 'chrome': + case 'opera': + if ( profile.name === 'opera' && profile.versionNumber < 15 ) { + accessKeyModifiers = [ 'shift', 'esc' ]; + } else if ( profile.platform === 'mac' ) { + accessKeyModifiers = [ 'ctrl', 'option' ]; + } else { + // Chrome/Opera on Windows or Linux + // (both alt- and alt-shift work, but alt with E, D, F etc does not + // work since they are browser shortcuts) + accessKeyModifiers = [ 'alt', 'shift' ]; + } + break; + case 'firefox': + case 'iceweasel': + if ( profile.versionBase < 2 ) { + // Before v2, Firefox used alt, though it was rebindable in about:config + accessKeyModifiers = [ 'alt' ]; + } else { + if ( profile.platform === 'mac' ) { + if ( profile.versionNumber < 14 ) { + accessKeyModifiers = [ 'ctrl' ]; + } else { + accessKeyModifiers = [ 'ctrl', 'option' ]; + } + } else { + accessKeyModifiers = [ 'alt', 'shift' ]; + } + } + break; + case 'safari': + case 'konqueror': + if ( profile.platform === 'win' ) { + accessKeyModifiers = [ 'alt' ]; + } else { + if ( profile.layoutVersion > 526 ) { + // Non-Windows Safari with webkit_version > 526 + accessKeyModifiers = [ 'ctrl', profile.platform === 'mac' ? 'option' : 'alt' ]; + } else { + accessKeyModifiers = [ 'ctrl' ]; + } + } + break; + case 'msie': + case 'edge': + accessKeyModifiers = [ 'alt' ]; + break; + default: + accessKeyModifiers = profile.platform === 'mac' ? [ 'ctrl' ] : [ 'alt' ]; + break; + } + + // cache modifiers + if ( !ua ) { + cachedAccessKeyModifiers = accessKeyModifiers; + } + return accessKeyModifiers; + } + + /** + * Get the access key label for an element. + * + * Will use native accessKeyLabel if available (currently only in Firefox 8+), + * falls back to #getAccessKeyModifiers. + * + * @private + * @param {HTMLElement} element Element to get the label for + * @return {string} Access key label + */ + function getAccessKeyLabel( element ) { + // abort early if no access key + if ( !element.accessKey ) { + return ''; + } + // use accessKeyLabel if possible + // https://html.spec.whatwg.org/multipage/interaction.html#dom-accesskeylabel + if ( !useTestPrefix && element.accessKeyLabel ) { + return element.accessKeyLabel; + } + return ( useTestPrefix ? 'test' : getAccessKeyModifiers().join( '-' ) ) + '-' + element.accessKey; + } + + /** + * Update the title for an element (on the element with the access key or it's label) to show + * the correct access key label. + * + * @private + * @param {HTMLElement} element Element with the accesskey + * @param {HTMLElement} titleElement Element with the title to update (may be the same as `element`) + */ + function updateTooltipOnElement( element, titleElement ) { + var oldTitle, parts, regexp, newTitle, accessKeyLabel, + separatorMsg = mw.message( 'word-separator' ).plain(); + + oldTitle = titleElement.title; + if ( !oldTitle ) { + // don't add a title if the element didn't have one before + return; + } + + parts = ( separatorMsg + mw.message( 'brackets' ).plain() ).split( '$1' ); + regexp = new RegExp( parts.map( mw.RegExp.escape ).join( '.*?' ) + '$' ); + newTitle = oldTitle.replace( regexp, '' ); + accessKeyLabel = getAccessKeyLabel( element ); + + if ( accessKeyLabel ) { + // Should be build the same as in Linker::titleAttrib + newTitle += separatorMsg + mw.message( 'brackets', accessKeyLabel ).plain(); + } + if ( oldTitle !== newTitle ) { + titleElement.title = newTitle; + } + } + + /** + * Update the title for an element to show the correct access key label. + * + * @private + * @param {HTMLElement} element Element with the accesskey + */ + function updateTooltip( element ) { + var id, $element, $label, $labelParent; + updateTooltipOnElement( element, element ); + + // update associated label if there is one + $element = $( element ); + if ( $element.is( labelable ) ) { + // Search it using 'for' attribute + id = element.id.replace( /"/g, '\\"' ); + if ( id ) { + $label = $( 'label[for="' + id + '"]' ); + if ( $label.length === 1 ) { + updateTooltipOnElement( element, $label[ 0 ] ); + } + } + + // Search it as parent, because the form control can also be inside the label element itself + $labelParent = $element.parents( 'label' ); + if ( $labelParent.length === 1 ) { + updateTooltipOnElement( element, $labelParent[ 0 ] ); + } + } + } + + /** + * Update the titles for all elements in a jQuery selection. + * + * @return {jQuery} + * @chainable + */ + $.fn.updateTooltipAccessKeys = function () { + return this.each( function () { + updateTooltip( this ); + } ); + }; + + /** + * getAccessKeyModifiers + * + * @method updateTooltipAccessKeys_getAccessKeyModifiers + * @inheritdoc #getAccessKeyModifiers + */ + $.fn.updateTooltipAccessKeys.getAccessKeyModifiers = getAccessKeyModifiers; + + /** + * getAccessKeyLabel + * + * @method updateTooltipAccessKeys_getAccessKeyLabel + * @inheritdoc #getAccessKeyLabel + */ + $.fn.updateTooltipAccessKeys.getAccessKeyLabel = getAccessKeyLabel; + + /** + * getAccessKeyPrefix + * + * @method updateTooltipAccessKeys_getAccessKeyPrefix + * @deprecated since 1.27 Use #getAccessKeyModifiers + * @param {Object} [ua] An object with a 'userAgent' and 'platform' property. + * @return {string} + */ + $.fn.updateTooltipAccessKeys.getAccessKeyPrefix = function ( ua ) { + return getAccessKeyModifiers( ua ).join( '-' ) + '-'; + }; + + /** + * Switch test mode on and off. + * + * @method updateTooltipAccessKeys_setTestMode + * @param {boolean} mode New mode + */ + $.fn.updateTooltipAccessKeys.setTestMode = function ( mode ) { + useTestPrefix = mode; + }; + + /** + * @class jQuery + * @mixins jQuery.plugin.accessKeyLabel + */ + +}() ); diff --git a/resources/src/mediawiki.util/util.js b/resources/src/mediawiki.util/util.js index 36a0195d84..7e0722f442 100644 --- a/resources/src/mediawiki.util/util.js +++ b/resources/src/mediawiki.util/util.js @@ -4,6 +4,8 @@ var util, config = require( './config.json' ); + require( './jquery.accessKeyLabel.js' ); + /** * Encode the string like PHP's rawurlencode * @ignore diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index d55b603ba9..76f4f82c89 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -102,7 +102,6 @@ return [ 'tests/qunit/suites/resources/mediawiki/mediawiki.visibleTimeout.test.js', ], 'dependencies' => [ - 'jquery.accessKeyLabel', 'jquery.color', 'jquery.colorUtil', 'jquery.getAttrs',