All files / src/ce/nodes ve.ce.SectionNode.js

87.5% Statements 14/16
50% Branches 1/2
66.66% Functions 2/3
87.5% Lines 14/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                                1x   7x     7x     7x     7x         1x   1x       1x                     1x 7x   7x     7x               1x           1x  
/*!
 * VisualEditor ContentEditable SectionNode class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * ContentEditable section node.
 *
 * @class
 * @extends ve.ce.BranchNode
 * @mixins ve.ce.ActiveNode
 * @constructor
 * @param {ve.dm.SectionNode} model Model to observe
 * @param {Object} [config] Configuration options
 */
ve.ce.SectionNode = function VeCeSectionNode() {
	// Parent constructor
	ve.ce.SectionNode.super.apply( this, arguments );
 
	// Events
	this.model.connect( this, { update: 'onUpdate' } );
 
	// Mixin constructors
	ve.ce.ActiveNode.call( this );
 
	// DOM changes
	this.$element.addClass( 've-ce-sectionNode' );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ce.SectionNode, ve.ce.BranchNode );
 
OO.mixinClass( ve.ce.SectionNode, ve.ce.ActiveNode );
 
/* Static Properties */
 
ve.ce.SectionNode.static.name = 'section';
 
/* Methods */
 
/**
 * Get the HTML tag name.
 *
 * Tag name is selected based on the model's style attribute.
 *
 * @return {string} HTML tag name
 */
ve.ce.SectionNode.prototype.getTagName = function () {
	var style = this.model.getAttribute( 'style' );
 
	Iif ( this.model.constructor.static.matchTagNames.indexOf( style ) === -1 ) {
		throw new Error( 'Invalid style' );
	}
	return style;
};
 
/**
 * Handle model update events.
 *
 * If the style changed since last update the DOM wrapper will be replaced with an appropriate one.
 */
ve.ce.SectionNode.prototype.onUpdate = function () {
	this.updateTagName();
};
 
/* Registration */
 
ve.ce.nodeFactory.register( ve.ce.SectionNode );