mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 02:51:50 +00:00
a379e0f91e
Follow up for I6a7c9e8ee8f995731bc205d666167874eb2ebe23 The first pass that Timo took missed the following cases * "{Array|String}": string is just one of the values * "{String[]}": string is followed by [] to indicate an array of strings Change-Id: I65e595e8d37fb624802d84af9536a2d3c5d73c7d
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
/*!
|
|
* VisualEditor data model InspectorFactory class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel Inspector factory.
|
|
*
|
|
* @class
|
|
* @extends ve.Factory
|
|
* @constructor
|
|
*/
|
|
ve.ui.InspectorFactory = function VeDmInspectorFactory() {
|
|
// Parent constructor
|
|
ve.Factory.call( this );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.InspectorFactory, ve.Factory );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Gets an inspector constructor for a given annotation type.
|
|
*
|
|
* @method
|
|
* @param {string} name Symbolic name of inspector to get pattern for
|
|
* @returns {RegExp} Regular expression matching annotations relevant to a given inspector
|
|
* @throws {Error} Unknown inspector
|
|
*/
|
|
ve.ui.InspectorFactory.prototype.getTypePattern = function ( name ) {
|
|
if ( name in this.registry ) {
|
|
return this.registry[name].static.typePattern;
|
|
}
|
|
throw new Error( 'Unknown inspector: ' + name );
|
|
};
|
|
|
|
/**
|
|
* Reduces an annotations set to only those which can be inspected by given inspector.
|
|
*
|
|
* @method
|
|
* @param {ve.AnnotationSet} annotations Annotations to be inspected
|
|
* @returns {string[]} Symbolic names of inspectors that can be used to inspect annotations
|
|
*/
|
|
ve.ui.InspectorFactory.prototype.getInspectorsForAnnotations = function ( annotations ) {
|
|
var name,
|
|
names = [];
|
|
if ( !annotations.isEmpty() ) {
|
|
for ( name in this.registry ) {
|
|
if ( annotations.hasAnnotationWithName( this.registry[name].static.typePattern ) ) {
|
|
names.push( name );
|
|
}
|
|
}
|
|
}
|
|
return names;
|
|
};
|
|
|
|
/* Initialization */
|
|
|
|
ve.ui.inspectorFactory = new ve.ui.InspectorFactory();
|