2012-10-07 00:41:25 +00:00
|
|
|
( function ( $, mw ) {
|
|
|
|
|
2013-12-10 23:05:26 +00:00
|
|
|
var scribunto = mw.scribunto = {
|
2012-10-07 00:41:25 +00:00
|
|
|
errors: null,
|
|
|
|
|
2013-12-10 23:05:26 +00:00
|
|
|
setErrors: function ( errors ) {
|
|
|
|
scribunto.errors = errors;
|
2012-10-07 00:41:25 +00:00
|
|
|
},
|
|
|
|
|
2013-12-10 23:05:26 +00:00
|
|
|
init: function () {
|
2012-10-07 00:41:25 +00:00
|
|
|
var regex = /^mw-scribunto-error-(\d+)/,
|
2013-12-10 23:05:26 +00:00
|
|
|
$dialog = $( '<div>' );
|
2012-10-07 00:41:25 +00:00
|
|
|
|
2013-12-10 23:05:26 +00:00
|
|
|
$dialog.dialog( {
|
2012-10-07 00:41:25 +00:00
|
|
|
title: mw.msg( 'scribunto-parser-dialog-title' ),
|
|
|
|
autoOpen: false
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '.scribunto-error' ).each( function ( index, span ) {
|
2013-12-10 23:05:26 +00:00
|
|
|
var errorId,
|
|
|
|
matches = regex.exec( span.id );
|
2012-10-07 00:41:25 +00:00
|
|
|
if ( matches === null ) {
|
2013-12-10 23:05:26 +00:00
|
|
|
mw.log( 'mw.scribunto.init: regex mismatch!' );
|
2012-10-07 00:41:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-12-10 23:05:26 +00:00
|
|
|
errorId = parseInt( matches[1], 10 );
|
|
|
|
$( span ).on( 'click', function ( e ) {
|
|
|
|
if ( typeof scribunto.errors[ errorId ] !== 'string' ) {
|
|
|
|
mw.log( 'mw.scribunto.init: error ' + matches[1] + ' not found, ' +
|
|
|
|
'mw.loader.using() callback may not have been called yet.' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var error = scribunto.errors[ errorId ];
|
|
|
|
$dialog
|
|
|
|
.dialog( 'close' )
|
|
|
|
.html( error )
|
|
|
|
.dialog( 'option', 'position', [ e.clientX + 5, e.clientY + 5 ] )
|
|
|
|
.dialog( 'open' );
|
|
|
|
} );
|
2012-10-07 00:41:25 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-10 23:05:26 +00:00
|
|
|
$( mw.scribunto.init );
|
2012-10-07 00:41:25 +00:00
|
|
|
|
|
|
|
} ) ( jQuery, mediaWiki );
|
2012-04-23 11:36:13 +00:00
|
|
|
|