mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Move some deactivation code from DesktopArticle to ArticleTarget
Also rename tryDeactive to tryTeardown. Change-Id: Ie89d59a62826bcfe3d30ad04f89d3c4211cc34f4
This commit is contained in:
parent
fd01a9e972
commit
307e6c2922
|
@ -30,7 +30,6 @@ ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config
|
||||||
this.onUnloadHandler = this.onUnload.bind( this );
|
this.onUnloadHandler = this.onUnload.bind( this );
|
||||||
this.activating = false;
|
this.activating = false;
|
||||||
this.deactivating = false;
|
this.deactivating = false;
|
||||||
this.edited = false;
|
|
||||||
this.recreating = false;
|
this.recreating = false;
|
||||||
this.activatingDeferred = null;
|
this.activatingDeferred = null;
|
||||||
this.toolbarSetupDeferred = null;
|
this.toolbarSetupDeferred = null;
|
||||||
|
@ -532,19 +531,13 @@ ve.init.mw.DesktopArticleTarget.prototype.teardownNewSection = function ( surfac
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to de-activate the target, but leave ready for re-activation later
|
* @inheritdoc
|
||||||
*
|
*
|
||||||
* Will first prompt the user if required, then call #deactivate.
|
* A prompt will not be shown if tryTeardown() is called while activation is still in progress.
|
||||||
*
|
* If tryTeardown() is called while the target is deactivating, or while it's not active and
|
||||||
* A dialog will not be shown if tryDeactivate() is called while activation is still in progress,
|
* not activating, nothing happens.
|
||||||
* or if the noDialog parameter is set to true. If tryDeactivate() is called while the target
|
|
||||||
* is deactivating, or while it's not active and not activating, nothing happens.
|
|
||||||
*
|
|
||||||
* @param {boolean} [noDialog] Do not display a dialog
|
|
||||||
* @param {string} [trackMechanism] Abort mechanism; used for event tracking if present
|
|
||||||
*/
|
*/
|
||||||
ve.init.mw.DesktopArticleTarget.prototype.tryDeactivate = function ( noDialog, trackMechanism ) {
|
ve.init.mw.DesktopArticleTarget.prototype.tryTeardown = function ( noPrompt, trackMechanism ) {
|
||||||
var target = this;
|
|
||||||
if ( this.deactivating || ( !this.active && !this.activating ) ) {
|
if ( this.deactivating || ( !this.active && !this.activating ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -558,16 +551,7 @@ ve.init.mw.DesktopArticleTarget.prototype.tryDeactivate = function ( noDialog, t
|
||||||
}
|
}
|
||||||
this.editingTabDialog = null;
|
this.editingTabDialog = null;
|
||||||
|
|
||||||
if ( noDialog || this.activating || !this.edited ) {
|
return ve.init.mw.DesktopArticleTarget.super.prototype.tryTeardown.call( this, noPrompt || this.activating, trackMechanism );
|
||||||
this.teardown( trackMechanism );
|
|
||||||
} else {
|
|
||||||
this.getSurface().dialogs.openWindow( 'cancelconfirm' )
|
|
||||||
.closed.then( function ( data ) {
|
|
||||||
if ( data && data.action === 'discard' ) {
|
|
||||||
target.teardown( trackMechanism );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -721,7 +705,7 @@ ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( code, errorDetai
|
||||||
} else if ( $( '#wpTextbox1' ).length && !ve.init.target.isModeAvailable( 'source' ) ) {
|
} else if ( $( '#wpTextbox1' ).length && !ve.init.target.isModeAvailable( 'source' ) ) {
|
||||||
// If we're switching from the wikitext editor, just deactivate
|
// If we're switching from the wikitext editor, just deactivate
|
||||||
// don't try to switch back to it fully, that'd discard changes.
|
// don't try to switch back to it fully, that'd discard changes.
|
||||||
target.tryDeactivate( true );
|
target.tryTeardown( true );
|
||||||
} else {
|
} else {
|
||||||
// TODO: Some sort of progress bar?
|
// TODO: Some sort of progress bar?
|
||||||
target.wikitextFallbackLoading = true;
|
target.wikitextFallbackLoading = true;
|
||||||
|
@ -732,7 +716,7 @@ ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( code, errorDetai
|
||||||
if ( errorDetails.statusText !== 'abort' ) {
|
if ( errorDetails.statusText !== 'abort' ) {
|
||||||
mw.log.warn( 'Failed to find error message', code, errorDetails );
|
mw.log.warn( 'Failed to find error message', code, errorDetails );
|
||||||
}
|
}
|
||||||
this.tryDeactivate( true );
|
this.tryTeardown( true );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -908,7 +892,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onDocumentKeyDown = function ( e ) {
|
||||||
// also check they didn't fire after this event, as would be the case if
|
// also check they didn't fire after this event, as would be the case if
|
||||||
// they were bound to the document.
|
// they were bound to the document.
|
||||||
if ( !e.isPropagationStopped() ) {
|
if ( !e.isPropagationStopped() ) {
|
||||||
target.tryDeactivate( false, 'navigate-read' );
|
target.tryTeardown( false, 'navigate-read' );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -925,7 +909,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onViewTabClick = function ( e ) {
|
||||||
if ( !ve.isUnmodifiedLeftClick( e ) ) {
|
if ( !ve.isUnmodifiedLeftClick( e ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.tryDeactivate( false, 'navigate-read' );
|
this.tryTeardown( false, 'navigate-read' );
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1009,7 +993,7 @@ ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function (
|
||||||
|
|
||||||
// Tear down the target now that we're done saving
|
// Tear down the target now that we're done saving
|
||||||
// Not passing trackMechanism because this isn't an abort action
|
// Not passing trackMechanism because this isn't an abort action
|
||||||
this.tryDeactivate( true );
|
this.tryTeardown( true );
|
||||||
if ( newid !== undefined ) {
|
if ( newid !== undefined ) {
|
||||||
mw.hook( 'postEdit' ).fire( {
|
mw.hook( 'postEdit' ).fire( {
|
||||||
message: ve.msg( 'postedit-confirmation-saved', mw.user )
|
message: ve.msg( 'postedit-confirmation-saved', mw.user )
|
||||||
|
@ -1380,7 +1364,7 @@ ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
|
||||||
}
|
}
|
||||||
if ( this.active && veaction !== 'edit' && veaction !== 'editsource' ) {
|
if ( this.active && veaction !== 'edit' && veaction !== 'editsource' ) {
|
||||||
this.actFromPopState = true;
|
this.actFromPopState = true;
|
||||||
this.tryDeactivate( false, 'navigate-back' );
|
this.tryTeardown( false, 'navigate-back' );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ ve.init.mw.ArticleTarget = function VeInitMwArticleTarget( config ) {
|
||||||
this.currentRevisionId = mw.config.get( 'wgCurRevisionId' );
|
this.currentRevisionId = mw.config.get( 'wgCurRevisionId' );
|
||||||
this.revid = this.requestedRevId || this.currentRevisionId;
|
this.revid = this.requestedRevId || this.currentRevisionId;
|
||||||
|
|
||||||
|
this.edited = false;
|
||||||
this.restoring = !!this.requestedRevId && this.requestedRevId !== this.currentRevisionId;
|
this.restoring = !!this.requestedRevId && this.requestedRevId !== this.currentRevisionId;
|
||||||
this.pageDeletedWarning = false;
|
this.pageDeletedWarning = false;
|
||||||
this.submitUrl = ( new mw.Uri( mw.util.getUrl( this.pageName ) ) )
|
this.submitUrl = ( new mw.Uri( mw.util.getUrl( this.pageName ) ) )
|
||||||
|
@ -1905,6 +1906,31 @@ ve.init.mw.ArticleTarget.prototype.teardown = function () {
|
||||||
return ve.init.mw.ArticleTarget.super.prototype.teardown.call( this );
|
return ve.init.mw.ArticleTarget.super.prototype.teardown.call( this );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to tear down the target, but leave ready for re-activation later
|
||||||
|
*
|
||||||
|
* Will first prompt the user if required, then call #teardown.
|
||||||
|
*
|
||||||
|
* @param {boolean} [noPrompt] Do not display a prompt to the user
|
||||||
|
* @param {string} [trackMechanism] Abort mechanism; used for event tracking if present
|
||||||
|
* @return {jQuery.Promise} Promise which resolves when the target has been torn down
|
||||||
|
*/
|
||||||
|
ve.init.mw.ArticleTarget.prototype.tryTeardown = function ( noPrompt, trackMechanism ) {
|
||||||
|
var target = this;
|
||||||
|
|
||||||
|
if ( noPrompt || !this.edited ) {
|
||||||
|
return this.teardown( trackMechanism );
|
||||||
|
} else {
|
||||||
|
return this.getSurface().dialogs.openWindow( 'cancelconfirm' )
|
||||||
|
.closed.then( function ( data ) {
|
||||||
|
if ( data && data.action === 'discard' ) {
|
||||||
|
return target.teardown( trackMechanism );
|
||||||
|
}
|
||||||
|
return $.Deferred().reject().promise();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue