mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 03:08:42 +00:00
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:
parent
015d63d560
commit
96421b283c
|
@ -762,8 +762,9 @@ ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
|
||||||
* Add the redirect header when a redirect is inserted into the page.
|
* Add the redirect header when a redirect is inserted into the page.
|
||||||
*
|
*
|
||||||
* @param {ve.dm.MetaItem} metaItem Item that was inserted
|
* @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;
|
var title, target, $link;
|
||||||
if ( metaItem.getType() === 'mwRedirect' ) {
|
if ( metaItem.getType() === 'mwRedirect' ) {
|
||||||
target = this;
|
target = this;
|
||||||
|
@ -773,6 +774,10 @@ ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaIt
|
||||||
.text( title );
|
.text( title );
|
||||||
ve.init.platform.linkCache.styleElement( title, $link );
|
ve.init.platform.linkCache.styleElement( title, $link );
|
||||||
|
|
||||||
|
if ( loading ) {
|
||||||
|
this.$originalRedirectMsg = $( '.redirectMsg' ).clone();
|
||||||
|
this.$originalRedirectSub = $( '#redirectsub, #redirectsub + br' ).clone();
|
||||||
|
}
|
||||||
// Add redirect target header
|
// Add redirect target header
|
||||||
if ( !$( '#redirectsub' ).length ) {
|
if ( !$( '#redirectsub' ).length ) {
|
||||||
$( '#contentSub' ).append(
|
$( '#contentSub' ).append(
|
||||||
|
@ -782,7 +787,6 @@ ve.init.mw.DesktopArticleTarget.prototype.onMetaItemInserted = function ( metaIt
|
||||||
$( '<br>' )
|
$( '<br>' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.$originalContent.find( '.redirectMsg' ).remove();
|
|
||||||
$( '<div>' )
|
$( '<div>' )
|
||||||
// Bit of a hack: Make sure any redirect note is styled
|
// Bit of a hack: Make sure any redirect note is styled
|
||||||
.addClass( 'redirectMsg mw-content-' + $( 'html' ).attr( 'dir' ) )
|
.addClass( 'redirectMsg mw-content-' + $( 'html' ).attr( 'dir' ) )
|
||||||
|
@ -1226,7 +1230,18 @@ ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
|
||||||
$( '#ca-view' ).addClass( 'selected' );
|
$( '#ca-view' ).addClass( 'selected' );
|
||||||
|
|
||||||
// Remove any VE-added redirectMsg
|
// 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();
|
mw.hook( 've.deactivate' ).fire();
|
||||||
this.emit( 'restorePage' );
|
this.emit( 'restorePage' );
|
||||||
|
@ -1317,6 +1332,8 @@ ve.init.mw.DesktopArticleTarget.prototype.replacePageContent = function (
|
||||||
}
|
}
|
||||||
// Remove any VE-added ve-redirect-header
|
// Remove any VE-added ve-redirect-header
|
||||||
$( '.redirectMsg' ).removeClass( '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
|
// Re-set any edit section handlers now that the page content has been replaced
|
||||||
if (
|
if (
|
||||||
|
@ -1430,7 +1447,7 @@ ve.init.mw.DesktopArticleTarget.prototype.maybeShowMetaDialog = function () {
|
||||||
|
|
||||||
redirectMetaItems = this.getSurface().getModel().getMetaList().getItemsInGroup( 'mwRedirect' );
|
redirectMetaItems = this.getSurface().getModel().getMetaList().getItemsInGroup( 'mwRedirect' );
|
||||||
if ( redirectMetaItems.length ) {
|
if ( redirectMetaItems.length ) {
|
||||||
this.onMetaItemInserted( redirectMetaItems[ 0 ] );
|
this.onMetaItemInserted( redirectMetaItems[ 0 ], true );
|
||||||
|
|
||||||
windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );
|
windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue