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

63 lines
1.5 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
ve.ce.BranchNode.call( this, model );
// Properties
this.$icon = $( '<div class="ve-ce-listItemNode-icon"></div>' ).prependTo( this.$ );
2012-03-08 12:27:02 +00:00
this.currentStylesHash = null;
// 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.setClasses();
} );
// Initialization
this.setClasses();
};
/* Methods */
ve.ce.ListItemNode.prototype.setClasses = function() {
var styles = this.model.getElementAttribute( 'styles' ),
stylesHash = styles.join( '|' );
if ( this.currentStylesHash !== stylesHash ) {
this.currentStylesHash = stylesHash;
var classes = this.$.attr( 'class' );
this.$
// Remove any existing level classes
.attr(
'class',
classes
.replace( / ?ve-ce-listItemNode-level[0-9]+/, '' )
.replace( / ?ve-ce-listItemNode-(bullet|number|term|definition)/, '' )
2012-03-08 12:27:02 +00:00
)
// Set the list style class from the style on top of the stack
.addClass( 've-ce-listItemNode-' + styles[styles.length - 1] )
2012-03-08 12:27:02 +00:00
// Set the list level class from the length of the stack
.addClass( 've-ce-listItemNode-level' + ( styles.length - 1 ) );
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 );