mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 17:36:35 +00:00
a4491c12f8
Objective: * Make the majority of link inspector, which is generic to any annotation, usable for other annotation inspectors This was merged earlier (f7107fa20d
) but broke master, so it was reverted (092fa74dee
). This commit also incorporates5dcf5d1c49
. Change-Id: Ib9190dee66ce064d69962f9c4c5b3a710be8ad07
92 lines
2.2 KiB
JavaScript
92 lines
2.2 KiB
JavaScript
/*!
|
|
* VisualEditor UserInterface LinkInspector class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Link inspector.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.AnnotationInspector
|
|
*
|
|
* @constructor
|
|
* @param {ve.ui.Surface} surface
|
|
* @param {Object} [config] Config options
|
|
*/
|
|
ve.ui.LinkInspector = function VeUiLinkInspector( surface, config ) {
|
|
// Parent constructor
|
|
ve.ui.AnnotationInspector.call( this, surface, config );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.LinkInspector, ve.ui.AnnotationInspector );
|
|
|
|
/* Static properties */
|
|
|
|
ve.ui.LinkInspector.static.icon = 'link';
|
|
|
|
ve.ui.LinkInspector.static.titleMessage = 'visualeditor-linkinspector-title';
|
|
|
|
ve.ui.LinkInspector.static.linkTargetInputWidget = ve.ui.LinkTargetInputWidget;
|
|
|
|
/**
|
|
* Annotation models this inspector can edit.
|
|
*
|
|
* @static
|
|
* @property {Function[]}
|
|
*/
|
|
ve.ui.LinkInspector.static.modelClasses = [ ve.dm.LinkAnnotation ];
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle frame ready events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.LinkInspector.prototype.initialize = function () {
|
|
// Parent method
|
|
ve.ui.AnnotationInspector.prototype.initialize.call( this );
|
|
|
|
// Properties
|
|
this.targetInput = new this.constructor.static.linkTargetInputWidget( {
|
|
'$$': this.frame.$$, '$overlay': this.surface.$localOverlayMenus
|
|
} );
|
|
|
|
// Initialization
|
|
this.$form.append( this.targetInput.$ );
|
|
};
|
|
|
|
/**
|
|
* Handle the inspector being opened.
|
|
*/
|
|
ve.ui.LinkInspector.prototype.onOpen = function () {
|
|
// Parent method
|
|
ve.ui.AnnotationInspector.prototype.onOpen.call( this );
|
|
|
|
// Wait for animation to complete
|
|
this.surface.disable();
|
|
setTimeout( ve.bind( function () {
|
|
// Note: Focus input prior to setting target annotation
|
|
this.targetInput.$input.focus();
|
|
// Setup annotation
|
|
this.targetInput.setAnnotation( this.initialAnnotation );
|
|
this.targetInput.$input.select();
|
|
this.surface.enable();
|
|
}, this ), 200 );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.LinkInspector.prototype.getAnnotationFromText = function ( text ) {
|
|
return new ve.dm.LinkAnnotation( { 'type': 'link', 'attributes': { 'href': text } } );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.inspectorFactory.register( 'link', ve.ui.LinkInspector );
|