mediawiki-extensions-Visual.../modules/ve/ce/nodes/ve.ce.ListItemNode.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

2012-03-08 12:27:02 +00:00
/**
* Creates an ve.ce.ListItemNode object.
*
* @class
* @constructor
* @extends {ve.ce.LeafNode}
* @param {ve.dm.ListItemNode} model List item model to view
*/
ve.ce.ListItemNode = function( model ) {
// Inheritance
var style = model.getElementAttribute( 'style' ),
type = ve.ce.ListItemNode.domNodeTypes[style];
ve.ce.BranchNode.call( this, model, $( '<' + type + '></' + type + '>' ) );
2012-03-08 12:27:02 +00:00
// Properties
this.currentStylesHash = null;
2012-03-08 12:27:02 +00:00
// DOM Changes
this.$.addClass( 've-ce-listItemNode' );
2012-03-08 12:27:02 +00:00
// Events
var _this = this;
this.model.on( 'update', function() {
_this.setStyle();
2012-03-08 12:27:02 +00:00
} );
};
2012-03-08 12:27:02 +00:00
/* Static Members */
ve.ce.ListItemNode.domNodeTypes = {
'item': 'li',
'definition': 'dd',
'term': 'dt'
2012-03-08 12:27:02 +00:00
};
/* Methods */
ve.ce.ListItemNode.prototype.setStyle = function() {
var style = this.model.getElementAttribute( 'style' ),
type = ve.ce.ListItemNode.domNodeTypes[style];
if ( type === undefined ) {
throw 'Invalid style attribute for heading node: ' + style;
}
if ( style !== this.currentStyleHash ) {
this.currentStyleHash = style;
this.convertDomElement( type );
2012-03-08 12:27:02 +00:00
}
};
/* Registration */
ve.ce.DocumentNode.splitRules.listItem = {
'self': true,
'children': false
};
/* Inheritance */
ve.extendClass( ve.ce.ListItemNode, ve.ce.BranchNode );