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

View file

@ -536,11 +536,11 @@
mw.message( 'wikieditor-toolbar-help-content-file-caption' ).text()
] },
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"/>' +
'</a>' +
'<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>'
}

View file

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