2023-08-21 08:08:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-02-03 21:03:41 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MediaWiki ReferencesListCommand class.
|
|
|
|
*
|
2018-01-03 01:05:45 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
|
2017-12-29 12:12:35 +00:00
|
|
|
* @license MIT
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* References list command.
|
|
|
|
*
|
|
|
|
* If a references list node is selected, opens the dialog to edit it.
|
|
|
|
* Otherwise inserts the references list for the default group.
|
|
|
|
*
|
|
|
|
* @constructor
|
2024-02-28 08:57:24 +00:00
|
|
|
* @extends ve.ui.Command
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListCommand = function VeUiMWReferencesListCommand() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWReferencesListCommand.super.call(
|
|
|
|
this, 'referencesList', null, null,
|
|
|
|
{ supportedSelections: [ 'linear' ] }
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWReferencesListCommand, ve.ui.Command );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2024-02-28 08:57:24 +00:00
|
|
|
* @override
|
2016-02-03 21:03:41 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWReferencesListCommand.prototype.execute = function ( surface ) {
|
2023-08-21 08:08:23 +00:00
|
|
|
const fragment = surface.getModel().getFragment();
|
|
|
|
const selectedNode = fragment.getSelectedNode();
|
2024-01-30 11:18:52 +00:00
|
|
|
const isReflistNodeSelected = selectedNode &&
|
|
|
|
selectedNode instanceof ve.dm.MWReferencesListNode;
|
2016-02-03 21:03:41 +00:00
|
|
|
|
|
|
|
if ( isReflistNodeSelected ) {
|
|
|
|
return surface.execute( 'window', 'open', 'referencesList' );
|
|
|
|
} else {
|
|
|
|
fragment.collapseToEnd().insertContent( [
|
|
|
|
{
|
|
|
|
type: 'mwReferencesList',
|
|
|
|
attributes: {
|
|
|
|
listGroup: 'mwReference/',
|
2017-09-19 20:17:52 +00:00
|
|
|
refGroup: '',
|
|
|
|
isResponsive: mw.config.get( 'wgCiteResponsiveReferences' )
|
2016-02-03 21:03:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{ type: '/mwReferencesList' }
|
|
|
|
] );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.commandRegistry.register( new ve.ui.MWReferencesListCommand() );
|