mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
Prototype of code that wraps nodes as listItems (inside a list)
This commit is contained in:
parent
1b89cbb79d
commit
959963cf6e
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in a new issue