mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-13 18:07:05 +00:00
3d51662881
This is apparently unofficially deprecated, and we can do things a bit more straightforwardly by using ParserOutput::addJsConfigVars() to communicate the error messages to the JS. This also takes the opportunity to move "ext.scribunto", which is mostly about errors, to "ext.scribunto.errors". Bug: T75618 Change-Id: I1577dab2dab1bd79cb127879de141fdbb8963aeb
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
( function ( $, mw ) {
|
|
|
|
mw.hook( 'wikipage.content' ).add( function () {
|
|
var errors = mw.config.get( 'ScribuntoErrors' ),
|
|
regex = /^mw-scribunto-error-(\d+)/,
|
|
$dialog = $( '<div>' );
|
|
|
|
if ( !errors ) {
|
|
mw.log( 'mw.scribunto.errors: ScribuntoErrors does not exist in mw.config' );
|
|
errors = [];
|
|
}
|
|
|
|
$dialog.dialog( {
|
|
title: mw.msg( 'scribunto-parser-dialog-title' ),
|
|
autoOpen: false
|
|
} );
|
|
|
|
$( '.scribunto-error' ).each( function ( index, span ) {
|
|
var errorId,
|
|
matches = regex.exec( span.id );
|
|
if ( matches === null ) {
|
|
mw.log( 'mw.scribunto.errors: regex mismatch!' );
|
|
return;
|
|
}
|
|
errorId = parseInt( matches[1], 10 );
|
|
$( span ).on( 'click', function ( e ) {
|
|
var error = errors[ errorId ];
|
|
if ( typeof error !== 'string' ) {
|
|
mw.log( 'mw.scribunto.errors: error ' + matches[1] + ' not found.' );
|
|
return;
|
|
}
|
|
$dialog
|
|
.dialog( 'close' )
|
|
.html( error )
|
|
.dialog( 'option', 'position', [ e.clientX + 5, e.clientY + 5 ] )
|
|
.dialog( 'open' );
|
|
} );
|
|
} );
|
|
} );
|
|
|
|
} ) ( jQuery, mediaWiki );
|