mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
fdf30b1ac8
Created an IndexValueStore class which can store any object and return an integer index to its hash map. Linear data is now stored in ve.dm.LinearData instances. Two subclasses for element and meta data contain methods specific to those data types (ElementLinearData and MetaLinearData). The static methods in ve.dm.Document that inspected data at a given offset are now instance methods of ve.dm.ElementLinearData. AnnotationSets (which are no longer OrderedHashSets) have been moved to /dm and also have to be instantiated with a pointer the store. Bug: 46320 Change-Id: I249a5d48726093d1cb3e36351893f4bff85f52e2
76 lines
1.9 KiB
JavaScript
76 lines
1.9 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface InspectorFactory class.
|
|
*
|
|
* @copyright 2011-2013 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.dm.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();
|