mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-23 15:36:52 +00:00
Handle VisualEditor when it skips the "tempWikitextEditor" stage
Depending on the user's internet connection, the code that sets up mw.libs.ve.tempWikitextEditor may be completely skipped if the normal editor code loads fast enough. Refactor the code to handle all three cases using the same function. Bug: T185279 Change-Id: I003b27f838d1986ed8d238089efd657b96e8ec91
This commit is contained in:
parent
6d0c6b6730
commit
a51f750f83
|
@ -1,18 +1,23 @@
|
|||
$( function () {
|
||||
var location = mw.config.get( 'wgLinterErrorLocation' ),
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
$textbox = $( '#wpTextbox1' );
|
||||
var location = mw.config.get( 'wgLinterErrorLocation' );
|
||||
|
||||
function highlightPosition( $textbox ) {
|
||||
$textbox.trigger( 'focus' ).textSelection( 'setSelection', { start: location[ 0 ], end: location[ 1 ] } );
|
||||
$textbox.textSelection( 'scrollToCaretPosition' );
|
||||
}
|
||||
|
||||
if ( location ) {
|
||||
if ( $textbox.length ) {
|
||||
$textbox.trigger( 'focus' ).textSelection( 'setSelection', { start: location[ 0 ], end: location[ 1 ] } );
|
||||
$textbox.textSelection( 'scrollToCaretPosition' );
|
||||
}
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
highlightPosition( $( '#wpTextbox1' ) );
|
||||
|
||||
mw.hook( 've.wikitextInteractive' ).add( function () {
|
||||
mw.libs.ve.tempWikitextEditor.$element[ 0 ].setSelectionRange(
|
||||
location[ 0 ], location[ 1 ]
|
||||
);
|
||||
mw.libs.ve.tempWikitextEditor.focus();
|
||||
if ( mw.libs.ve.tempWikitextEditor ) {
|
||||
highlightPosition( mw.libs.ve.tempWikitextEditor.$element );
|
||||
} else {
|
||||
// VE dummy textbox
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
highlightPosition( $( '#wpTextbox1' ) );
|
||||
}
|
||||
} );
|
||||
}
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue