mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
44e47a6e8f
If a references list node is selected, open the dialog to edit it. Otherwise just insert the references list for the default group, since this is what the user wants to do in 99% of cases. * Replaced the simple 'referencesList' command (which opened the dialog) with a custom implementation in ve.ui.MWReferencesListCommand, which inserts the references list or opens the dialog like before. * Removed the ability to insert a references list from ve.ui.MWReferencesListDialog, since it should now never open without a references list selected. If it does, throw an error. I considered the behavior of always showing the dialog if there is at least one references list already in the document, but I think it would be confusing if the tool behaved differently depending on the state of the document (rather than merely current selection). Bug: T71727 Change-Id: Ifbbfa28548de9c0435c5174fb7762079f59bac54
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface MediaWiki ReferencesListCommand class.
|
|
*
|
|
* @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
|
|
*/
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.Command
|
|
*
|
|
* @constructor
|
|
*/
|
|
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 */
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWReferencesListCommand.prototype.execute = function ( surface ) {
|
|
var
|
|
fragment = surface.getModel().getFragment(),
|
|
selectedNode = fragment.getSelectedNode(),
|
|
isReflistNodeSelected = selectedNode && selectedNode instanceof ve.dm.MWReferencesListNode;
|
|
|
|
if ( isReflistNodeSelected ) {
|
|
return surface.execute( 'window', 'open', 'referencesList' );
|
|
} else {
|
|
fragment.collapseToEnd().insertContent( [
|
|
{
|
|
type: 'mwReferencesList',
|
|
attributes: {
|
|
listGroup: 'mwReference/',
|
|
refGroup: ''
|
|
}
|
|
},
|
|
{ type: '/mwReferencesList' }
|
|
] );
|
|
return true;
|
|
}
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.commandRegistry.register( new ve.ui.MWReferencesListCommand() );
|