2015-08-13 00:58:23 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWNumberedExternalLinkNodeContextItem class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
|
2015-08-13 00:58:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWNumberedExternalLinkNode.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.LinkContextItem
|
|
|
|
*
|
|
|
|
* @constructor
|
2023-07-10 13:31:31 +00:00
|
|
|
* @param {ve.ui.LinearContext} context Context the item is in
|
|
|
|
* @param {ve.dm.Model} model Model the item is related to
|
2023-02-02 09:47:32 +00:00
|
|
|
* @param {Object} [config]
|
2015-08-13 00:58:23 +00:00
|
|
|
*/
|
2015-08-18 12:54:51 +00:00
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem = function VeUiMWNumberedExternalLinkNodeContextItem() {
|
2015-08-13 00:58:23 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwNumberedExternalLinkNodeContextItem' );
|
2018-05-30 16:57:03 +00:00
|
|
|
|
2019-07-29 19:20:17 +00:00
|
|
|
if ( this.labelButton ) {
|
|
|
|
this.labelButton.setLabel( OO.ui.deferMsg( 'visualeditor-linknodeinspector-add-label' ) );
|
|
|
|
}
|
2015-08-13 00:58:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWNumberedExternalLinkNodeContextItem, ve.ui.LinkContextItem );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.static.name = 'link/mwNumberedExternal';
|
|
|
|
|
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.static.modelClasses = [ ve.dm.MWNumberedExternalLinkNode ];
|
|
|
|
|
2015-12-09 18:42:20 +00:00
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.static.clearable = false;
|
|
|
|
|
2015-08-13 00:58:23 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2018-05-30 16:57:03 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.prototype.onLabelButtonClick = function () {
|
2022-02-21 18:07:07 +00:00
|
|
|
var surfaceModel = this.context.getSurface().getModel(),
|
2018-05-30 16:57:03 +00:00
|
|
|
surfaceView = this.context.getSurface().getView(),
|
|
|
|
doc = surfaceModel.getDocument(),
|
|
|
|
nodeRange = this.model.getOuterRange();
|
|
|
|
|
|
|
|
// TODO: this is very similar to part of
|
|
|
|
// ve.ui.MWLinkNodeInspector.prototype.getTeardownProcess, and should
|
|
|
|
// perhaps be consolidated into a reusable "replace node with annotated
|
|
|
|
// text and select that text" method somewhere appropriate.
|
|
|
|
|
2022-02-21 18:07:07 +00:00
|
|
|
var annotation = new ve.dm.MWExternalLinkAnnotation( {
|
2018-05-30 16:57:03 +00:00
|
|
|
type: 'link/mwExternal',
|
|
|
|
attributes: {
|
|
|
|
href: this.model.getHref()
|
|
|
|
}
|
|
|
|
} );
|
2022-02-21 18:07:07 +00:00
|
|
|
var annotations = doc.data.getAnnotationsFromOffset( nodeRange.start ).clone();
|
2018-05-30 16:57:03 +00:00
|
|
|
annotations.push( annotation );
|
2022-02-21 18:07:07 +00:00
|
|
|
var content = this.model.getHref().split( '' );
|
2018-05-30 16:57:03 +00:00
|
|
|
ve.dm.Document.static.addAnnotationsToData( content, annotations );
|
|
|
|
surfaceModel.change(
|
|
|
|
ve.dm.TransactionBuilder.static.newFromReplacement( doc, nodeRange, content )
|
|
|
|
);
|
|
|
|
setTimeout( function () {
|
2019-04-13 16:04:43 +00:00
|
|
|
surfaceView.selectAnnotation( function ( view ) {
|
|
|
|
return view.model instanceof ve.dm.MWExternalLinkAnnotation;
|
|
|
|
} );
|
2018-05-30 16:57:03 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2015-08-13 00:58:23 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWNumberedExternalLinkNodeContextItem );
|