mediawiki-extensions-Visual.../modules/ve-mw/ce/nodes/ve.ce.MWAlienExtensionNode.js
Ed Sanders fdcd42f73a Split AlienExtensionNode into inline and block
MWExtensionNode:
* Inherit from LeafNode at the top level. Inline and block only
  differ in CE where inline has isContent set.

MWAlienExtensionNode:
* Inhert from MW(Inline|Block)ExtensionNode respectively. Both
  mixin MWAlienExtensionNode.

Bonus:
* Bring in paragraph unwrapping on inline nodes from MWMathNode

Bug: T93712
Change-Id: Ib04234f740cf1f27c861d8b3cfeea5e323b94678
2015-04-09 16:32:02 +01:00

140 lines
3.6 KiB
JavaScript

/*!
* VisualEditor ContentEditable MWAlienExtensionNode class.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MediaWiki alien extension node.
*
* @class
* @abstract
* @mixins OO.ui.IconElement
*
* @constructor
* @param {Object} [config] Configuration options
*/
ve.ce.MWAlienExtensionNode = function VeCeMWAlienExtensionNode( config ) {
// Mixin constructors
OO.ui.IconElement.call( this, config );
// Events
this.connect( this, { setup: 'onAlienSetup' } );
};
/* Inheritance */
OO.initClass( ve.ce.MWAlienExtensionNode );
OO.mixinClass( ve.ce.MWAlienExtensionNode, OO.ui.IconElement );
/* Static members */
ve.ce.MWAlienExtensionNode.static.primaryCommandName = 'alienExtension';
/* Methods */
/**
* Handle setup events
*/
ve.ce.MWAlienExtensionNode.prototype.onAlienSetup = function () {
if ( !this.isVisible() ) {
this.setIcon( 'alienextension' );
this.$element.first().prepend( this.$icon );
} else {
this.setIcon( null );
}
};
/**
* @inheritdoc ve.ce.MWExtensionNode
*/
ve.ce.MWAlienExtensionNode.prototype.render = function ( generatedContents ) {
// Since render is trigerred before onSetup, we need to make sure that the
// icon is detached only when it is defined and is not null
if ( this.$icon ) {
this.$icon.detach();
}
// Call parent mixin
ve.ce.GeneratedContentNode.prototype.render.call( this, generatedContents );
// Since render replaces this.$element with a new node, we need to make sure
// our iconElement is defined again to be this.$element
this.$element.addClass( 've-ce-mwAlienExtensionNode' );
};
/* Static methods */
/**
* @inheritdoc ve.ce.MWExtensionNode
*/
ve.ce.MWAlienExtensionNode.static.getDescription = function ( model ) {
return model.getExtensionName();
};
/**
* ContentEditable MediaWiki alien inline extension node.
*
* @class
* @abstract
* @extends ve.ce.MWInlineExtensionNode
* @mixins ve.ce.MWAlienExtensionNode
*
* @constructor
* @param {ve.dm.MWAlienInlineExtensionNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWAlienInlineExtensionNode = function VeCeMWAlienInlineExtensionNode( config ) {
// Parent constructor
ve.ce.MWAlienInlineExtensionNode.super.apply( this, arguments );
// Mixin constructors
ve.ce.MWAlienExtensionNode.call( this, config );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWAlienInlineExtensionNode, ve.ce.MWInlineExtensionNode );
OO.mixinClass( ve.ce.MWAlienInlineExtensionNode, ve.ce.MWAlienExtensionNode );
/* Static members */
ve.ce.MWAlienInlineExtensionNode.static.name = 'mwAlienInlineExtension';
/**
* ContentEditable MediaWiki alien block extension node.
*
* @class
* @abstract
* @extends ve.ce.MWBlockExtensionNode
* @mixins ve.ce.MWAlienExtensionNode
*
* @constructor
* @param {ve.dm.MWAlienBlockExtensionNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWAlienBlockExtensionNode = function VeCeMWAlienBlockExtensionNode() {
// Parent constructor
ve.ce.MWAlienBlockExtensionNode.super.apply( this, arguments );
// Mixin constructors
ve.ce.MWAlienExtensionNode.call( this );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWAlienBlockExtensionNode, ve.ce.MWBlockExtensionNode );
OO.mixinClass( ve.ce.MWAlienBlockExtensionNode, ve.ce.MWAlienExtensionNode );
/* Static members */
ve.ce.MWAlienBlockExtensionNode.static.name = 'mwAlienBlockExtension';
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWAlienInlineExtensionNode );
ve.ce.nodeFactory.register( ve.ce.MWAlienBlockExtensionNode );