Merge "Avoid href="#" on <a> elements"

This commit is contained in:
jenkins-bot 2020-01-25 16:25:07 +00:00 committed by Gerrit Code Review
commit e94ad450bd
3 changed files with 65 additions and 38 deletions

View file

@ -400,22 +400,27 @@
.attr( 'rel', 'wikiEditor-ui-view-' + options.name ) .attr( 'rel', 'wikiEditor-ui-view-' + options.name )
.addClass( context.view === options.name ? 'current' : null ) .addClass( context.view === options.name ? 'current' : null )
.append( $( '<a>' ) .append( $( '<a>' )
.attr( 'href', '#' ) .attr( 'tabindex', 0 )
.on( 'mousedown', function () { .on( 'mousedown', function () {
// No dragging! // No dragging!
return false; return false;
} ) } )
.on( 'click', function ( event ) { .on( 'click keydown', function ( event ) {
context.$ui.find( '.wikiEditor-ui-view' ).hide(); if (
context.$ui.find( '.' + $( this ).parent().attr( 'rel' ) ).show(); event.type === 'click' ||
context.$tabs.find( 'div' ).removeClass( 'current' ); event.type === 'keydown' && event.key === 'Enter'
$( this ).parent().addClass( 'current' ); ) {
$( this ).trigger( 'blur' ); context.$ui.find( '.wikiEditor-ui-view' ).hide();
if ( 'init' in options && typeof options.init === 'function' ) { context.$ui.find( '.' + $( this ).parent().attr( 'rel' ) ).show();
options.init( context ); context.$tabs.find( 'div' ).removeClass( 'current' );
$( this ).parent().addClass( 'current' );
$( this ).trigger( 'blur' );
if ( 'init' in options && typeof options.init === 'function' ) {
options.init( context );
}
event.preventDefault();
return false;
} }
event.preventDefault();
return false;
} ) } )
.text( $.wikiEditor.autoMsg( options, 'title' ) ) .text( $.wikiEditor.autoMsg( options, 'title' ) )
) )

View file

@ -536,11 +536,11 @@
mw.message( 'wikieditor-toolbar-help-content-file-caption' ).text() mw.message( 'wikieditor-toolbar-help-content-file-caption' ).text()
] }, ] },
result: { html: '<div class="thumbinner" style="width: 102px;">' + result: { html: '<div class="thumbinner" style="width: 102px;">' +
'<a href="#" class="image">' + '<a class="image">' +
'<img alt="" src="' + $.wikiEditor.imgPath + 'toolbar/example-image.png" width="100" height="50" class="thumbimage"/>' + '<img alt="" src="' + $.wikiEditor.imgPath + 'toolbar/example-image.png" width="100" height="50" class="thumbimage"/>' +
'</a>' + '</a>' +
'<div class="thumbcaption"><div class="magnify">' + '<div class="thumbcaption"><div class="magnify">' +
'<a title="' + mw.message( 'thumbnail-more' ).escaped() + '" class="internal" href="#"></a>' + '<a title="' + mw.message( 'thumbnail-more' ).escaped() + '" class="internal"></a>' +
'</div>' + mw.message( 'wikieditor-toolbar-help-content-file-caption' ).escaped() + '</div>' + '</div>' + mw.message( 'wikieditor-toolbar-help-content-file-caption' ).escaped() + '</div>' +
'</div>' '</div>'
} }

View file

@ -308,7 +308,7 @@
} else { } else {
$button = $( '<a>' ) $button = $( '<a>' )
.attr( { .attr( {
href: '#', tabindex: 0,
title: label, title: label,
rel: id, rel: id,
role: 'button', role: 'button',
@ -347,12 +347,17 @@
); );
} ); } );
} else { } else {
$button.on( 'click', function ( e ) { $button.on( 'click keydown', function ( e ) {
toolbarModule.fn.doAction( if (
context, tool.action e.type === 'click' ||
); e.type === 'keydown' && e.key === 'Enter'
e.preventDefault(); ) {
return false; toolbarModule.fn.doAction(
context, tool.action
);
e.preventDefault();
return false;
}
} ); } );
} }
} }
@ -373,18 +378,23 @@
e.preventDefault(); e.preventDefault();
return false; return false;
} ) } )
.on( 'click', function ( e ) { .on( 'click keydown', function ( e ) {
toolbarModule.fn.doAction( if (
$( this ).data( 'context' ), $( this ).data( 'action' ), $( this ) e.type === 'click' ||
); e.type === 'keydown' && e.key === 'Enter'
// Hide the dropdown ) {
$( this ).closest( '.tool-select' ).removeClass( 'options-shown' ); toolbarModule.fn.doAction(
e.preventDefault(); $( this ).data( 'context' ), $( this ).data( 'action' ), $( this )
return false; );
// Hide the dropdown
$( this ).closest( '.tool-select' ).removeClass( 'options-shown' );
e.preventDefault();
return false;
}
} ) } )
.text( optionLabel ) .text( optionLabel )
.addClass( 'option' ) .addClass( 'option' )
.attr( { rel: option, href: '#' } ) .attr( { rel: option, tabindex: 0 } )
); );
} }
} }
@ -392,18 +402,24 @@
.addClass( 'label' ) .addClass( 'label' )
.text( label ) .text( label )
.data( 'options', $options ) .data( 'options', $options )
.attr( 'href', '#' ) .attr( 'tabindex', 0 )
.on( 'mousedown', function ( e ) { .on( 'mousedown', function ( e ) {
// No dragging! // No dragging!
e.preventDefault(); e.preventDefault();
return false; return false;
} ) } )
.on( 'click', function ( e ) { .on( 'click keydown', function ( e ) {
var $options = $( this ).data( 'options' ); var $options;
// eslint-disable-next-line no-jquery/no-class-state if (
$options.closest( '.tool-select' ).toggleClass( 'options-shown' ); e.type === 'click' ||
e.preventDefault(); e.type === 'keydown' && e.key === 'Enter'
return false; ) {
$options = $( this ).data( 'options' );
// eslint-disable-next-line no-jquery/no-class-state
$options.closest( '.tool-select' ).toggleClass( 'options-shown' );
e.preventDefault();
return false;
}
} ) } )
); );
$select.append( $( '<div>' ).addClass( 'menu' ).append( $options ) ); $select.append( $( '<div>' ).addClass( 'menu' ).append( $options ) );
@ -585,7 +601,7 @@
$( '<a>' ) $( '<a>' )
.addClass( selected === id ? 'current' : null ) .addClass( selected === id ? 'current' : null )
.attr( { .attr( {
href: '#', tabindex: 0,
role: 'button', role: 'button',
'aria-pressed': 'false', 'aria-pressed': 'false',
'aria-controls': 'wikiEditor-section-' + id 'aria-controls': 'wikiEditor-section-' + id
@ -600,7 +616,13 @@
e.preventDefault(); e.preventDefault();
return false; return false;
} ) } )
.on( 'click', function ( e ) { .on( 'click keydown', function ( e ) {
if (
e.type !== 'click' &&
( e.type !== 'keydown' || e.key !== 'Enter' )
) {
return;
}
// We have to set aria-pressed over here, as NVDA wont recognize it // We have to set aria-pressed over here, as NVDA wont recognize it
// if we do it in the below .each as it seems // if we do it in the below .each as it seems
$( this ).attr( 'aria-pressed', 'true' ); $( this ).attr( 'aria-pressed', 'true' );