mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +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
234 lines
5.2 KiB
JavaScript
234 lines
5.2 KiB
JavaScript
/**
|
|
* VisualEditor user interface Inspector class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.Inspector object.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.EventEmitter}
|
|
* @param {ve.ui.Context} context
|
|
*/
|
|
ve.ui.Inspector = function VeUiInspector( context ) {
|
|
// Inheritance
|
|
ve.EventEmitter.call( this );
|
|
|
|
// Properties
|
|
this.context = context;
|
|
this.disabled = false;
|
|
this.frame = context.getFrame();
|
|
this.$ = $( '<div class="ve-ui-inspector"></div>' );
|
|
this.$form = this.frame.$$( '<form></form>' );
|
|
this.$title = this.frame.$$( '<div class="ve-ui-inspector-title"></div>' )
|
|
.text( ve.msg( this.constructor.static.titleMessage ) );
|
|
this.$titleIcon = this.frame.$$( '<div class="ve-ui-inspector-titleIcon"></div>' )
|
|
.addClass( 've-ui-icon-' + this.constructor.static.icon );
|
|
this.$closeButton = this.frame.$$(
|
|
'<div class="ve-ui-inspector-button ve-ui-inspector-closeButton ve-ui-icon-close"></div>'
|
|
);
|
|
this.$removeButton = this.frame.$$(
|
|
'<div class="ve-ui-inspector-button ve-ui-inspector-removeButton ve-ui-icon-remove"></div>'
|
|
);
|
|
|
|
// Events
|
|
this.$closeButton.on( {
|
|
'click': ve.bind( this.onCloseButtonClick, this ),
|
|
} );
|
|
this.$removeButton.on( {
|
|
'click': ve.bind( this.onRemoveButtonClick, this ),
|
|
} );
|
|
this.$form.on( {
|
|
'submit': ve.bind( this.onFormSubmit, this ),
|
|
'keydown': ve.bind( this.onFormKeyDown, this )
|
|
} );
|
|
|
|
// Initialization
|
|
this.$.append(
|
|
this.$closeButton,
|
|
this.$titleIcon,
|
|
this.$title,
|
|
this.$removeButton,
|
|
this.$form
|
|
);
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.Inspector, ve.EventEmitter );
|
|
|
|
/* Static Members */
|
|
|
|
ve.ui.Inspector.static.icon = 'inspector';
|
|
|
|
ve.ui.Inspector.static.titleMessage = 'visualeditor-inspector-title';
|
|
|
|
ve.ui.Inspector.static.typePattern = new RegExp();
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Checks if this inspector is disabled.
|
|
*
|
|
* @method
|
|
* @param {Boolean} Inspector is disabled
|
|
*/
|
|
ve.ui.Inspector.prototype.isDisabled = function () {
|
|
return this.disabled;
|
|
};
|
|
|
|
/**
|
|
* Disables inspector.
|
|
*
|
|
* @method
|
|
* @param {Boolean} state Disable inspector
|
|
*/
|
|
ve.ui.Inspector.prototype.setDisabled = function ( state ) {
|
|
this.disabled = !!state;
|
|
if ( this.disabled ) {
|
|
this.$.addClass( 've-ui-inspector-disabled' );
|
|
} else {
|
|
this.$.removeClass( 've-ui-inspector-disabled' );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Responds to close button click events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Click event
|
|
*/
|
|
ve.ui.Inspector.prototype.onCloseButtonClick = function () {
|
|
this.context.closeInspector( true );
|
|
};
|
|
|
|
/**
|
|
* Responds to remove button click events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Click event
|
|
* @emits 'remove'
|
|
*/
|
|
ve.ui.Inspector.prototype.onRemoveButtonClick = function() {
|
|
if ( !this.disabled ) {
|
|
this.context.getSurface().execute(
|
|
'annotation', 'clearAll', this.constructor.static.typePattern
|
|
);
|
|
this.onRemove();
|
|
this.emit( 'remove' );
|
|
}
|
|
this.context.closeInspector();
|
|
};
|
|
|
|
/**
|
|
* Responds to form submission events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Submit event
|
|
*/
|
|
ve.ui.Inspector.prototype.onFormSubmit = function ( e ) {
|
|
e.preventDefault();
|
|
if ( this.$.hasClass( 've-ui-inspector-disabled' ) ) {
|
|
return;
|
|
}
|
|
this.context.closeInspector( true );
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Responds to form keydown events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Keydown event
|
|
*/
|
|
ve.ui.Inspector.prototype.onFormKeyDown = function ( e ) {
|
|
// Escape
|
|
if ( e.which === 27 ) {
|
|
this.context.closeInspector( true );
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Responds to the inspector being opened.
|
|
*
|
|
* This is when an inspector would initialize it's form with data from the selection.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Inspector.prototype.onOpen = function () {
|
|
// This is a stub, override functionality in child classes
|
|
};
|
|
|
|
/**
|
|
* Responds to the inspector being closed.
|
|
*
|
|
* This is when an inspector would apply any changes made in the form to the selection.
|
|
*
|
|
* @method
|
|
* @param {Boolean} accept Changes to the form should be applied
|
|
*/
|
|
ve.ui.Inspector.prototype.onClose = function () {
|
|
// This is a stub, override functionality in child classes
|
|
};
|
|
|
|
/**
|
|
* Responds to the annotation being inspected being removed.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Inspector.prototype.onRemove = function () {
|
|
// This is a stub, override functionality in child classes
|
|
};
|
|
|
|
/**
|
|
* Prepares the inspector to be opened.
|
|
*
|
|
* This gives an inspector an opportunity to make selection and annotation changes prior to the
|
|
* inspector being opened.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Inspector.prototype.prepareSelection = function () {
|
|
// This is a stub, override functionality in child classes
|
|
};
|
|
|
|
/**
|
|
* Gets a list of matching annotations in selection.
|
|
*
|
|
* @method
|
|
* @returns {ve.AnnotationSet} Matching annotations
|
|
*/
|
|
ve.ui.Inspector.prototype.getMatchingAnnotations = function () {
|
|
return this.context.getSurface().getModel().getFragment().getAnnotations()
|
|
.getAnnotationsByName( this.constructor.static.typePattern );
|
|
};
|
|
|
|
/**
|
|
* Opens inspector.
|
|
*
|
|
* @method
|
|
* @emits 'open'
|
|
*/
|
|
ve.ui.Inspector.prototype.open = function () {
|
|
this.$.show();
|
|
this.onOpen();
|
|
this.emit( 'open' );
|
|
};
|
|
|
|
/**
|
|
* Closes inspector.
|
|
*
|
|
* @method
|
|
* @emits 'close'
|
|
*/
|
|
ve.ui.Inspector.prototype.close = function ( accept ) {
|
|
this.$.hide();
|
|
this.onClose( accept );
|
|
this.emit( 'close' );
|
|
};
|