mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 23:05:35 +00:00
ec912dc2d1
ve.ui.Widget.css * Adjust menu up a few pixels to match other uses of ve.ui.MenuWidget (the format drop down) ve.ui.LinkInspector.js * Moved the form value initialization to a timeout that fires well after the animation of the inspector - this is only important because the first element has a menu that pops up and the menu was rendering in the wrong location ve.ui.Frame.js * Added reference to frame within this.$$ by passing it to get$$ ve.ui.Inspector.js * Removed auto-focus on open from inspector base class - this will be done in a more specific and controlled way instead ve.ui.js * Added optional frame argument to get$$ so that it's easy to get the frame from any $$ that's bound to an iframe document ve.ui.Window.js * Removed duplicate static member assignments * Added auto-focus on the window's frame before calling onOpen * Added auto-blur of anything focused within the iframe after calling onClose ve.ui.MWLinkTargetInputWidget.js * Auto-highlight the selected item when populating a menu so that pressing enter always keeps the currently selected item selected ve.ui.TextInputMenuWidget.js * Take the frame's position into account when positioning a menu below an input Change-Id: I334f7db29af6b821bcfc8dc3c0ccba2636d4d9b1
155 lines
3.5 KiB
JavaScript
155 lines
3.5 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface Inspector class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* UserInterface inspector.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.Window
|
|
*
|
|
* @constructor
|
|
* @param {ve.Surface} surface
|
|
*/
|
|
ve.ui.Inspector = function VeUiInspector( surface ) {
|
|
// Inheritance
|
|
ve.ui.Window.call( this, surface );
|
|
|
|
// Properties
|
|
this.initialSelection = null;
|
|
|
|
// Initialization
|
|
this.$.addClass( 've-ui-inspector' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.Inspector, ve.ui.Window );
|
|
|
|
/* Static Properties */
|
|
|
|
/**
|
|
* Pattern to use when matching against annotation type strings.
|
|
*
|
|
* @static
|
|
* @property
|
|
* @type {RegExp}
|
|
*/
|
|
ve.ui.Inspector.static.typePattern = new RegExp();
|
|
|
|
ve.ui.Inspector.static.stylesheets =
|
|
ve.ui.Inspector.static.stylesheets.concat( [ 've.ui.Inspector.css' ] );
|
|
|
|
ve.ui.Inspector.static.titleMessage = 've-ui-inspector-title';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle frame ready events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Inspector.prototype.initialize = function () {
|
|
// Call parent method
|
|
ve.ui.Window.prototype.initialize.call( this );
|
|
|
|
// Initialization
|
|
this.$form = this.$$( '<form>' );
|
|
this.closeButton = new ve.ui.IconButtonWidget( {
|
|
'$$': this.$$, 'icon': 'previous', 'title': ve.msg( 'visualeditor-inspector-close-tooltip' )
|
|
} );
|
|
this.removeButton = new ve.ui.IconButtonWidget( {
|
|
'$$': this.$$, 'icon': 'remove', 'title': ve.msg( 'visualeditor-inspector-remove-tooltip' )
|
|
} );
|
|
|
|
// Events
|
|
this.$form.on( {
|
|
'submit': ve.bind( this.onFormSubmit, this ),
|
|
'keydown': ve.bind( this.onFormKeyDown, this )
|
|
} );
|
|
this.closeButton.on( 'click', ve.bind( this.onCloseButtonClick, this ) );
|
|
this.removeButton.on( 'click', ve.bind( this.onRemoveButtonClick, this ) );
|
|
|
|
// Initialization
|
|
this.closeButton.$.addClass( 've-ui-inspector-closeButton' );
|
|
this.removeButton.$.addClass( 've-ui-inspector-removeButton' );
|
|
this.$head.prepend( this.closeButton.$ ).append( this.removeButton.$ );
|
|
this.$body.append( this.$form );
|
|
};
|
|
|
|
/**
|
|
* Handle close button click events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Inspector.prototype.onCloseButtonClick = function () {
|
|
this.close();
|
|
};
|
|
|
|
/**
|
|
* Handle remove button click events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Inspector.prototype.onRemoveButtonClick = function() {
|
|
this.close( true );
|
|
};
|
|
|
|
/**
|
|
* Handle form submission events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Form submit event
|
|
*/
|
|
ve.ui.Inspector.prototype.onFormSubmit = function () {
|
|
this.close();
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Handle form keydown events.
|
|
*
|
|
* @method
|
|
* @param {jQuery.Event} e Key down event
|
|
*/
|
|
ve.ui.Inspector.prototype.onFormKeyDown = function ( e ) {
|
|
// Escape
|
|
if ( e.which === 27 ) {
|
|
this.close();
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle inspector initialize events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.Inspector.prototype.onOpen = function () {
|
|
this.initialSelection = this.surface.getModel().getSelection();
|
|
};
|
|
|
|
/**
|
|
* Handle inspector initialize events.
|
|
*
|
|
* @method
|
|
* @param {boolean} accept Changes have been accepted
|
|
*/
|
|
ve.ui.Inspector.prototype.onClose = function () {
|
|
this.surface.getView().getDocument().getDocumentNode().$.focus();
|
|
};
|
|
|
|
/**
|
|
* Get matching annotations within a fragment.
|
|
*
|
|
* @method
|
|
* @param {ve.dm.SurfaceFragment} fragment Fragment to get matching annotations within
|
|
* @returns {ve.AnnotationSet} Matching annotations
|
|
*/
|
|
ve.ui.Inspector.prototype.getMatchingAnnotations = function ( fragment ) {
|
|
return fragment.getAnnotations().getAnnotationsByName( this.constructor.static.typePattern );
|
|
};
|