2012-03-08 12:27:02 +00:00
|
|
|
/**
|
|
|
|
* Creates an ve.ce.HeadingNode object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.ce.LeafNode}
|
|
|
|
* @param {ve.dm.HeadingNode} model Heading model to view
|
|
|
|
*/
|
|
|
|
ve.ce.HeadingNode = function( model ) {
|
|
|
|
// Inheritance
|
2012-04-05 21:31:59 +00:00
|
|
|
var level = model.getElementAttribute( 'level' ),
|
|
|
|
type = ve.ce.HeadingNode.domNodeTypes[level];
|
|
|
|
if ( type === undefined ) {
|
|
|
|
throw 'Invalid level attribute for heading node: ' + level;
|
|
|
|
}
|
|
|
|
ve.ce.LeafNode.call( this, model, $( '<' + type + '></' + type + '>' ) );
|
2012-03-08 12:27:02 +00:00
|
|
|
|
|
|
|
// Properties
|
2012-04-04 18:53:23 +00:00
|
|
|
this.currentLevelHash = level;
|
2012-03-08 12:27:02 +00:00
|
|
|
|
|
|
|
// DOM Changes
|
2012-04-04 18:53:23 +00:00
|
|
|
this.$.addClass( 've-ce-headingNode' );
|
2012-03-08 12:27:02 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
var _this = this;
|
|
|
|
this.model.on( 'update', function() {
|
2012-04-04 18:53:23 +00:00
|
|
|
_this.setLevel();
|
2012-03-08 12:27:02 +00:00
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2012-04-05 21:31:59 +00:00
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
ve.ce.HeadingNode.domNodeTypes = {
|
|
|
|
'1': 'h1',
|
|
|
|
'2': 'h2',
|
|
|
|
'3': 'h3',
|
|
|
|
'4': 'h4',
|
|
|
|
'5': 'h5',
|
|
|
|
'6': 'h6'
|
|
|
|
};
|
|
|
|
|
2012-03-08 12:27:02 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2012-04-04 18:53:23 +00:00
|
|
|
ve.ce.HeadingNode.prototype.setLevel = function() {
|
2012-04-05 21:31:59 +00:00
|
|
|
var level = this.model.getElementAttribute( 'level' ),
|
|
|
|
type = ve.ce.HeadingNode.domNodeTypes[level];
|
|
|
|
if ( type === undefined ) {
|
|
|
|
throw 'Invalid level attribute for heading node: ' + level;
|
|
|
|
}
|
2012-03-08 12:27:02 +00:00
|
|
|
if ( level !== this.currentLevelHash ) {
|
|
|
|
this.currentLevelHash = level;
|
2012-04-05 21:31:59 +00:00
|
|
|
this.convertDomElement( type );
|
2012-03-08 12:27:02 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.DocumentNode.splitRules.heading = {
|
|
|
|
'self': true,
|
|
|
|
'children': null
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.ce.HeadingNode, ve.ce.LeafNode );
|