2013-10-17 20:15:36 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWNumberedExternalLinkNode class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-10-17 20:15:36 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ContentEditable MediaWiki numbered external link node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ce.LeafNode
|
2014-09-17 00:33:39 +00:00
|
|
|
* @mixins ve.ce.FocusableNode
|
2013-10-17 20:15:36 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWNumberedExternalLinkNode} model Model to observe
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ce.MWNumberedExternalLinkNode = function VeCeMWNumberedExternalLinkNode() {
|
2013-10-17 20:15:36 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.ce.MWNumberedExternalLinkNode.super.apply( this, arguments );
|
2013-10-17 20:15:36 +00:00
|
|
|
|
2018-05-31 14:06:57 +00:00
|
|
|
// Wrap the link in a span. The link must remain empty to match :empty selectors.
|
|
|
|
// Also move ve-ce-* classes back up to the wrapper.
|
|
|
|
this.$link = this.$element.removeClass( 've-ce-leafNode' )
|
|
|
|
// These attributes are used for styling, so ensure they exists (they should
|
|
|
|
// have been copied from originalDomElements already)
|
|
|
|
.attr( 'rel', 'mw:ExtLink' )
|
|
|
|
.addClass( 'external' );
|
|
|
|
this.$element = $( '<span>' ).append( this.$link ).addClass( 've-ce-leafNode' );
|
|
|
|
|
2013-10-17 20:15:36 +00:00
|
|
|
// Mixin constructors
|
|
|
|
ve.ce.FocusableNode.call( this );
|
|
|
|
|
|
|
|
// DOM changes
|
2015-05-02 04:52:40 +00:00
|
|
|
this.$element
|
|
|
|
// TODO: Test to see whether we can get away with adding unicode-bidi
|
|
|
|
// embed/isolate style on $element. unicode-bidi isolate is more conceptually
|
|
|
|
// correct, but not well supported (e.g. it seems to result in unexpected jumping
|
|
|
|
// on Chromium).
|
|
|
|
.addClass( 've-ce-mwNumberedExternalLinkNode' )
|
|
|
|
// Need some content to make span take up a cursor position, but it must be text
|
|
|
|
// with no directionality, else it can break Chromium cursoring (see
|
|
|
|
// https://code.google.com/p/chromium/issues/detail?id=441056 ). Either a
|
|
|
|
// unicorn-like img tag or the actual apparent link text ("[1]", hitherto shown
|
|
|
|
// with CSS generated content) would fall foul of this bug. Use a zero-width
|
|
|
|
// space so it doesn't change the appearance.
|
2021-10-25 15:51:29 +00:00
|
|
|
.prepend( $( document.createTextNode( '\u200B' ) ) );
|
2013-10-17 20:15:36 +00:00
|
|
|
|
|
|
|
// Events
|
2014-08-22 20:50:48 +00:00
|
|
|
this.model.connect( this, { update: 'onUpdate' } );
|
2013-10-17 20:15:36 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.onUpdate();
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.LeafNode );
|
|
|
|
|
|
|
|
OO.mixinClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.FocusableNode );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ce.MWNumberedExternalLinkNode.static.name = 'link/mwNumberedExternal';
|
|
|
|
|
2018-05-31 14:06:57 +00:00
|
|
|
ve.ce.MWNumberedExternalLinkNode.static.tagName = 'a';
|
2013-10-17 20:15:36 +00:00
|
|
|
|
2014-10-22 02:44:27 +00:00
|
|
|
ve.ce.MWNumberedExternalLinkNode.static.primaryCommandName = 'link';
|
2013-12-20 23:25:24 +00:00
|
|
|
|
2014-06-10 01:18:23 +00:00
|
|
|
/* Static Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ce.MWNumberedExternalLinkNode.static.getDescription = function ( model ) {
|
|
|
|
return model.getAttribute( 'href' );
|
|
|
|
};
|
|
|
|
|
2013-10-17 20:15:36 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle model update events.
|
|
|
|
*/
|
|
|
|
ve.ce.MWNumberedExternalLinkNode.prototype.onUpdate = function () {
|
2022-11-24 13:25:14 +00:00
|
|
|
// T322704
|
|
|
|
ve.setAttributeSafe( this.$link[ 0 ], 'href', this.model.getAttribute( 'href' ) || '', '#' );
|
2013-10-17 20:15:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWNumberedExternalLinkNode );
|