mediawiki-extensions-Visual.../modules/ve/ui/widgets/ve.ui.LinkTargetInputWidget.js
Rob Moen 002fa5d40b Fix current annotation being nullified
MWLinkTargetInputWidget annotation property was being killed
on populateMenu.

Other changes:
* Removed calls to sanitize on subclasses setValue methods
  as those methods call the parent class method which already
  sanitizes input.

Bug: 46025
Change-Id: I169dd58a06122122f187f9d751076ef56b255558
2013-03-13 01:41:33 +00:00

99 lines
2.2 KiB
JavaScript

/*!
* VisualEditor UserInterface LinkTargetInputWidget class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.LinkTargetInputWidget object.
*
* @class
* @extends ve.ui.TextInputWidget
*
* @constructor
* @param {Object} [config] Config options
*/
ve.ui.LinkTargetInputWidget = function VeUiLinkTargetInputWidget( config ) {
// Parent constructor
ve.ui.TextInputWidget.call( this, config );
// Properties
this.annotation = null;
// Initialization
this.$.addClass( 've-ui-linkTargetInputWidget' );
};
/* Inheritance */
ve.inheritClass( ve.ui.LinkTargetInputWidget, ve.ui.TextInputWidget );
/* Methods */
/**
* Set the value of the input.
*
* Overrides setValue to keep annotations in sync.
*
* @method
* @param {string} value New value
*/
ve.ui.LinkTargetInputWidget.prototype.setValue = function ( value ) {
// Keep annotation in sync with value
value = this.sanitizeValue( value );
if ( value === '' ) {
this.annotation = null;
} else {
this.setAnnotation( new ve.dm.LinkAnnotation( { 'href': value } ) );
}
// Call parent method
ve.ui.TextInputWidget.prototype.setValue.call( this, value );
};
/**
* Sets the annotation value.
*
* The input value will automatically be updated.
*
* @method
* @param {ve.dm.LinkAnnotation} annotation Link annotation
* @chainable
*/
ve.ui.LinkTargetInputWidget.prototype.setAnnotation = function ( annotation ) {
this.annotation = annotation;
// Call parent method
ve.ui.TextInputWidget.prototype.setValue.call(
this, this.getTargetFromAnnotation( annotation )
);
return this;
};
/**
* Gets the annotation value.
*
* @method
* @returns {ve.dm.LinkAnnotation} Link annotation
*/
ve.ui.LinkTargetInputWidget.prototype.getAnnotation = function () {
return this.annotation;
};
/**
* Gets a target from an annotation.
*
* @method
* @param {ve.dm.LinkAnnotation} annotation Link annotation
* @returns {string} Target
*/
ve.ui.LinkTargetInputWidget.prototype.getTargetFromAnnotation = function ( annotation ) {
if ( annotation instanceof ve.dm.LinkAnnotation ) {
return annotation.data.href;
}
return '';
};