mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-14 18:15:19 +00:00
ada58df361
Change-Id: I3c618c196e504a80ca297a4132a17f1977a24fb7
78 lines
1.7 KiB
JavaScript
78 lines
1.7 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable MWMagicLinkNode class.
|
|
*
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* ContentEditable MediaWiki magic link node.
|
|
*
|
|
* @class
|
|
* @extends ve.ce.LeafNode
|
|
* @mixins ve.ce.FocusableNode
|
|
* @constructor
|
|
* @param {ve.dm.MWMagicLinkNode} model Model to observe
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ce.MWMagicLinkNode = function VeCeMWMagicLinkNode( model, config ) {
|
|
// Parent constructor
|
|
ve.ce.LeafNode.call( this, model, config );
|
|
|
|
// Mixin constructors
|
|
ve.ce.FocusableNode.call( this );
|
|
|
|
// DOM changes
|
|
this.$element.addClass( 've-ce-mwMagicLinkNode' );
|
|
|
|
// Add link
|
|
this.$link = $( '<a>' ).appendTo( this.$element );
|
|
|
|
// Events
|
|
this.model.connect( this, { update: 'onUpdate' } );
|
|
|
|
// Initialization
|
|
this.onUpdate();
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ce.MWMagicLinkNode, ve.ce.LeafNode );
|
|
|
|
OO.mixinClass( ve.ce.MWMagicLinkNode, ve.ce.FocusableNode );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ce.MWMagicLinkNode.static.name = 'link/mwMagic';
|
|
|
|
ve.ce.MWMagicLinkNode.static.tagName = 'span';
|
|
|
|
ve.ce.MWMagicLinkNode.static.primaryCommandName = 'link';
|
|
|
|
/* Static Methods */
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ce.MWMagicLinkNode.static.getDescription = function ( model ) {
|
|
return model.getAttribute( 'content' );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle model update events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.MWMagicLinkNode.prototype.onUpdate = function () {
|
|
this.$link
|
|
.attr( 'href', this.model.getHref() )
|
|
.attr( 'rel', this.model.getRel() )
|
|
.text( this.model.getAttribute( 'content' ) );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWMagicLinkNode );
|