2011-11-02 21:00:55 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.es.ListNode object.
|
2011-11-02 21:00:55 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @extends {ve.es.BranchNode}
|
|
|
|
* @param {ve.dm.ListNode} model List model to view
|
2011-11-02 21:00:55 +00:00
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.ListNode = 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
|
|
|
|
|
|
|
// DOM Changes
|
|
|
|
this.$.addClass( 'es-listView' );
|
|
|
|
|
|
|
|
// Events
|
2011-12-07 23:13:57 +00:00
|
|
|
var _this = this;
|
|
|
|
this.model.on( 'update', function() {
|
|
|
|
_this.enumerate();
|
|
|
|
} );
|
2011-11-02 21:00:55 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.enumerate();
|
|
|
|
};
|
|
|
|
|
2011-11-14 23:47:07 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/**
|
|
|
|
* Set the number labels of all ordered list items.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.es.ListNode.prototype.enumerate = function() {
|
2011-11-02 21:00:55 +00:00
|
|
|
var styles,
|
|
|
|
levels = [];
|
|
|
|
for ( var i = 0; i < this.children.length; i++ ) {
|
|
|
|
styles = this.children[i].model.getElementAttribute( 'styles' );
|
|
|
|
levels = levels.slice( 0, styles.length );
|
|
|
|
if ( styles[styles.length - 1] === 'number' ) {
|
|
|
|
if ( !levels[styles.length - 1] ) {
|
|
|
|
levels[styles.length - 1] = 0;
|
|
|
|
}
|
2011-12-07 01:13:08 +00:00
|
|
|
this.children[i].$icon.text( ++levels[styles.length - 1] + '.' );
|
2011-12-07 01:12:04 +00:00
|
|
|
} else {
|
|
|
|
this.children[i].$icon.text( '' );
|
2011-12-09 02:07:23 +00:00
|
|
|
if ( levels[styles.length - 1] ) {
|
|
|
|
levels[styles.length - 1] = 0;
|
|
|
|
}
|
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.list = {
|
2011-11-14 23:59:36 +00:00
|
|
|
'self': false,
|
|
|
|
'children': true
|
|
|
|
};
|
|
|
|
|
2011-11-02 21:00:55 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.es.ListNode, ve.es.BranchNode );
|