2016-10-13 08:14:18 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
$( function () {
|
2017-03-10 22:09:17 +00:00
|
|
|
var location = mw.config.get( 'wgLinterErrorLocation' ),
|
|
|
|
$textbox = $( '#wpTextbox1' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the normal offset for one that is usable
|
|
|
|
* by VE's DOM that changes newlines into <p>
|
|
|
|
*
|
|
|
|
* @param {ve.ui.Surface} surface
|
|
|
|
* @param {int} offset
|
|
|
|
* @return {int}
|
|
|
|
*/
|
|
|
|
function fixOffset( surface, offset ) {
|
|
|
|
return ( surface.getDom().slice( 0, offset ).match( /\n/g ) || [] ).length + 1 + offset;
|
|
|
|
}
|
|
|
|
|
2016-10-13 08:14:18 +00:00
|
|
|
if ( location ) {
|
2017-03-10 22:09:17 +00:00
|
|
|
if ( $textbox.length ) {
|
|
|
|
$textbox.focus().textSelection( 'setSelection', { start: location[ 0 ], end: location[ 1 ] } );
|
|
|
|
}
|
|
|
|
// Register NWE code should it be loaded
|
|
|
|
// TODO: We should somehow force source mode if VE is opened
|
|
|
|
mw.hook( 've.activationComplete' ).add( function () {
|
|
|
|
var range,
|
|
|
|
surface = ve.init.target.getSurface();
|
|
|
|
|
|
|
|
if ( surface.getMode() === 'source' ) {
|
|
|
|
range = new ve.Range( fixOffset( surface, location[ 0 ] ), fixOffset( surface, location[ 1 ] ) );
|
|
|
|
surface.getModel().setLinearSelection( range );
|
|
|
|
}
|
|
|
|
} );
|
2016-10-13 08:14:18 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}( mediaWiki, jQuery ) );
|