Fix restoration of redirect HTML after exiting without saving

This feels like it's getting far more complicated than it should be.

Bug: T140032
Change-Id: Id951400cead61da37b8bdfa05cf8add6c115547d
This commit is contained in:
Alex Monk 2016-07-14 04:16:38 +01:00
parent 015d63d560
commit 96421b283c

View file

@ -762,8 +762,9 @@ ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
* Add the redirect header when a redirect is inserted into the page.
*
* @param {ve.dm.MetaItem} metaItem Item that was inserted
* @param {boolean} [loading=false] Whether VE is loading.
*/
ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaItem ) {
ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaItem, loading ) {
var title, target, $link;
if ( metaItem.getType() === 'mwRedirect' ) {
target = this;
@ -773,6 +774,10 @@ ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaIt
.text( title );
ve.init.platform.linkCache.styleElement( title, $link );
if ( loading ) {
this.$originalRedirectMsg = $( '.redirectMsg' ).clone();
this.$originalRedirectSub = $( '#redirectsub, #redirectsub + br' ).clone();
}
// Add redirect target header
if ( !$( '#redirectsub' ).length ) {
$( '#contentSub' ).append(
@ -782,7 +787,6 @@ ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaIt
$( '<br>' )
);
}
this.$originalContent.find( '.redirectMsg' ).remove();
$( '<div>' )
// Bit of a hack: Make sure any redirect note is styled
.addClass( 'redirectMsg mw-content-' + $( 'html' ).attr( 'dir' ) )
@ -1226,7 +1230,18 @@ ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
$( '#ca-view' ).addClass( 'selected' );
// Remove any VE-added redirectMsg
$( '.mw-body-content > .ve-redirect-header' ).remove();
if ( $( '.mw-body-content > .ve-redirect-header' ).length ) {
$( '.mw-body-content > .ve-redirect-header' ).remove();
$( '#contentSub #redirectSub, #contentSub #redirectSub + br' ).remove();
}
// Restore any previous redirectMsg/redirectsub
if ( this.$originalRedirectMsg ) {
this.$originalRedirectMsg.prependTo( $( '#mw-content-text' ) );
this.$originalRedirectSub.prependTo( $( '#contentSub' ) );
this.$originalRedirectMsg = undefined;
this.$originalRedirectSub = undefined;
}
mw.hook( 've.deactivate' ).fire();
this.emit( 'restorePage' );
@ -1317,6 +1332,8 @@ ve.init.mw.DesktopArticleTarget.prototype.replacePageContent = function (
}
// Remove any VE-added ve-redirect-header
$( '.redirectMsg' ).removeClass( 've-redirect-header' );
this.$originalRedirectMsg = undefined;
this.$originalRedirectSub = undefined;
// Re-set any edit section handlers now that the page content has been replaced
if (
@ -1430,7 +1447,7 @@ ve.init.mw.DesktopArticleTarget.prototype.maybeShowMetaDialog = function () {
redirectMetaItems = this.getSurface().getModel().getMetaList().getItemsInGroup( 'mwRedirect' );
if ( redirectMetaItems.length ) {
this.onMetaItemInserted( redirectMetaItems[ 0 ] );
this.onMetaItemInserted( redirectMetaItems[ 0 ], true );
windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );