summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Scribunto/modules/ext.scribunto.errors.js
blob: 037008b915c2a2a83cd081096c5aff0dae43171d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
( 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 ) );