mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Merge "Show welcome dialog on mobile too"
This commit is contained in:
commit
e39d8a744b
|
@ -41,8 +41,6 @@ ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config
|
|||
this.recreating = false;
|
||||
this.activatingDeferred = null;
|
||||
this.toolbarSetupDeferred = null;
|
||||
this.welcomeDialog = null;
|
||||
this.welcomeDialogPromise = null;
|
||||
this.checkboxFields = null;
|
||||
this.checkboxesByName = null;
|
||||
this.$otherFields = null;
|
||||
|
@ -386,8 +384,6 @@ ve.init.mw.DesktopArticleTarget.prototype.activate = function ( dataPromise ) {
|
|||
this.activatingDeferred = $.Deferred();
|
||||
this.toolbarSetupDeferred = $.Deferred();
|
||||
|
||||
this.maybeShowWelcomeDialog();
|
||||
|
||||
$( 'html' ).removeClass( 've-loading' ).addClass( 've-activating' );
|
||||
$.when( this.activatingDeferred, this.toolbarSetupDeferred ).done( function () {
|
||||
$( 'html' ).removeClass( 've-activating' ).addClass( 've-active' );
|
||||
|
@ -633,6 +629,7 @@ ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
|
|||
ve.init.mw.DesktopArticleTarget.super.prototype.surfaceReady.apply( this, arguments );
|
||||
|
||||
this.setupUnloadHandlers();
|
||||
this.maybeShowWelcomeDialog();
|
||||
this.maybeShowMetaDialog();
|
||||
|
||||
this.activatingDeferred.resolve();
|
||||
|
@ -1217,88 +1214,6 @@ ve.init.mw.DesktopArticleTarget.prototype.teardownUnloadHandlers = function () {
|
|||
window.removeEventListener( 'unload', this.onUnloadHandler );
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the beta dialog as needed
|
||||
*/
|
||||
ve.init.mw.DesktopArticleTarget.prototype.maybeShowWelcomeDialog = function () {
|
||||
var usePrefs, prefSaysShow, urlSaysHide, windowManager,
|
||||
target = this;
|
||||
|
||||
this.welcomeDialogPromise = $.Deferred();
|
||||
|
||||
if ( mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome ) {
|
||||
// Set up a temporary window manager
|
||||
windowManager = new OO.ui.WindowManager( {
|
||||
classes: [
|
||||
've-init-mw-desktopArticleTarget-windowManager',
|
||||
've-init-mw-desktopArticleTarget-windowManager-welcome'
|
||||
]
|
||||
} );
|
||||
$( 'body' ).append( windowManager.$element );
|
||||
this.welcomeDialog = new ve.ui.MWWelcomeDialog();
|
||||
windowManager.addWindows( [ this.welcomeDialog ] );
|
||||
|
||||
// Only use the preference value if the user is logged-in.
|
||||
// If the user is anonymous, we can't save the preference
|
||||
// after showing the dialog. And we don't intend to use this
|
||||
// preference to influence anonymous users (use the config
|
||||
// variable for that; besides the pref value would be stale if
|
||||
// the wiki uses static html caching).
|
||||
usePrefs = !mw.user.isAnon();
|
||||
prefSaysShow = usePrefs && !mw.user.options.get( 'visualeditor-hidebetawelcome' );
|
||||
urlSaysHide = 'vehidebetadialog' in this.currentUri.query;
|
||||
|
||||
if (
|
||||
!urlSaysHide &&
|
||||
(
|
||||
prefSaysShow ||
|
||||
(
|
||||
!usePrefs &&
|
||||
localStorage.getItem( 've-beta-welcome-dialog' ) === null &&
|
||||
$.cookie( 've-beta-welcome-dialog' ) === null
|
||||
)
|
||||
)
|
||||
) {
|
||||
windowManager.openWindow( this.welcomeDialog )
|
||||
.then( function ( opened ) {
|
||||
return opened;
|
||||
} )
|
||||
.then( function ( closing ) {
|
||||
return closing;
|
||||
} )
|
||||
.then( function ( data ) {
|
||||
// Detach the temporary window manager
|
||||
windowManager.destroy();
|
||||
target.welcomeDialogPromise.resolve();
|
||||
if ( data && data.action === 'switch' ) {
|
||||
target.switchToWikitextEditor( true, true );
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
this.welcomeDialogPromise.resolve();
|
||||
}
|
||||
|
||||
if ( prefSaysShow ) {
|
||||
new mw.Api().postWithToken( 'options', {
|
||||
action: 'options',
|
||||
change: 'visualeditor-hidebetawelcome=1'
|
||||
} );
|
||||
|
||||
// No need to set a cookie every time for logged-in users that have already
|
||||
// set the hidebetawelcome=1 preference, but only if this isn't a one-off
|
||||
// view of the page via the hiding GET parameter.
|
||||
} else if ( !usePrefs && !urlSaysHide ) {
|
||||
try {
|
||||
localStorage.setItem( 've-beta-welcome-dialog', 1 );
|
||||
} catch ( e ) {
|
||||
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.welcomeDialogPromise.reject();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the meta dialog as needed on load.
|
||||
*/
|
||||
|
|
|
@ -55,6 +55,9 @@ ve.init.mw.ArticleTarget = function VeInitMwArticleTarget( pageName, revisionId,
|
|||
} );
|
||||
this.events = { track: $.noop, trackActivationStart: $.noop, trackActivationComplete: $.noop };
|
||||
|
||||
this.welcomeDialog = null;
|
||||
this.welcomeDialogPromise = null;
|
||||
|
||||
this.preparedCacheKeyPromise = null;
|
||||
this.clearState();
|
||||
|
||||
|
@ -1624,3 +1627,78 @@ ve.init.mw.ArticleTarget.prototype.scrollToHeading = function ( headingNode ) {
|
|||
|
||||
$window.scrollTop( headingNode.$element.offset().top - this.getToolbar().$element.height() );
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the beta dialog as needed
|
||||
*/
|
||||
ve.init.mw.ArticleTarget.prototype.maybeShowWelcomeDialog = function () {
|
||||
var usePrefs, prefSaysShow, urlSaysHide,
|
||||
windowManager = this.getSurface().dialogs,
|
||||
target = this;
|
||||
|
||||
this.welcomeDialogPromise = $.Deferred();
|
||||
|
||||
if ( mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome ) {
|
||||
// Only use the preference value if the user is logged-in.
|
||||
// If the user is anonymous, we can't save the preference
|
||||
// after showing the dialog. And we don't intend to use this
|
||||
// preference to influence anonymous users (use the config
|
||||
// variable for that; besides the pref value would be stale if
|
||||
// the wiki uses static html caching).
|
||||
usePrefs = !mw.user.isAnon();
|
||||
prefSaysShow = usePrefs && !mw.user.options.get( 'visualeditor-hidebetawelcome' );
|
||||
urlSaysHide = 'vehidebetadialog' in new mw.Uri( location.href ).query;
|
||||
|
||||
if (
|
||||
!urlSaysHide &&
|
||||
(
|
||||
prefSaysShow ||
|
||||
(
|
||||
!usePrefs &&
|
||||
localStorage.getItem( 've-beta-welcome-dialog' ) === null &&
|
||||
$.cookie( 've-beta-welcome-dialog' ) === null
|
||||
)
|
||||
)
|
||||
) {
|
||||
windowManager.openWindow(
|
||||
'welcome',
|
||||
{ targetName: this.constructor.static.name }
|
||||
)
|
||||
.then( function ( opened ) {
|
||||
return opened;
|
||||
} )
|
||||
.then( function ( closing ) {
|
||||
return closing;
|
||||
} )
|
||||
.then( function ( data ) {
|
||||
target.welcomeDialogPromise.resolve();
|
||||
target.welcomeDialog = null;
|
||||
if ( data && data.action === 'switch' ) {
|
||||
// TODO: Make this work on mobile - right now we can only
|
||||
// get away with it because the button which triggers this
|
||||
// action is hidden on mobile
|
||||
target.switchToWikitextEditor( true, true );
|
||||
}
|
||||
} );
|
||||
this.welcomeDialog = windowManager.windows.welcome; // ew :/
|
||||
} else {
|
||||
this.welcomeDialogPromise.resolve();
|
||||
}
|
||||
|
||||
if ( prefSaysShow ) {
|
||||
new mw.Api().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
||||
|
||||
// No need to set a cookie every time for logged-in users that have already
|
||||
// set the hidebetawelcome=1 preference, but only if this isn't a one-off
|
||||
// view of the page via the hiding GET parameter.
|
||||
} else if ( !usePrefs && !urlSaysHide ) {
|
||||
try {
|
||||
localStorage.setItem( 've-beta-welcome-dialog', 1 );
|
||||
} catch ( e ) {
|
||||
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.welcomeDialogPromise.reject();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
ve.ui.MWWelcomeDialog = function VeUiMWWelcomeDialog( config ) {
|
||||
// Parent constructor
|
||||
ve.ui.MWWelcomeDialog.super.call( this, config );
|
||||
|
||||
this.$element
|
||||
.addClass( 've-init-mw-desktopArticleTarget-windowManager' )
|
||||
.addClass( 've-init-mw-desktopArticleTarget-windowManager-welcome' );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
@ -64,9 +68,24 @@ ve.ui.MWWelcomeDialog.prototype.getSetupProcess = function ( data ) {
|
|||
)
|
||||
}, data );
|
||||
|
||||
if ( data.targetName === 'mobile' ) {
|
||||
this.mobile = true;
|
||||
}
|
||||
|
||||
return ve.ui.MWWelcomeDialog.super.prototype.getSetupProcess.call( this, data );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWWelcomeDialog.prototype.getReadyProcess = function () {
|
||||
if ( this.mobile ) {
|
||||
this.actions.remove( this.actions.get( { actions: 'switch' } ) ); // ew
|
||||
}
|
||||
|
||||
return ve.ui.MWWelcomeDialog.super.prototype.getReadyProcess.apply( this, arguments );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
text-align: center;
|
||||
}
|
||||
|
||||
.ve-ui-mobileWindowManager .visualeditor-welcomedialog-content {
|
||||
background-size: 11em;
|
||||
}
|
||||
|
||||
.visualeditor-welcomedialog-content-text {
|
||||
display: inline-block;
|
||||
margin-top: 12em;
|
||||
|
|
Loading…
Reference in a new issue