mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 00:00:49 +00:00
Merge "Make link annotations more flexible"
This commit is contained in:
commit
6223c44456
|
@ -51,13 +51,13 @@ ve.dm.MWInternalLinkAnnotation.static.toDataElement = function ( domElements, co
|
|||
};
|
||||
|
||||
/**
|
||||
* Build a ve.dm.MWInternalLinkAnnotation from a given mw.Title.
|
||||
* Build element from a given mw.Title and raw title
|
||||
*
|
||||
* @param {mw.Title} title The title to link to.
|
||||
* @param {string} [rawTitle] String from which the title was created
|
||||
* @return {ve.dm.MWInternalLinkAnnotation} The annotation.
|
||||
* @return {Object} The element.
|
||||
*/
|
||||
ve.dm.MWInternalLinkAnnotation.static.newFromTitle = function ( title, rawTitle ) {
|
||||
ve.dm.MWInternalLinkAnnotation.static.dataElementFromTitle = function ( title, rawTitle ) {
|
||||
var element,
|
||||
target = title.toText(),
|
||||
namespaceIds = mw.config.get( 'wgNamespaceIds' );
|
||||
|
@ -73,16 +73,31 @@ ve.dm.MWInternalLinkAnnotation.static.newFromTitle = function ( title, rawTitle
|
|||
}
|
||||
|
||||
element = {
|
||||
type: 'link/mwInternal',
|
||||
type: this.name,
|
||||
attributes: {
|
||||
title: target,
|
||||
normalizedTitle: ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( title ),
|
||||
lookupTitle: ve.dm.MWInternalLinkAnnotation.static.getLookupTitle( title )
|
||||
normalizedTitle: this.normalizeTitle( title ),
|
||||
lookupTitle: this.getLookupTitle( title )
|
||||
}
|
||||
};
|
||||
|
||||
if ( rawTitle ) {
|
||||
element.attributes.origTitle = rawTitle;
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
|
||||
/**
|
||||
* Build a ve.dm.MWInternalLinkAnnotation from a given mw.Title.
|
||||
*
|
||||
* @param {mw.Title} title The title to link to.
|
||||
* @param {string} [rawTitle] String from which the title was created
|
||||
* @return {ve.dm.MWInternalLinkAnnotation} The annotation.
|
||||
*/
|
||||
ve.dm.MWInternalLinkAnnotation.static.newFromTitle = function ( title, rawTitle ) {
|
||||
var element = this.dataElementFromTitle( title, rawTitle );
|
||||
|
||||
return new ve.dm.MWInternalLinkAnnotation( element );
|
||||
};
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ ve.ui.MWLinkAnnotationInspector.static.actions = ve.ui.MWLinkAnnotationInspector
|
|||
ve.ui.MWLinkAnnotationInspector.prototype.initialize = function () {
|
||||
// Properties
|
||||
this.allowProtocolInInternal = false;
|
||||
this.internalAnnotationInput = new ve.ui.MWInternalLinkAnnotationWidget();
|
||||
this.externalAnnotationInput = new ve.ui.MWExternalLinkAnnotationWidget();
|
||||
this.internalAnnotationInput = this.createInternalAnnotationInput();
|
||||
this.externalAnnotationInput = this.createExternalAnnotationInput();
|
||||
|
||||
this.linkTypeIndex = new OO.ui.IndexLayout( {
|
||||
expanded: false
|
||||
|
@ -97,6 +97,20 @@ ve.ui.MWLinkAnnotationInspector.prototype.initialize = function () {
|
|||
this.form.$element.append( this.linkTypeIndex.$element );
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ve.ui.MWInternalLinkAnnotationWidget}
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.createInternalAnnotationInput = function () {
|
||||
return new ve.ui.MWInternalLinkAnnotationWidget();
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {ve.ui.MWExternalLinkAnnotationWidget}
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.createExternalAnnotationInput = function () {
|
||||
return new ve.ui.MWExternalLinkAnnotationWidget();
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the current input mode is for external links
|
||||
*
|
||||
|
@ -323,7 +337,7 @@ ve.ui.MWLinkAnnotationInspector.prototype.getAnnotationFromFragment = function (
|
|||
// Figure out if this is an internal or external link
|
||||
if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( target ) ) {
|
||||
// External link
|
||||
return new ve.dm.MWExternalLinkAnnotation( {
|
||||
return this.newExternalLinkAnnotation( {
|
||||
type: 'link/mwExternal',
|
||||
attributes: {
|
||||
href: target
|
||||
|
@ -331,7 +345,7 @@ ve.ui.MWLinkAnnotationInspector.prototype.getAnnotationFromFragment = function (
|
|||
} );
|
||||
} else if ( title ) {
|
||||
// Internal link
|
||||
return ve.dm.MWInternalLinkAnnotation.static.newFromTitle( title );
|
||||
return this.newInternalLinkAnnotationFromTitle( title );
|
||||
} else {
|
||||
// Doesn't look like an external link and mw.Title considered it an illegal value,
|
||||
// for an internal link.
|
||||
|
@ -339,6 +353,22 @@ ve.ui.MWLinkAnnotationInspector.prototype.getAnnotationFromFragment = function (
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {mw.Title} title The title to link to.
|
||||
* @return {ve.dm.MWInternalLinkAnnotation} The annotation.
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.newInternalLinkAnnotationFromTitle = function ( title ) {
|
||||
return ve.dm.MWInternalLinkAnnotation.static.newFromTitle( title );
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Object} element
|
||||
* @return {ve.dm.MWExternalLinkAnnotation} The annotation.
|
||||
*/
|
||||
ve.ui.MWLinkAnnotationInspector.prototype.newExternalLinkAnnotation = function ( element ) {
|
||||
return new ve.dm.MWExternalLinkAnnotation( element );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue