mediawiki-extensions-Scribunto/modules/ext.scribunto.js
Tim Starling 886c6ae06d Don't open multiple error dialogs
If a Scribunto error dialog is open and the user clicks another error,
or the same error again, don't open another dialog window, instead close
the old one and reuse it.

Change-Id: I50b8d48ee551cfb8cb4e1e672a0e36e15b5ae216
2012-05-26 16:00:05 +04:00

51 lines
1.2 KiB
JavaScript

(function ( $, mw ) {
mw.scribunto = {
errors: null,
'setErrors': function (errors) {
this.errors = errors;
},
'init': function () {
var regex = /^mw-scribunto-error-(\d+)/;
var that = this;
var dialog = $( '<div/>' );
dialog.dialog({
title: mw.msg( 'scribunto-parser-dialog-title' ),
autoOpen: false
});
$('.scribunto-error').each( function( index, span ) {
var matches = regex.exec( span.id );
if ( matches == null ) {
console.log( "mw.scribunto.init: regex mismatch!" );
return;
}
var errorId = parseInt( matches[1] );
$(span)
.css( 'cursor', 'pointer' )
.bind( 'click', function( evt ) {
if ( typeof that.errors[ errorId ] != 'string' ) {
console.log( "mw.scribunto.init: error " + matches[1] + " not found, " +
"mw.loader.using() callback may not have been called yet." );
return;
}
var error = that.errors[ errorId ];
dialog
.dialog( 'close' )
.html( error )
.dialog( 'option', 'position', [ evt.clientX + 5, evt.clientY + 5 ] )
.dialog( 'open' );
} );
} );
}
};
$(document).ready( function() {
mw.scribunto.init();
});
})( jQuery, mediaWiki );