mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 08:34:54 +00:00
8d33a3de0d
* Made method descriptions imperative: "Do this" rather than "Does this" * Changed use of "this object" to "the object" in method documentation * Added missing documentation * Fixed incorrect documentation * Fixed incorrect debug method names (as in those VeDmClassName tags we add to functions so they make sense when dumped into in the console) * Normalized use of package names throughout * Normalized class descriptions * Removed incorrect @abstract tags * Added missing @method tags * Lots of other minor cleanup Change-Id: I4ea66a2dd107613e2ea3a5f56ff54d675d72957e
76 lines
1.9 KiB
JavaScript
76 lines
1.9 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface InspectorFactory class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface inspector factory.
|
|
*
|
|
* @class
|
|
* @extends ve.Factory
|
|
* @constructor
|
|
*/
|
|
ve.ui.InspectorFactory = function VeUiInspectorFactory() {
|
|
// Parent constructor
|
|
ve.Factory.call( this );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.InspectorFactory, ve.Factory );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get 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 );
|
|
};
|
|
|
|
/**
|
|
* Reduce an annotation 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 ) {
|
|
if ( annotations.isEmpty() ) {
|
|
return [];
|
|
}
|
|
|
|
var i, len, j, annotation,
|
|
matches = [],
|
|
inspectors = this.entries.slice( 0 ),
|
|
inspector,
|
|
arr = annotations.get();
|
|
|
|
for ( i = 0, len = arr.length; i < len; i++ ) {
|
|
annotation = arr[i];
|
|
j = inspectors.length;
|
|
while ( inspectors[--j] ) {
|
|
inspector = inspectors[j];
|
|
if ( this.registry[inspector].static.typePattern.test( annotation.name ) ) {
|
|
matches.push( inspector );
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return matches;
|
|
};
|
|
|
|
/* Initialization */
|
|
|
|
ve.ui.inspectorFactory = new ve.ui.InspectorFactory();
|