mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-06 06:29:11 +00:00
dcbea2328c
Change-Id: I26daca6313bf09055af8f980ba0065782257fd54
67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable DefinitionListItemNode class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* ContentEditable definition list item node.
|
|
*
|
|
* @class
|
|
* @extends ve.ce.BranchNode
|
|
* @constructor
|
|
* @param {ve.dm.DefinitionListItemNode} model Model to observe
|
|
* @param {Object} [config] Config options
|
|
*/
|
|
ve.ce.DefinitionListItemNode = function VeCeDefinitionListItemNode( model, config ) {
|
|
// Parent constructor
|
|
ve.ce.BranchNode.call( this, model, config );
|
|
|
|
// Events
|
|
this.model.connect( this, { 'update': 'onUpdate' } );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ce.DefinitionListItemNode, ve.ce.BranchNode );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ce.DefinitionListItemNode.static.name = 'definitionListItem';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get the HTML tag name.
|
|
*
|
|
* Tag name is selected based on the model's style attribute.
|
|
*
|
|
* @returns {string} HTML tag name
|
|
* @throws {Error} If style is invalid
|
|
*/
|
|
ve.ce.DefinitionListItemNode.prototype.getTagName = function () {
|
|
var style = this.model.getAttribute( 'style' ),
|
|
types = { 'definition': 'dd', 'term': 'dt' };
|
|
|
|
if ( !( style in types ) ) {
|
|
throw new Error( 'Invalid style' );
|
|
}
|
|
return types[style];
|
|
};
|
|
|
|
/**
|
|
* Handle model update events.
|
|
*
|
|
* If the style changed since last update the DOM wrapper will be replaced with an appropriate one.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.DefinitionListItemNode.prototype.onUpdate = function () {
|
|
this.updateTagName();
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.DefinitionListItemNode );
|