Implemented indent and outdent functionality.

This commit is contained in:
Inez Korczynski 2011-12-08 23:45:07 +00:00
parent 47e76f21d1
commit 22c461a55b

View file

@ -16,8 +16,68 @@
es.IndentationButtonTool.prototype.onClick = function() { es.IndentationButtonTool.prototype.onClick = function() {
if ( !this.$.hasClass( 'es-toolbarButtonTool-disabled' ) ) { if ( !this.$.hasClass( 'es-toolbarButtonTool-disabled' ) ) {
alert( 'This functionality is not yet supported.' ); var listItems = [],
listItem,
i;
for ( i = 0; i < this.nodes.length; i++ ) {
listItem = this.nodes[i].getParent();
if ( listItems.length > 0 ) {
if (listItem != listItems[listItems.length - 1]) {
listItems.push( listItem );
} }
} else {
listItems.push( listItem );
}
}
if ( this.name === 'indent' ) {
this.indent( listItems );
} else if ( this.name === 'outdent' ) {
this.outdent( listItems );
}
}
};
es.IndentationButtonTool.prototype.indent = function( listItems ) {
var surface = this.toolbar.surfaceView,
styles,
i;
for ( i = 0; i < listItems.length; i++ ) {
styles = listItems[i].getElementAttribute( 'styles' );
if ( styles.length < 6 ) {
styles.push( styles[styles.length - 1] );
tx = surface.model.getDocument().prepareElementAttributeChange(
surface.documentView.model.getOffsetFromNode( listItems[i], false ),
'set',
'styles',
styles
);
surface.model.transact( tx );
}
}
surface.emitCursor();
};
es.IndentationButtonTool.prototype.outdent = function( listItems ) {
var surface = this.toolbar.surfaceView,
styles,
i;
for ( i = 0; i < listItems.length; i++ ) {
styles = listItems[i].getElementAttribute( 'styles' );
console.log(styles);
if ( styles.length > 1 ) {
styles.splice( styles.length - 1, 1);
tx = surface.model.getDocument().prepareElementAttributeChange(
surface.documentView.model.getOffsetFromNode( listItems[i], false ),
'set',
'styles',
styles
);
surface.model.transact( tx );
}
}
surface.emitCursor();
}; };
es.IndentationButtonTool.prototype.updateState = function( annotations, nodes ) { es.IndentationButtonTool.prototype.updateState = function( annotations, nodes ) {
@ -30,7 +90,8 @@ es.IndentationButtonTool.prototype.updateState = function( annotations, nodes )
return true; return true;
} }
if ( areListItems( nodes ) ) { this.nodes = nodes;
if ( areListItems( this.nodes ) ) {
this.$.removeClass( 'es-toolbarButtonTool-disabled' ); this.$.removeClass( 'es-toolbarButtonTool-disabled' );
} else { } else {
this.$.addClass( 'es-toolbarButtonTool-disabled' ); this.$.addClass( 'es-toolbarButtonTool-disabled' );