From e1f4e3f14833511a549b8b3e8a70aa1cfa993a07 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Fri, 17 Apr 2020 14:19:55 -0700 Subject: [PATCH] ArticleTarget: Move shouldShowWelcomeDialog() into DesktopArticleTarget The base class doesn't use it, it only defines it, and DesktopArticleTarget is the only subclass that uses it. MobileArticleTarget calls it, but also overrides it to be a no-op. Change-Id: Ib3feea94844f4e1ed71dccece7657450516cac89 --- .../init/targets/ve.init.mw.ArticleTarget.js | 68 ------------------- .../ve.init.mw.DesktopArticleTarget.js | 67 ++++++++++++++++++ .../targets/ve.init.mw.MobileArticleTarget.js | 10 --- 3 files changed, 67 insertions(+), 78 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js index 73f62c425d..80f2652d95 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ArticleTarget.js @@ -79,9 +79,6 @@ ve.init.mw.ArticleTarget = function VeInitMwArticleTarget( config ) { trackActivationComplete: function () {} }; - this.welcomeDialog = null; - this.welcomeDialogPromise = null; - this.preparedCacheKeyPromise = null; this.clearState(); @@ -2078,71 +2075,6 @@ ve.init.mw.ArticleTarget.prototype.getSectionFragmentFromPage = function ( conte return ''; }; -ve.init.mw.ArticleTarget.prototype.shouldShowWelcomeDialog = function () { - return !( - // Disabled in config? - !mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome || - // Hidden using URL parameter? - 'vehidebetadialog' in new mw.Uri().query || - // Hidden using preferences? - mw.user.options.get( 'visualeditor-hidebetawelcome' ) || - // Hidden using local storage or cookie (anons only)? - ( - mw.user.isAnon() && ( - mw.storage.get( 've-beta-welcome-dialog' ) || - $.cookie( 've-beta-welcome-dialog' ) - ) - ) - ); -}; - -ve.init.mw.ArticleTarget.prototype.stopShowingWelcomeDialog = function () { - if ( mw.user.isAnon() ) { - // Try local storage first; if that fails, set a cookie - if ( !mw.storage.set( 've-beta-welcome-dialog', 1 ) ) { - $.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } ); - } - } else { - this.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' ); - mw.user.options.set( 'visualeditor-hidebetawelcome', '1' ); - } -}; - -/** - * Show the beta dialog as needed - */ -ve.init.mw.ArticleTarget.prototype.maybeShowWelcomeDialog = function () { - var editorMode = this.getDefaultMode(), - windowManager = this.getSurface().dialogs, - target = this; - - this.welcomeDialogPromise = ve.createDeferred(); - - if ( this.shouldShowWelcomeDialog() ) { - this.welcomeDialog = new mw.libs.ve.WelcomeDialog(); - windowManager.addWindows( [ this.welcomeDialog ] ); - windowManager.openWindow( - this.welcomeDialog, - { - switchable: editorMode === 'source' ? this.isModeAvailable( 'visual' ) : true, - editor: editorMode - } - ) - .closed.then( function ( data ) { - target.welcomeDialogPromise.resolve(); - target.welcomeDialog = null; - if ( data && data.action === 'switch-wte' ) { - target.switchToWikitextEditor( false ); - } else if ( data && data.action === 'switch-ve' ) { - target.switchToVisualEditor(); - } - } ); - this.stopShowingWelcomeDialog(); - } else { - this.welcomeDialogPromise.reject(); - } -}; - /** * Switches to the wikitext editor, either keeping (default) or discarding changes. * diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index c95b371464..32d5e413f2 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -37,6 +37,8 @@ ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config this.toolbarSetupDeferred = null; this.suppressNormalStartupDialogs = false; this.editingTabDialog = null; + this.welcomeDialog = null; + this.welcomeDialogPromise = null; // 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 @@ -1397,6 +1399,71 @@ ve.init.mw.DesktopArticleTarget.prototype.teardownUnloadHandlers = function () { window.removeEventListener( 'unload', this.onUnloadHandler ); }; +ve.init.mw.DesktopArticleTarget.prototype.shouldShowWelcomeDialog = function () { + return !( + // Disabled in config? + !mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome || + // Hidden using URL parameter? + 'vehidebetadialog' in new mw.Uri().query || + // Hidden using preferences? + mw.user.options.get( 'visualeditor-hidebetawelcome' ) || + // Hidden using local storage or cookie (anons only)? + ( + mw.user.isAnon() && ( + mw.storage.get( 've-beta-welcome-dialog' ) || + $.cookie( 've-beta-welcome-dialog' ) + ) + ) + ); +}; + +ve.init.mw.DesktopArticleTarget.prototype.stopShowingWelcomeDialog = function () { + if ( mw.user.isAnon() ) { + // Try local storage first; if that fails, set a cookie + if ( !mw.storage.set( 've-beta-welcome-dialog', 1 ) ) { + $.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } ); + } + } else { + this.getLocalApi().saveOption( 'visualeditor-hidebetawelcome', '1' ); + mw.user.options.set( 'visualeditor-hidebetawelcome', '1' ); + } +}; + +/** + * Show the beta dialog as needed + */ +ve.init.mw.DesktopArticleTarget.prototype.maybeShowWelcomeDialog = function () { + var editorMode = this.getDefaultMode(), + windowManager = this.getSurface().dialogs, + target = this; + + this.welcomeDialogPromise = ve.createDeferred(); + + if ( this.shouldShowWelcomeDialog() ) { + this.welcomeDialog = new mw.libs.ve.WelcomeDialog(); + windowManager.addWindows( [ this.welcomeDialog ] ); + windowManager.openWindow( + this.welcomeDialog, + { + switchable: editorMode === 'source' ? this.isModeAvailable( 'visual' ) : true, + editor: editorMode + } + ) + .closed.then( function ( data ) { + target.welcomeDialogPromise.resolve(); + target.welcomeDialog = null; + if ( data && data.action === 'switch-wte' ) { + target.switchToWikitextEditor( false ); + } else if ( data && data.action === 'switch-ve' ) { + target.switchToVisualEditor(); + } + } ); + this.stopShowingWelcomeDialog(); + } else { + this.welcomeDialogPromise.reject(); + } +}; + /** * Show the meta dialog as needed on load. */ diff --git a/modules/ve-mw/init/targets/ve.init.mw.MobileArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.MobileArticleTarget.js index 1d18a7f7c7..82bddafd0f 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.MobileArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.MobileArticleTarget.js @@ -287,8 +287,6 @@ ve.init.mw.MobileArticleTarget.prototype.surfaceReady = function () { this.events.trackActivationComplete(); - this.maybeShowWelcomeDialog(); - if ( ve.init.platform.constructor.static.isIos() ) { if ( this.viewportZoomHandler ) { this.viewportZoomHandler.detach(); @@ -298,14 +296,6 @@ ve.init.mw.MobileArticleTarget.prototype.surfaceReady = function () { } }; -/** - * @inheritdoc - */ -ve.init.mw.MobileArticleTarget.prototype.maybeShowWelcomeDialog = function () { - // Never show the dialog (T227670), but set up this promise in case something depends on it - this.welcomeDialogPromise = ve.createDeferred().reject(); -}; - /** * Match the content padding to the toolbar height */