2011-11-02 21:00:55 +00:00
|
|
|
/**
|
|
|
|
* Creates an es.ListItemView object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {es.DocumentViewLeafNode}
|
|
|
|
* @param {es.ListItemModel} model List item model to view
|
|
|
|
*/
|
|
|
|
es.ListItemView = function( model ) {
|
|
|
|
// Inheritance
|
2011-11-07 21:30:13 +00:00
|
|
|
es.DocumentViewBranchNode.call( this, model );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.$icon = $( '<div class="es-listItemView-icon"></div>' ).prependTo( this.$ );
|
|
|
|
|
|
|
|
// DOM Changes
|
|
|
|
this.$.addClass( 'es-listItemView' );
|
|
|
|
|
|
|
|
// Events
|
|
|
|
this.on( 'update', this.setClasses );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.setClasses();
|
|
|
|
};
|
|
|
|
|
2011-11-14 23:47:07 +00:00
|
|
|
/* Methods */
|
2011-11-07 21:30:13 +00:00
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
es.ListItemView.prototype.setClasses = function() {
|
|
|
|
var classes = this.$.attr( 'class' ),
|
|
|
|
styles = this.model.getElementAttribute( 'styles' );
|
|
|
|
this.$
|
|
|
|
// Remove any existing level classes
|
|
|
|
.attr(
|
|
|
|
'class',
|
|
|
|
classes
|
|
|
|
.replace( /es-listItemView-level[0-9]+/, '' )
|
|
|
|
.replace( /es-listItemView-(bullet|number)/, '' )
|
|
|
|
)
|
|
|
|
// Set the list style class from the style on top of the stack
|
|
|
|
.addClass( 'es-listItemView-' + styles[styles.length - 1] )
|
|
|
|
// Set the list level class from the length of the stack
|
|
|
|
.addClass( 'es-listItemView-level' + ( styles.length - 1 ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
es.ListItemView.prototype.setNumber = function( number ) {
|
|
|
|
this.$icon.text( number + '.' );
|
|
|
|
};
|
|
|
|
|
2011-11-14 23:59:36 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2011-11-16 18:54:05 +00:00
|
|
|
es.DocumentView.splitRules.listItem = {
|
2011-11-14 23:59:36 +00:00
|
|
|
'self': true,
|
|
|
|
'children': false
|
|
|
|
};
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2011-11-07 21:30:13 +00:00
|
|
|
es.extendClass( es.ListItemView, es.DocumentViewBranchNode );
|