mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
Make it possible to create autonumbered external links from link inspector
Inserting a new external link from the link inspector when nothing is selected (collapsed selection) will now produce an autonumbered external link ('link/mwNumberedExternal' node, corresponding to wikitext "[http://example.com]"). It used to produce annotated link text ('link/mwExternal' annotation, corresponding to wikitext "[http://example.com http://example.com]" or "http://example.com"). Depends on two commits in VisualEditor/VisualEditor: * Icc2e368a to insert unannotated content from the inspector. * I40cd4d5a to insert non-text content from the inspector. Bug: 51309 Change-Id: Ie4a633ed42907551337a62d96d0abd59e208d49d
This commit is contained in:
parent
b0b2199730
commit
8e84d75383
|
@ -86,6 +86,47 @@ ve.ui.MWLinkAnnotationInspector.prototype.getAnnotationFromFragment = function (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
ve.ui.MWLinkAnnotationInspector.prototype.getInsertionData = function () {
|
||||||
|
var target = this.targetInput.getValue(),
|
||||||
|
inserting = this.initialSelection.isCollapsed();
|
||||||
|
|
||||||
|
// If this is a new external link, insert an autonumbered link instead of a link annotation (in
|
||||||
|
// #getAnnotation we have the same condition to skip the annotating). Otherwise call parent method
|
||||||
|
// to figure out the text to insert and annotate.
|
||||||
|
if ( inserting && ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( target ) ) {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: 'link/mwNumberedExternal',
|
||||||
|
attributes: {
|
||||||
|
href: target
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ type: '/link/mwNumberedExternal' }
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return ve.ui.MWLinkAnnotationInspector.super.prototype.getInsertionData.call( this );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
ve.ui.MWLinkAnnotationInspector.prototype.getAnnotation = function () {
|
||||||
|
var target = this.targetInput.getValue(),
|
||||||
|
inserting = this.initialSelection.isCollapsed();
|
||||||
|
|
||||||
|
// If this is a new external link, we've just inserted an autonumbered link node (see
|
||||||
|
// #getInsertionData). Do not place any annotations of top of it.
|
||||||
|
if ( inserting && ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( target ) ) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return ve.ui.MWLinkAnnotationInspector.super.prototype.getAnnotation.call( this );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* Registration */
|
/* Registration */
|
||||||
|
|
||||||
ve.ui.windowFactory.register( ve.ui.MWLinkAnnotationInspector );
|
ve.ui.windowFactory.register( ve.ui.MWLinkAnnotationInspector );
|
||||||
|
|
Loading…
Reference in a new issue