2011-11-02 21:00:55 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.es.ListItemNode object.
|
2011-11-02 21:00:55 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @extends {ve.es.LeafNode}
|
|
|
|
* @param {ve.dm.ListItemNode} model List item model to view
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.ListItemNode = function( model ) {
|
2011-11-02 21:00:55 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.BranchNode.call( this, model );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.$icon = $( '<div class="es-listItemView-icon"></div>' ).prependTo( this.$ );
|
2011-11-23 23:22:59 +00:00
|
|
|
this.currentStylesHash = null;
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// DOM Changes
|
|
|
|
this.$.addClass( 'es-listItemView' );
|
|
|
|
|
|
|
|
// Events
|
2011-12-07 23:13:57 +00:00
|
|
|
var _this = this;
|
|
|
|
this.model.on( 'update', function() {
|
|
|
|
_this.setClasses();
|
|
|
|
} );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.setClasses();
|
|
|
|
};
|
|
|
|
|
2011-11-14 23:47:07 +00:00
|
|
|
/* Methods */
|
2011-11-07 21:30:13 +00:00
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.ListItemNode.prototype.setClasses = function() {
|
2011-11-23 23:22:59 +00:00
|
|
|
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( / ?es-listItemView-level[0-9]+/, '' )
|
2011-12-07 23:12:33 +00:00
|
|
|
.replace( / ?es-listItemView-(bullet|number|term|definition)/, '' )
|
2011-11-23 23:22:59 +00:00
|
|
|
)
|
|
|
|
// 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 ) );
|
|
|
|
}
|
2011-11-02 21:00:55 +00:00
|
|
|
};
|
|
|
|
|
2011-11-14 23:59:36 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.DocumentNode.splitRules.listItem = {
|
2011-11-14 23:59:36 +00:00
|
|
|
'self': true,
|
|
|
|
'children': false
|
|
|
|
};
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.es.ListItemNode, ve.es.BranchNode );
|