mediawiki-extensions-Visual.../modules/ve-mw/ui/commands/ve.ui.MWUseExistingReferenceCommand.js
James D. Forrester 19df1d4c8a build: Enable jscs rule 'requireVarDeclFirst' and make pass
Change-Id: Ia2f765d12bde001c329c2ff4c080a36b71de9803
2015-08-19 11:05:01 -07:00

53 lines
1.3 KiB
JavaScript

/*!
* VisualEditor UserInterface MediaWiki UseExistingReferenceCommand class.
*
* @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
*/
/**
* 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() );