mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-12-21 12:23:02 +00:00
248e886dc0
This avoids having multiple HTML elements with the same `id` attribute when certain Scribunto errors reoccur more than once on the same page. Bug: T375539 Change-Id: I123a0f0046a616f63506f096651ae917bbc65cc5
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
( () => {
|
|
|
|
mw.hook( 'wikipage.content' ).add( () => {
|
|
const regex = /\bmw-scribunto-error-(\w+)\b/;
|
|
let popup;
|
|
|
|
$( '.scribunto-error' ).each( ( index, span ) => {
|
|
let matches = regex.exec( span.className );
|
|
if ( matches === null ) {
|
|
// T375539: backward-compatibility with old cached HTML
|
|
matches = regex.exec( span.id );
|
|
}
|
|
if ( matches === null ) {
|
|
mw.log( 'mw.scribunto.errors: regex mismatch!' );
|
|
return;
|
|
}
|
|
const $span = $( span );
|
|
$span.on( 'click', () => {
|
|
const error = mw.config.get( 'ScribuntoErrors-' + matches[ 1 ] );
|
|
if ( typeof error !== 'string' ) {
|
|
mw.log( 'mw.scribunto.errors: error ' + matches[ 1 ] + ' not found.' );
|
|
return;
|
|
}
|
|
|
|
if ( !popup ) {
|
|
popup = new OO.ui.PopupWidget( {
|
|
padded: true,
|
|
head: true,
|
|
label: $( '<div>' )
|
|
.text( mw.msg( 'scribunto-parser-dialog-title' ) )
|
|
.addClass( 'scribunto-error-label' )
|
|
} );
|
|
OO.ui.getDefaultOverlay().append( popup.$element );
|
|
}
|
|
popup.$body.html( error );
|
|
popup.setFloatableContainer( $span );
|
|
popup.toggle( true );
|
|
} );
|
|
} );
|
|
} );
|
|
|
|
} )();
|