Merge "Abort loading when 'escape' is pressed"

This commit is contained in:
jenkins-bot 2017-10-04 15:40:57 +00:00 committed by Gerrit Code Review
commit 6e2589d1a6

View file

@ -55,6 +55,8 @@
'</div>' '</div>'
); );
} }
// eslint-disable-next-line no-use-before-define
$( document ).on( 'keydown', onDocumentKeyDown );
// Center within visible part of the target // Center within visible part of the target
$content = $( '#content' ); $content = $( '#content' );
@ -86,19 +88,35 @@
} }
} }
function resetLoadingProgress() { function clearLoading() {
progressStep = 0; progressStep = 0;
setLoadingProgress( 0, 0 ); setLoadingProgress( 0, 0 );
}
function hideLoading() {
isLoading = false; isLoading = false;
// eslint-disable-next-line no-use-before-define
$( document ).off( 'keydown', onDocumentKeyDown );
$( 'html' ).removeClass( 've-loading' ); $( 'html' ).removeClass( 've-loading' );
if ( init.$loading ) { if ( init.$loading ) {
init.$loading.detach(); init.$loading.detach();
} }
} }
function abortLoading() {
$( 'html' ).removeClass( 've-activated' );
active = false;
// Push read tab URL to history
if ( history.pushState && $( '#ca-view a' ).length ) {
history.pushState( { tag: 'visualeditor' }, document.title, new mw.Uri( $( '#ca-view a' ).attr( 'href' ) ) );
}
clearLoading();
}
function onDocumentKeyDown( e ) {
if ( e.which === 27 /* OO.ui.Keys.ESCAPE */ ) {
abortLoading();
e.preventDefault();
}
}
function parseSection( section ) { function parseSection( section ) {
var parsedSection = section; var parsedSection = section;
// Section must be a number, 'new' or 'T-' prefixed // Section must be a number, 'new' or 'T-' prefixed
@ -147,6 +165,13 @@
var target, var target,
modes = []; modes = [];
if ( !active ) {
// Loading was aborted
// TODO: Make loaders abortable instead of waiting
targetPromise = null;
return $.Deferred().reject().promise();
}
if ( init.isVisualAvailable ) { if ( init.isVisualAvailable ) {
modes.push( 'visual' ); modes.push( 'visual' );
} }
@ -287,10 +312,7 @@
.then( function () { .then( function () {
ve.track( 'mwedit.ready' ); ve.track( 'mwedit.ready' );
} ) } )
.always( function () { .always( clearLoading );
hideLoading();
resetLoadingProgress();
} );
} }
function activatePageTarget( mode, modified ) { function activatePageTarget( mode, modified ) {