mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-23 16:06:53 +00:00
Merge "Delay the load of VE modules until we're sure they're needed"
This commit is contained in:
commit
18af8d462d
|
@ -8,35 +8,8 @@ var
|
|||
top: 10 + ( $( document.documentElement ).hasClass( 'vector-feature-sticky-header-enabled' ) ? 50 : 0 ),
|
||||
bottom: 10
|
||||
},
|
||||
defaultEditMode = mw.user.options.get( 'discussiontools-editmode' ) || mw.config.get( 'wgDiscussionToolsFallbackEditMode' ),
|
||||
defaultVisual = defaultEditMode === 'visual',
|
||||
featuresEnabled = mw.config.get( 'wgDiscussionToolsFeaturesEnabled' ) || {},
|
||||
enable2017Wikitext = featuresEnabled.sourcemodetoolbar,
|
||||
conf = mw.config.get( 'wgVisualEditorConfig' ),
|
||||
visualModules = [ 'ext.discussionTools.ReplyWidgetVisual' ]
|
||||
.concat( conf.pluginModules.filter( mw.loader.getState ) ),
|
||||
plainModules = [ 'ext.discussionTools.ReplyWidgetPlain' ];
|
||||
|
||||
if ( OO.ui.isMobile() ) {
|
||||
visualModules = [
|
||||
'ext.visualEditor.core.mobile',
|
||||
'ext.visualEditor.mwextensions'
|
||||
].concat( visualModules );
|
||||
} else {
|
||||
visualModules = [
|
||||
'ext.visualEditor.core.desktop',
|
||||
'ext.visualEditor.desktopTarget',
|
||||
'ext.visualEditor.mwextensions.desktop'
|
||||
].concat( visualModules );
|
||||
}
|
||||
|
||||
// Start loading reply widget code
|
||||
if ( defaultVisual || enable2017Wikitext ) {
|
||||
mw.loader.using( visualModules );
|
||||
} else {
|
||||
mw.loader.using( plainModules );
|
||||
}
|
||||
|
||||
defaultVisual = controller.defaultVisual,
|
||||
enable2017Wikitext = controller.enable2017Wikitext;
|
||||
/**
|
||||
* Handles setup, save and teardown of commenting widgets
|
||||
*
|
||||
|
@ -326,7 +299,7 @@ CommentController.prototype.getReplyWidgetClass = function ( visual ) {
|
|||
// If 2017WTE mode is enabled, always use ReplyWidgetVisual.
|
||||
visual = visual || enable2017Wikitext;
|
||||
|
||||
return mw.loader.using( visual ? visualModules : plainModules ).then( function () {
|
||||
return mw.loader.using( controller.getReplyWidgetModules( visual ) ).then( function () {
|
||||
return require( visual ? 'ext.discussionTools.ReplyWidgetVisual' : 'ext.discussionTools.ReplyWidgetPlain' );
|
||||
} );
|
||||
};
|
||||
|
|
|
@ -341,4 +341,14 @@ ReplyLinksController.prototype.teardown = function () {
|
|||
}
|
||||
};
|
||||
|
||||
ReplyLinksController.prototype.pageHasReplyLinks = function () {
|
||||
return this.$replyLinkSets.length > 0;
|
||||
};
|
||||
|
||||
ReplyLinksController.prototype.pageHasNewTopicLink = function () {
|
||||
// Note: this will miss if there are random on-page links that would
|
||||
// trigger the new topic tool via onAnyLinkClick
|
||||
return featuresEnabled.newtopictool && document.getElementById( 'ca-addsection' );
|
||||
};
|
||||
|
||||
module.exports = ReplyLinksController;
|
||||
|
|
|
@ -16,7 +16,10 @@ var
|
|||
highlighter = require( './highlighter.js' ),
|
||||
topicSubscriptions = require( './topicsubscriptions.js' ),
|
||||
pageHandlersSetup = false,
|
||||
pageDataCache = {};
|
||||
pageDataCache = {},
|
||||
defaultEditMode = mw.user.options.get( 'discussiontools-editmode' ) || mw.config.get( 'wgDiscussionToolsFallbackEditMode' ),
|
||||
defaultVisual = defaultEditMode === 'visual',
|
||||
enable2017Wikitext = featuresEnabled.sourcemodetoolbar;
|
||||
|
||||
var mobile = null;
|
||||
if ( OO.ui.isMobile() && mw.config.get( 'skin' ) === 'minerva' ) {
|
||||
|
@ -249,6 +252,36 @@ function getCheckboxesPromise( pageName, oldId ) {
|
|||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resourceloader modules required for a mode of the reply widget
|
||||
*
|
||||
* @param {boolean} visual Prefer the VE-based class
|
||||
* @return {string[]}
|
||||
*/
|
||||
function getReplyWidgetModules( visual ) {
|
||||
if ( !visual ) {
|
||||
return [ 'ext.discussionTools.ReplyWidgetPlain' ];
|
||||
}
|
||||
|
||||
var veConf = mw.config.get( 'wgVisualEditorConfig' ),
|
||||
visualModules = [ 'ext.discussionTools.ReplyWidgetVisual' ]
|
||||
.concat( veConf.pluginModules.filter( mw.loader.getState ) );
|
||||
|
||||
if ( OO.ui.isMobile() ) {
|
||||
visualModules = [
|
||||
'ext.visualEditor.core.mobile',
|
||||
'ext.visualEditor.mwextensions'
|
||||
].concat( visualModules );
|
||||
} else {
|
||||
visualModules = [
|
||||
'ext.visualEditor.core.desktop',
|
||||
'ext.visualEditor.desktopTarget',
|
||||
'ext.visualEditor.mwextensions.desktop'
|
||||
].concat( visualModules );
|
||||
}
|
||||
return visualModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Discussion Tools features
|
||||
*
|
||||
|
@ -305,6 +338,15 @@ function init( $container, state ) {
|
|||
mobile.init( $container );
|
||||
}
|
||||
|
||||
if ( linksController.pageHasReplyLinks() || linksController.pageHasNewTopicLink() ) {
|
||||
// Start loading reply widget code
|
||||
// The worst-case here is that we might be on a page with no comments
|
||||
// and the add-topic link suppressed, *but* which has valid links to
|
||||
// trigger the new topic tool within the content. If that happens,
|
||||
// the modules will still be loaded when those links are interacted with.
|
||||
mw.loader.using( getReplyWidgetModules( defaultVisual || enable2017Wikitext ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup comment controllers for each comment, and the new topic controller
|
||||
*
|
||||
|
@ -718,5 +760,8 @@ module.exports = {
|
|||
checkThreadItemOnPage: checkThreadItemOnPage,
|
||||
getCheckboxesPromise: getCheckboxesPromise,
|
||||
getApi: getApi,
|
||||
storage: storage
|
||||
storage: storage,
|
||||
getReplyWidgetModules: getReplyWidgetModules,
|
||||
defaultVisual: defaultVisual,
|
||||
enable2017Wikitext: enable2017Wikitext
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue