2015-08-13 00:58:23 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWNumberedExternalLinkNodeContextItem class.
|
|
|
|
*
|
2019-01-01 13:24:23 +00:00
|
|
|
* @copyright 2011-2019 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
|
|
|
|
* @param {ve.ui.Context} context Context item is in
|
|
|
|
* @param {ve.dm.Model} model Model item is related to
|
|
|
|
* @param {Object} config Configuration options
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.static.deletable = true;
|
|
|
|
|
2015-08-13 00:58:23 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2015-12-09 18:42:20 +00:00
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.prototype.isDeletable = function () {
|
|
|
|
// We don't care about whether the context wants to show delete buttons, so override the check.
|
2019-02-08 19:18:22 +00:00
|
|
|
return this.constructor.static.deletable && !this.isReadOnly();
|
2015-12-09 16:11:06 +00:00
|
|
|
};
|
2015-08-13 00:58:23 +00:00
|
|
|
|
2018-05-30 16:57:03 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWNumberedExternalLinkNodeContextItem.prototype.onLabelButtonClick = function () {
|
|
|
|
var annotation, annotations, content,
|
|
|
|
surfaceModel = this.context.getSurface().getModel(),
|
|
|
|
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.
|
|
|
|
|
|
|
|
annotation = new ve.dm.MWExternalLinkAnnotation( {
|
|
|
|
type: 'link/mwExternal',
|
|
|
|
attributes: {
|
|
|
|
href: this.model.getHref()
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
annotations = doc.data.getAnnotationsFromOffset( nodeRange.start ).clone();
|
|
|
|
annotations.push( annotation );
|
|
|
|
content = this.model.getHref().split( '' );
|
|
|
|
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 );
|