2014-10-22 02:44:27 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWLinkAction class.
|
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
|
2014-10-22 02:44:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Link action.
|
|
|
|
*
|
|
|
|
* Opens either MWLinkAnnotationInspector or MWLinkNodeInspector depending on what is selected.
|
|
|
|
*
|
|
|
|
* @class
|
2015-08-12 20:55:31 +00:00
|
|
|
* @extends ve.ui.LinkAction
|
2014-10-22 02:44:27 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Surface} surface Surface to act on
|
|
|
|
*/
|
|
|
|
ve.ui.MWLinkAction = function VeUiMWLinkAction( surface ) {
|
|
|
|
// Parent constructor
|
2015-08-12 20:55:31 +00:00
|
|
|
ve.ui.MWLinkAction.super.call( this, surface );
|
2014-10-22 02:44:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-08-12 20:55:31 +00:00
|
|
|
OO.inheritClass( ve.ui.MWLinkAction, ve.ui.LinkAction );
|
2014-10-22 02:44:27 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of allowed methods for the action.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property
|
|
|
|
*/
|
2015-08-12 20:55:31 +00:00
|
|
|
ve.ui.MWLinkAction.static.methods = ve.ui.MWLinkAction.super.static.methods.concat( [ 'open' ] );
|
2014-10-22 02:44:27 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2015-08-17 16:28:57 +00:00
|
|
|
/**
|
|
|
|
* Match the trailing punctuation set used for autolinks in wikitext.
|
|
|
|
* Closing parens are only stripped if open parens are missing from the
|
|
|
|
* candidate text, so that URLs with embedded matched parentheses (like
|
|
|
|
* wiki articles with disambiguation text) autolink nicely.
|
|
|
|
* @method
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWLinkAction.prototype.getTrailingPunctuation = function ( candidate ) {
|
|
|
|
return /\(/.test( candidate ) ? /[,;.:!?]+$/ : /[,;.:!?)]+$/;
|
|
|
|
};
|
|
|
|
|
2015-08-12 20:55:31 +00:00
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* @inheritdoc
|
|
|
|
* @return {ve.dm.MWExternalLinkAnnotation} The annotation to use.
|
|
|
|
*/
|
|
|
|
ve.ui.MWLinkAction.prototype.getLinkAnnotation = function ( href ) {
|
|
|
|
return new ve.dm.MWExternalLinkAnnotation( {
|
|
|
|
type: 'link/mwExternal',
|
|
|
|
attributes: { href: href }
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2014-10-22 02:44:27 +00:00
|
|
|
/**
|
|
|
|
* Open either the 'link' or 'linkNode' window, depending on what is selected.
|
|
|
|
*
|
|
|
|
* @method
|
2014-11-23 17:19:10 +00:00
|
|
|
* @return {boolean} Action was executed
|
2014-10-22 02:44:27 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWLinkAction.prototype.open = function () {
|
|
|
|
var fragment = this.surface.getModel().getFragment(),
|
|
|
|
windowName = 'link';
|
|
|
|
|
|
|
|
if ( fragment.getSelectedNode() instanceof ve.dm.MWNumberedExternalLinkNode ) {
|
|
|
|
windowName = 'linkNode';
|
|
|
|
}
|
|
|
|
this.surface.execute( 'window', 'open', windowName );
|
2014-11-23 17:19:10 +00:00
|
|
|
return true;
|
2014-10-22 02:44:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.actionFactory.register( ve.ui.MWLinkAction );
|