Prototype of code that wraps nodes as listItems (inside a list)

This commit is contained in:
Inez Korczynski 2011-12-06 00:42:15 +00:00
parent 1b89cbb79d
commit 959963cf6e

View file

@ -19,15 +19,73 @@
/* Methods */
es.ListButtonTool.prototype.onClick = function() {
/*
var parent;
for( var i = 0; i < this.nodes.length; i++ ) {
parent = this.nodes[i].getParent();
if ( parent.getElementType() !== 'listItem' ) {
console.log( this.nodes[i] );
var stacks = [],
stack = [],
i,
j,
data;
//
// Step 1
//
for( i = 0; i < this.nodes.length; i++ ) {
if ( this.nodes[i].getParent().getElementType() === 'listItem' ) {
if( stack.length > 0 ) {
stacks.push ( stack );
stack = [];
}
} else {
if( stack.length > 0 ) {
if ( this.nodes[i].getParent() === stack[stack.length - 1].getParent() ) {
stack.push( this.nodes[i] );
} else {
stacks.push ( stack );
stack = [this.nodes[i]];
}
} else {
stack.push( this.nodes[i] );
}
}
}
*/
if( stack.length > 0 ) {
stacks.push ( stack );
}
//
// Step 2
//
var insertAt,
removeLength,
tx;
for( i = 0; i < stacks.length; i++ ) {
removeLength = 0;
insertAt = this.toolbar.surfaceView.documentView.model.getOffsetFromNode(
stacks[i][0], false
);
data = [ { 'type': 'list' } ];
for( j = 0; j < stacks[i].length; j++ ) {
removeLength += stacks[i][j].getElementLength();
data = data
.concat( [ { 'type': 'listItem', 'attributes' : { 'styles': [ this.name ] } } ] )
.concat( stacks[i][j].getElementData() )
.concat( [ { 'type': '/listItem' } ] );
}
data = data.concat( [ { 'type': '/list' } ] );
tx = this.toolbar.surfaceView.model.getDocument().prepareRemoval(
new es.Range( insertAt, insertAt+removeLength)
);
this.toolbar.surfaceView.model.transact( tx );
tx = this.toolbar.surfaceView.model.getDocument().prepareInsertion(
insertAt,
data
);
this.toolbar.surfaceView.model.transact( tx );
}
};
es.ListButtonTool.prototype.updateState = function( annotations, nodes ) {