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
|
2012-04-04 18:53:23 +00:00
|
|
|
this.$icon = $( '<div class="ve-ce-listItemNode-icon"></div>' ).prependTo( this.$ );
|
2012-03-08 12:27:02 +00:00
|
|
|
this.currentStylesHash = null;
|
|
|
|
|
|
|
|
// DOM Changes
|
2012-04-04 18:53:23 +00:00
|
|
|
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
|
2012-04-04 18:53:23 +00:00
|
|
|
.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
|
2012-04-04 18:53:23 +00:00
|
|
|
.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
|
2012-04-04 18:53:23 +00:00
|
|
|
.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 );
|