Show beta welcome dialog before surface is ready

Split up beta and meta dialog show methods so that beta dialog
is displayed as soon as possible, regardless of the surface being
ready. Also make sure that we destroy the temporary window
manager on destroy.

Bug: T90454
Change-Id: Ib8f94518af431487ce940a74a8c268dbdbe403d2
This commit is contained in:
Moriel Schottlender 2015-03-25 14:52:06 -07:00 committed by Trevor Parscal
parent 9019f02130
commit 74c3b758e2
3 changed files with 60 additions and 14 deletions

View file

@ -18,7 +18,8 @@
font-size: 1em; font-size: 1em;
} }
.ve-ui-overlay { .ve-ui-overlay,
.ve-init-mw-viewPageTarget-windowManager-welcome {
/* Mimic #globalWrapper */ /* Mimic #globalWrapper */
font-size: 127%; font-size: 127%;
} }

View file

@ -98,3 +98,8 @@
margin: 1em -1.5em -1.5em -1.5em; margin: 1em -1.5em -1.5em -1.5em;
} }
} }
/* Prevent the progress bar from overlaying the welcome dialog */
.ve-init-mw-viewPageTarget-windowManager-welcome .oo-ui-dialog {
z-index: 2;
}

View file

@ -40,6 +40,9 @@ ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() {
this.recreating = false; this.recreating = false;
this.activatingDeferred = null; this.activatingDeferred = null;
this.toolbarSetupDeferred = null; this.toolbarSetupDeferred = null;
this.welcomeDialog = null;
this.welcomeDialogPromise = null;
// If this is true then #transformPage / #restorePage will not call pushState // If this is true then #transformPage / #restorePage will not call pushState
// This is to avoid adding a new history entry for the url we just got from onpopstate // This is to avoid adding a new history entry for the url we just got from onpopstate
// (which would mess up with the expected order of Back/Forwards browsing) // (which would mess up with the expected order of Back/Forwards browsing)
@ -282,6 +285,8 @@ ve.init.mw.ViewPageTarget.prototype.activate = function ( dataPromise ) {
this.activatingDeferred = $.Deferred(); this.activatingDeferred = $.Deferred();
this.toolbarSetupDeferred = $.Deferred(); this.toolbarSetupDeferred = $.Deferred();
this.maybeShowWelcomeDialog();
$( 'html' ).removeClass( 've-loading' ).addClass( 've-activating' ); $( 'html' ).removeClass( 've-loading' ).addClass( 've-activating' );
$.when( this.activatingDeferred, this.toolbarSetupDeferred ).always( function () { $.when( this.activatingDeferred, this.toolbarSetupDeferred ).always( function () {
$( 'html' ).removeClass( 've-activating' ).addClass( 've-active' ); $( 'html' ).removeClass( 've-activating' ).addClass( 've-active' );
@ -336,6 +341,9 @@ ve.init.mw.ViewPageTarget.prototype.deactivate = function ( noDialog, trackMecha
return; return;
} }
// Just in case this wasn't closed before
this.welcomeDialog.close();
if ( noDialog || this.activating || !this.edited ) { if ( noDialog || this.activating || !this.edited ) {
this.cancel( trackMechanism ); this.cancel( trackMechanism );
} else { } else {
@ -522,7 +530,7 @@ ve.init.mw.ViewPageTarget.prototype.onSurfaceReady = function () {
this.restoreScrollPosition(); this.restoreScrollPosition();
this.restoreEditSection(); this.restoreEditSection();
this.setupUnloadHandlers(); this.setupUnloadHandlers();
this.maybeShowDialogs(); this.maybeShowMetaDialog();
this.activatingDeferred.resolve(); this.activatingDeferred.resolve();
@ -1573,11 +1581,25 @@ ve.init.mw.ViewPageTarget.prototype.tearDownUnloadHandlers = function () {
}; };
/** /**
* Show dialogs as needed on load. * Show the beta dialog as needed
*/ */
ve.init.mw.ViewPageTarget.prototype.maybeShowDialogs = function () { ve.init.mw.ViewPageTarget.prototype.maybeShowWelcomeDialog = function () {
var usePrefs, prefSaysShow, urlSaysHide, target = this; var usePrefs, prefSaysShow, urlSaysHide, windowManager,
target = this;
this.welcomeDialogPromise = $.Deferred();
if ( mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome ) { if ( mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome ) {
// Set up a temporary window manager
windowManager = new OO.ui.WindowManager( {
classes: [
've-init-mw-viewPageTarget-windowManager',
've-init-mw-viewPageTarget-windowManager-welcome'
]
} );
$( 'body' ).append( windowManager.$element );
this.welcomeDialog = new ve.ui.MWBetaWelcomeDialog();
windowManager.addWindows( [ this.welcomeDialog ] );
// Only use the preference value if the user is logged-in. // Only use the preference value if the user is logged-in.
// If the user is anonymous, we can't save the preference // If the user is anonymous, we can't save the preference
@ -1600,17 +1622,20 @@ ve.init.mw.ViewPageTarget.prototype.maybeShowDialogs = function () {
) )
) )
) { ) {
this.getSurface().getDialogs().openWindow( 'betaWelcome' ).done( function ( opened ) { windowManager.openWindow( this.welcomeDialog )
opened.done( function ( closing ) { .then( function ( opened ) {
closing.done( function () { return opened;
// Pop out the notices when the welcome dialog is closed } )
target.actionsToolbar.tools.notices.getPopup().toggle( true ); .then( function ( closing ) {
} ); return closing;
} ); } )
.then( function () {
// Detach the temporary window manager
windowManager.destroy();
target.welcomeDialogPromise.resolve();
} ); } );
} else { } else {
// Automatically open the notices immediately this.welcomeDialogPromise.resolve();
this.actionsToolbar.tools.notices.getPopup().toggle( true );
} }
if ( prefSaysShow ) { if ( prefSaysShow ) {
@ -1629,7 +1654,22 @@ ve.init.mw.ViewPageTarget.prototype.maybeShowDialogs = function () {
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } ); $.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
} }
} }
} else {
this.welcomeDialogPromise.reject();
} }
};
/**
* Show the meta dialog as needed on load.
*/
ve.init.mw.ViewPageTarget.prototype.maybeShowMetaDialog = function () {
var target = this;
this.welcomeDialogPromise
.always( function () {
// Pop out the notices when the welcome dialog is closed
target.actionsToolbar.tools.notices.getPopup().toggle( true );
} );
if ( this.getSurface().getModel().metaList.getItemsInGroup( 'mwRedirect' ).length ) { if ( this.getSurface().getModel().metaList.getItemsInGroup( 'mwRedirect' ).length ) {
this.getSurface().getDialogs().openWindow( 'meta', { this.getSurface().getDialogs().openWindow( 'meta', {