2012-03-08 12:27:02 +00:00
|
|
|
/**
|
|
|
|
* Creates an ve.ce.ListNode object.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.ce.BranchNode}
|
|
|
|
* @param {ve.dm.ListNode} model List model to view
|
|
|
|
*/
|
|
|
|
ve.ce.ListNode = function( model ) {
|
|
|
|
// Inheritance
|
2012-04-05 21:31:59 +00:00
|
|
|
var style = model.getElementAttribute( 'style' ),
|
|
|
|
type = ve.ce.ListNode.domNodeTypes[style];
|
|
|
|
ve.ce.BranchNode.call( this, model, $( '<' + type + '></' + type + '>' ) );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.currentStylesHash = null;
|
2012-03-08 12:27:02 +00:00
|
|
|
|
|
|
|
// DOM Changes
|
2012-04-04 18:53:23 +00:00
|
|
|
this.$.addClass( 've-ce-listNode' );
|
2012-03-08 12:27:02 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
var _this = this;
|
|
|
|
this.model.on( 'update', function() {
|
2012-04-05 21:31:59 +00:00
|
|
|
_this.setStyle();
|
2012-03-08 12:27:02 +00:00
|
|
|
} );
|
2012-04-05 21:31:59 +00:00
|
|
|
};
|
2012-03-08 12:27:02 +00:00
|
|
|
|
2012-04-05 21:31:59 +00:00
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
ve.ce.ListNode.domNodeTypes = {
|
|
|
|
'bullet': 'ul',
|
|
|
|
'number': 'ol',
|
|
|
|
'definition': 'dl'
|
2012-03-08 12:27:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2012-04-06 18:32:57 +00:00
|
|
|
ve.ce.ListNode.prototype.setStyle = function() {
|
2012-04-05 21:31:59 +00:00
|
|
|
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.list = {
|
|
|
|
'self': false,
|
|
|
|
'children': true
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.ce.ListNode, ve.ce.BranchNode );
|