MediaWiki:Gadget-FDVEDiagramLink.js: Difference between revisions
VE plugin: double-click an embedded diagram to open its editor in a new tab |
Warn loudly if the VE classes are missing instead of failing silently |
||
| Line 28: | Line 28: | ||
'use strict'; | 'use strict'; | ||
if ( typeof ve === 'undefined' || !ve.ui || !ve.dm ) { | |||
// Not inside VisualEditor - nothing to do, and nothing worth saying. | |||
return; | |||
} | |||
// VE loads plugin modules as SIBLINGS of its own modules, not after them: | |||
// ve.init.mw.ArticleTargetLoader builds | |||
// [ 'ext.visualEditor.articleTarget', ...conf.pluginModules ] | |||
// and loads that as one batch, so there is no ordering guarantee. The classes | |||
// below therefore have to be pulled in through this gadget's own | |||
// dependencies= in MediaWiki:Gadgets-definition | |||
// (ext.visualEditor.core, ext.visualEditor.mwtransclusion). | |||
// | |||
// If that wiring is ever lost, this file would silently do nothing and the | |||
// stock template context item would take over again - which is exactly how | |||
// this failed the first time - so say so out loud. | |||
if ( | if ( | ||
!ve.ui.MWTransclusionContextItem || | !ve.ui.MWTransclusionContextItem || | ||
!ve.ui.contextItemFactory || | !ve.ui.contextItemFactory || | ||
!ve.dm.MWTransclusionNode | !ve.dm.MWTransclusionNode | ||
) { | ) { | ||
// | // eslint-disable-next-line no-console | ||
console.warn( 'FDVEDiagramLink: VisualEditor classes not available at ' + | |||
'plugin execution time; check dependencies= in MediaWiki:Gadgets-definition. ' + | |||
'Diagram nodes will fall back to the stock template context item.' ); | |||
return; | return; | ||
} | } | ||