mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-05 22:22:54 +00:00
9df1a59818
Ed & Roan: Disable editing of references of which we are unable to find the source (e.g. <ref name="x"> without a target, or when the target is currently nested in something we don't yet process such as inside a <references> block or a template). Timo: Improve UI to not be a regular focusable node where the inspector just won't show up but add a not-allowed cursor and explanatory tooltip. James: Fix messages to refer to VisualEditor instead of "the" VisualEditor. Change-Id: Ib2bca092ce13c9187fa8b27ad6a6404cae02aea2
104 lines
2.9 KiB
JavaScript
104 lines
2.9 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface ToolFactory class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface tool factory.
|
|
*
|
|
* @class
|
|
* @extends ve.Factory
|
|
* @constructor
|
|
*/
|
|
ve.ui.ToolFactory = function VeUiToolFactory() {
|
|
// Parent constructor
|
|
ve.Factory.call( this );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.ToolFactory, ve.Factory );
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get a list of tools from a set of annotations.
|
|
*
|
|
* The most specific tool will be chosen based on inheritance - mostly. The order of being added
|
|
* also matters if the candidate classes aren't all in the same inheritance chain, and since object
|
|
* properties aren't necessarily ordered it's not predictable what the effect of ordering will be.
|
|
*
|
|
* TODO: Add tracking of order of registration using an array and prioritize the most recently
|
|
* registered candidate.
|
|
*
|
|
* @method
|
|
* @param {ve.dm.AnnotationSet} annotations Annotations to be inspected
|
|
* @returns {string[]} Symbolic names of tools that can be used to inspect annotations
|
|
*/
|
|
ve.ui.ToolFactory.prototype.getToolsForAnnotations = function ( annotations ) {
|
|
if ( annotations.isEmpty() ) {
|
|
return [];
|
|
}
|
|
|
|
var i, len, annotation, name, tool, candidateTool, candidateToolName,
|
|
arr = annotations.get(),
|
|
matches = [];
|
|
|
|
for ( i = 0, len = arr.length; i < len; i++ ) {
|
|
annotation = arr[i];
|
|
candidateTool = null;
|
|
for ( name in this.registry ) {
|
|
tool = this.registry[name];
|
|
if ( tool.static.canEditModel( annotation ) ) {
|
|
if ( !candidateTool || tool.prototype instanceof candidateTool ) {
|
|
candidateTool = tool;
|
|
candidateToolName = name;
|
|
}
|
|
}
|
|
}
|
|
if ( candidateTool ) {
|
|
matches.push( candidateToolName );
|
|
}
|
|
}
|
|
return matches;
|
|
};
|
|
|
|
/**
|
|
* Get a tool for a node.
|
|
*
|
|
* The most specific tool will be chosen based on inheritance - mostly. The order of being added
|
|
* also matters if the candidate classes aren't all in the same inheritance chain, and since object
|
|
* properties aren't necessarily ordered it's not predictable what the effect of ordering will be.
|
|
*
|
|
* TODO: Add tracking of order of registration using an array and prioritize the most recently
|
|
* registered candidate.
|
|
*
|
|
* @method
|
|
* @param {ve.dm.Node} node Node to be edited
|
|
* @returns {string|undefined} Symbolic name of tool that can be used to edit node
|
|
*/
|
|
ve.ui.ToolFactory.prototype.getToolForNode = function ( node ) {
|
|
var name, tool, candidateTool, candidateToolName;
|
|
|
|
if ( !node.isInspectable() ) {
|
|
return undefined;
|
|
}
|
|
|
|
for ( name in this.registry ) {
|
|
tool = this.registry[name];
|
|
if ( tool.static.canEditModel( node ) ) {
|
|
if ( !candidateTool || tool.prototype instanceof candidateTool ) {
|
|
candidateTool = tool;
|
|
candidateToolName = name;
|
|
}
|
|
}
|
|
}
|
|
return candidateToolName;
|
|
};
|
|
|
|
/* Initialization */
|
|
|
|
ve.ui.toolFactory = new ve.ui.ToolFactory();
|