mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
d2476a26d2
ve.AnnotationAction * Added filter to the clearAll method to allow clearing all matching annotations only ve.dm.Document * Some variable renaming for consistency ve.dm.SurfaceFragment * Added truncateRange method * Added annotation scope to expandRange method * Added support for passing an annotation object into annotateContent method * Switched to using name instead of type in annotateContent method to match the ve.dm.Annotation class * Fixed logic in annotation mode of expandSelection so that expansion only takes place if the annotation is found ve.ui.LinkInspector * Moved most of the functionality elsewhere * General reorganization * Changed setOverlayPosition to accept 2 arguments instead of an object with 2 properties and renamed it to positionOverlayBelow * Check for annotation object before extracting target information from it * Initialize default target as empty string to avoid undefined being cast to a string and the default target becoming 'undefined' icons.ai, inspector.png, inspector.svg * Added generic inspector icon which will be used when a custom icon is not specified in future inspector subclasses ve.ui.Inspector.Icons * Added inspector icon * Renamed clear icon to remove to match it's actual image ve.ui.Context * Greatly simplified the interface, reducing the number of methods by inlining a few things and combining others * Now always listening to resize events on the window rather than only while document is focused * Not listening to scroll events anymore, they used to affect the top/bottom positioning of the menu which we don't do anymore * Lots of cleanup and reorganization * No need to fallback to empty array since getInspectorsForAnnotations does so already * Only consider fully-covered annotations for inspectors ve.ui.Frame * Simplified the constructor by introducing the createFrame method * General cleanup * Typo fixes ve.ui.Inspector * Generalized lots of functionality previously located in the link inspector class which will be useful to all inspectors (such as title, clear button, saving changes, etc.) * Added setDisabled and isDisabled methods to manage CSS changes and avoid needing to check the CSS to determine the state of the inspector (storing state in the view is evil) * Added getMatchingAnnotations method for convenience * Added prepareSelection stub * Lots of cleanup and documentation * Type pattern is now defined in base class * Added stubs for onOpen and onClose with documentation so that subclass authors know what these methods do * Removed checks for onOpen or onClose methods since they are now noop stubs and are always there * Added stub and removed checks for onRemove * Made esc key close and accept - the illusion is supposed to be that the link changes are applied instantly, even though they are only updated when you close, so all closing except for when removing should apply changes - i.e. esc is now equal to back rather than being a special function that doesn't have an associated affordance * Only consider fully-covered annotations when getting matching annotations ve.ui.InspectorFactory * Depending on type pattern now since it's always there * Added getInspectorsForAnnotations method * Return empty array if annotation set is empty VisualEditor, VisualEditor.i18n * Added default inspector message Change-Id: I1cc008445bcbc8cba6754ca4b6ac0397575980d5
100 lines
2.7 KiB
JavaScript
100 lines
2.7 KiB
JavaScript
/**
|
|
* VisualEditor AnnotationAction class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Annotate action.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.Action}
|
|
* @param {ve.Surface} surface Surface to act on
|
|
*/
|
|
ve.AnnotationAction = function VeAnnotationAction( surface ) {
|
|
// Parent constructor
|
|
ve.Action.call( this, surface );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.AnnotationAction, ve.Action );
|
|
|
|
/* Static Members */
|
|
|
|
/**
|
|
* List of allowed methods for this action.
|
|
*
|
|
* @static
|
|
* @member
|
|
*/
|
|
ve.AnnotationAction.static.methods = ['set', 'clear', 'toggle', 'clearAll'];
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Sets a given annotation.
|
|
*
|
|
* @method
|
|
* @param {String} name Annotation name, for example: 'textStyle/bold'
|
|
* @param {Object} [data] Additional annotation data
|
|
*/
|
|
ve.AnnotationAction.prototype.set = function ( name, data ) {
|
|
this.surface.getModel().getFragment().annotateContent( 'set', name, data );
|
|
};
|
|
|
|
/**
|
|
* Clears a given annotation.
|
|
*
|
|
* @method
|
|
* @param {String} name Annotation name, for example: 'textStyle/bold'
|
|
* @param {Object} [data] Additional annotation data
|
|
*/
|
|
ve.AnnotationAction.prototype.clear = function ( name, data ) {
|
|
this.surface.getModel().getFragment().annotateContent( 'clear', name, data );
|
|
};
|
|
|
|
/**
|
|
* Toggles a given annotation.
|
|
*
|
|
* If the selected text is completely covered with this annotation already the annotation will be
|
|
* cleared. Otherwise the annotation will be set.
|
|
*
|
|
* @method
|
|
* @param {String} name Annotation name, for example: 'textStyle/bold'
|
|
* @param {Object} [data] Additional annotation data
|
|
*/
|
|
ve.AnnotationAction.prototype.toggle = function ( name, data ) {
|
|
var fragment = this.surface.getModel().getFragment();
|
|
fragment.annotateContent(
|
|
fragment.getAnnotations().hasAnnotationWithName( name ) ? 'clear' : 'set', name, data
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Clears all annotations.
|
|
*
|
|
* @method
|
|
* @param {String|RegExp} [filter] Annotation name or RegExp that matches types
|
|
*/
|
|
ve.AnnotationAction.prototype.clearAll = function ( filter ) {
|
|
var i, len, arr,
|
|
fragment = this.surface.getModel().getFragment(),
|
|
annotations = fragment.getAnnotations( true );
|
|
if ( typeof filter === 'string' || filter instanceof RegExp ) {
|
|
annotations = annotations.getAnnotationsByName( filter );
|
|
}
|
|
arr = annotations.get();
|
|
// TODO: Allow multiple annotations to be set or cleared by ve.dm.SurfaceFragment, probably
|
|
// using an annotation set and ideally building a single transaction
|
|
for ( i = 0, len = arr.length; i < len; i++ ) {
|
|
fragment.annotateContent( 'clear', arr[i].name, arr[i].data );
|
|
}
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.actionFactory.register( 'annotation', ve.AnnotationAction );
|