X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/extensions/Cite/modules/ve-cite/ve.ui.MWUseExistingReferenceCommand.js diff --git a/extensions/Cite/modules/ve-cite/ve.ui.MWUseExistingReferenceCommand.js b/extensions/Cite/modules/ve-cite/ve.ui.MWUseExistingReferenceCommand.js new file mode 100644 index 00000000..65912bbb --- /dev/null +++ b/extensions/Cite/modules/ve-cite/ve.ui.MWUseExistingReferenceCommand.js @@ -0,0 +1,53 @@ +/*! + * VisualEditor UserInterface MediaWiki UseExistingReferenceCommand class. + * + * @copyright 2011-2017 Cite VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * Use existing reference command. + * + * @class + * @extends ve.ui.Command + * + * @constructor + */ +ve.ui.MWUseExistingReferenceCommand = function VeUiMWUseExistingReferenceCommand() { + // Parent constructor + ve.ui.MWUseExistingReferenceCommand.super.call( + this, 'reference/existing', 'window', 'open', + { args: [ 'reference', { useExisting: true } ], supportedSelections: [ 'linear' ] } + ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.MWUseExistingReferenceCommand, ve.ui.Command ); + +/* Methods */ + +/** + * @inheritdoc + */ +ve.ui.MWUseExistingReferenceCommand.prototype.isExecutable = function ( fragment ) { + var groupName, groups; + + // Parent method + if ( !ve.ui.MWUseExistingReferenceCommand.super.prototype.isExecutable.apply( this, arguments ) ) { + return false; + } + + groups = fragment.getDocument().getInternalList().getNodeGroups(); + + for ( groupName in groups ) { + if ( groupName.lastIndexOf( 'mwReference/' ) === 0 && groups[ groupName ].indexOrder.length ) { + return true; + } + } + return false; +}; + +/* Registration */ + +ve.ui.commandRegistry.register( new ve.ui.MWUseExistingReferenceCommand() );