Jforrester has uploaded a new change for review.
https://gerrit.wikimedia.org/r/250865
Change subject: Use mw.loader.using instead of weird hacks to load OOjs UI on
action=edit
......................................................................
Use mw.loader.using instead of weird hacks to load OOjs UI on action=edit
Change-Id: If03dab6130aed7662b04000b809884a514bb2762
---
M .jsduck/categories.json
M .jsduck/mw-categories.json
M VisualEditor.hooks.php
M extension.json
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
R modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js
6 files changed, 49 insertions(+), 41 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/65/250865/1
diff --git a/.jsduck/categories.json b/.jsduck/categories.json
index 87a42c5..c803a53 100644
--- a/.jsduck/categories.json
+++ b/.jsduck/categories.json
@@ -11,6 +11,12 @@
]
},
{
+ "name": "Switching",
+ "classes": [
+ "mw.libs.ve.SwitchConfirmDialog"
+ ]
+ },
+ {
"name": "User Interface",
"classes": [
"ve.ui.MW*Page",
diff --git a/.jsduck/mw-categories.json b/.jsduck/mw-categories.json
index 446e510..12657b2 100644
--- a/.jsduck/mw-categories.json
+++ b/.jsduck/mw-categories.json
@@ -11,6 +11,12 @@
]
},
{
+ "name": "Switching",
+ "classes": [
+ "mw.libs.ve.SwitchConfirmDialog"
+ ]
+ },
+ {
"name": "User Interface",
"classes": [
"ve.ui.MW*Page",
diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index 1962b80..4b65639 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -45,9 +45,6 @@
'ext.visualEditor.desktopArticleTarget.init',
'ext.visualEditor.targetLoader'
) );
- if ( in_array( Action::getActionName( RequestContext::getMain()
), array( 'edit', 'submit' ) ) ) {
- $output->addModules( 'ext.visualEditor.switching' );
- }
$output->addModuleStyles( array(
'ext.visualEditor.desktopArticleTarget.noscript' ) );
// add scroll offset js variable to output
$veConfig = ConfigFactory::getDefaultInstance()->makeConfig(
'visualeditor' );
diff --git a/extension.json b/extension.json
index 8701829..a3ebf2b 100644
--- a/extension.json
+++ b/extension.json
@@ -970,12 +970,11 @@
},
"ext.visualEditor.switching": {
"scripts": [
-
"modules/ve-mw/ui/dialogs/ve.ui.MWVESwitchConfirmDialog.js"
+
"modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js"
],
"dependencies": [
"oojs",
- "oojs-ui",
- "ext.visualEditor.core"
+ "oojs-ui"
],
"messages": [
"visualeditor-mweditmodeve-title",
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
index 672ea79..75c6664 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
@@ -417,6 +417,7 @@
if ( pageCanLoadVE ) {
// Allow instant switching to edit mode,
without refresh
+ mw.loader.load( 'ext.visualEditor.switching' );
$caVeEdit.click( init.onEditTabClick );
}
},
@@ -503,8 +504,7 @@
},
onEditTabClick: function ( e ) {
- var wikitextModified = $( '#wpTextbox1' ).val() !==
initialWikitext,
- windowManager, switchWindow;
+ var wikitextModified = $( '#wpTextbox1' ).val() !==
initialWikitext;
// Default mouse button is normalised by jQuery to key
code 1.
// Only do our handling if no keys are pressed, mouse
button is 1
@@ -515,24 +515,27 @@
}
if ( !isViewPage && ( mw.config.get( 'wgAction' ) ===
'submit' || wikitextModified ) ) {
- // Prompt if either we're on action=submit (the
user has previewed) or
- // the wikitext hash is different to the value
observed upon page load.
+ mw.loader.using( 'ext.visualEditor.switching' )
+ .done( function () {
+ var windowManager = new
OO.ui.WindowManager(),
+ switchWindow = new
mw.libs.ve.SwitchConfirmDialog();
+ // Prompt if either we're on
action=submit (the user has previewed) or
+ // the wikitext hash is
different to the value observed upon page load.
- windowManager = new OO.ui.WindowManager();
- $( 'body' ).append( windowManager.$element );
- switchWindow = new
ve.ui.MWVESwitchConfirmDialog();
- windowManager.addWindows( [ switchWindow ] );
- windowManager.openWindow( switchWindow ).done(
function ( opened ) {
- opened.done( function ( closing ) {
- closing.done( function ( data )
{
- if ( data &&
data.action === 'keep' ) {
-
activatePageTarget();
- } else if ( data &&
data.action === 'discard' ) {
- location.href =
veEditUri;
- }
+ $( 'body' ).append(
windowManager.$element );
+ windowManager.addWindows( [
switchWindow ] );
+ windowManager.openWindow(
switchWindow ).done( function ( opened ) {
+ opened.done( function (
closing ) {
+ closing.done(
function ( data ) {
+ if (
data && data.action === 'keep' ) {
+
activatePageTarget();
+ } else
if ( data && data.action === 'discard' ) {
+
location.href = veEditUri;
+ }
+ } );
+ } );
} );
} );
- } );
} else {
activatePageTarget();
}
diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWVESwitchConfirmDialog.js
b/modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js
similarity index 65%
rename from modules/ve-mw/ui/dialogs/ve.ui.MWVESwitchConfirmDialog.js
rename to modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js
index 6cf9a62..9383cd4 100644
--- a/modules/ve-mw/ui/dialogs/ve.ui.MWVESwitchConfirmDialog.js
+++ b/modules/ve-mw/init/ve.init.MWVESwitchConfirmDialog.js
@@ -5,6 +5,7 @@
* @license The MIT License (MIT); see LICENSE.txt
*/
+mw.libs.ve = mw.libs.ve || {};
/**
* Dialog for letting the user choose how to switch to wikitext mode.
*
@@ -14,32 +15,32 @@
* @constructor
* @param {Object} [config] Configuration options
*/
-ve.ui.MWVESwitchConfirmDialog = function VeUiMWVESwitchConfirmDialog( config )
{
+mw.libs.ve.SwitchConfirmDialog = function MWLibsVESwitchConfirmDialog( config
) {
// Parent constructor
- ve.ui.MWVESwitchConfirmDialog.super.call( this, config );
+ mw.libs.ve.SwitchConfirmDialog.super.call( this, config );
};
/* Inheritance */
-OO.inheritClass( ve.ui.MWVESwitchConfirmDialog, OO.ui.MessageDialog );
+OO.inheritClass( mw.libs.ve.SwitchConfirmDialog, OO.ui.MessageDialog );
/* Static Properties */
-ve.ui.MWVESwitchConfirmDialog.static.name = 'veswitchconfirm';
+mw.libs.ve.SwitchConfirmDialog.static.name = 'veswitchconfirm';
-ve.ui.MWVESwitchConfirmDialog.static.verbose = true;
+mw.libs.ve.SwitchConfirmDialog.static.verbose = true;
-ve.ui.MWVESwitchConfirmDialog.static.size = 'small';
+mw.libs.ve.SwitchConfirmDialog.static.size = 'small';
-ve.ui.MWVESwitchConfirmDialog.static.icon = 'help';
+mw.libs.ve.SwitchConfirmDialog.static.icon = 'help';
-ve.ui.MWVESwitchConfirmDialog.static.title =
+mw.libs.ve.SwitchConfirmDialog.static.title =
mw.msg( 'visualeditor-mweditmodeve-title' );
-ve.ui.MWVESwitchConfirmDialog.static.message =
+mw.libs.ve.SwitchConfirmDialog.static.message =
mw.msg( 'visualeditor-mweditmodeve-warning' );
-ve.ui.MWVESwitchConfirmDialog.static.actions = [
+mw.libs.ve.SwitchConfirmDialog.static.actions = [
{
action: 'cancel',
label: mw.msg( 'visualeditor-mweditmodesource-warning-cancel' ),
@@ -65,8 +66,8 @@
/**
* @inheritdoc
*/
-ve.ui.MWVESwitchConfirmDialog.prototype.getSetupProcess = function () {
- return
ve.ui.MWVESwitchConfirmDialog.super.prototype.getSetupProcess.apply( this,
arguments )
+mw.libs.ve.SwitchConfirmDialog.prototype.getSetupProcess = function () {
+ return
mw.libs.ve.SwitchConfirmDialog.super.prototype.getSetupProcess.apply( this,
arguments )
.next( function () {
this.actions.setMode( mw.config.get(
'wgVisualEditorConfig' ).fullRestbaseUrl ? 'restbase' : 'simple' );
}, this );
@@ -75,7 +76,7 @@
/**
* @inheritdoc
*/
-ve.ui.MWVESwitchConfirmDialog.prototype.getActionProcess = function ( action )
{
+mw.libs.ve.SwitchConfirmDialog.prototype.getActionProcess = function ( action
) {
if ( action === 'keep' ) {
return new OO.ui.Process( function () {
this.getActions()
@@ -97,9 +98,5 @@
}
// Parent method
- return
ve.ui.MWVESwitchConfirmDialog.super.prototype.getActionProcess.call( this,
action );
+ return
mw.libs.ve.SwitchConfirmDialog.super.prototype.getActionProcess.call( this,
action );
};
-
-/* Registration */
-
-ve.ui.windowFactory.register( ve.ui.MWVESwitchConfirmDialog );
--
To view, visit https://gerrit.wikimedia.org/r/250865
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If03dab6130aed7662b04000b809884a514bb2762
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: wmf/1.27.0-wmf.5
Gerrit-Owner: Jforrester <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits