Index: trunk/extensions/VisualEditor/modules/es/tools/es.IndentationButtonTool.js |
— | — | @@ -16,10 +16,70 @@ |
17 | 17 | |
18 | 18 | es.IndentationButtonTool.prototype.onClick = function() { |
19 | 19 | if ( !this.$.hasClass( 'es-toolbarButtonTool-disabled' ) ) { |
20 | | - alert( 'This functionality is not yet supported.' ); |
| 20 | + var listItems = [], |
| 21 | + listItem, |
| 22 | + i; |
| 23 | + for ( i = 0; i < this.nodes.length; i++ ) { |
| 24 | + listItem = this.nodes[i].getParent(); |
| 25 | + if ( listItems.length > 0 ) { |
| 26 | + if (listItem != listItems[listItems.length - 1]) { |
| 27 | + listItems.push( listItem ); |
| 28 | + } |
| 29 | + } else { |
| 30 | + listItems.push( listItem ); |
| 31 | + } |
| 32 | + } |
| 33 | + if ( this.name === 'indent' ) { |
| 34 | + this.indent( listItems ); |
| 35 | + } else if ( this.name === 'outdent' ) { |
| 36 | + this.outdent( listItems ); |
| 37 | + } |
21 | 38 | } |
22 | 39 | }; |
23 | 40 | |
| 41 | +es.IndentationButtonTool.prototype.indent = function( listItems ) { |
| 42 | + var surface = this.toolbar.surfaceView, |
| 43 | + styles, |
| 44 | + i; |
| 45 | + |
| 46 | + for ( i = 0; i < listItems.length; i++ ) { |
| 47 | + styles = listItems[i].getElementAttribute( 'styles' ); |
| 48 | + if ( styles.length < 6 ) { |
| 49 | + styles.push( styles[styles.length - 1] ); |
| 50 | + tx = surface.model.getDocument().prepareElementAttributeChange( |
| 51 | + surface.documentView.model.getOffsetFromNode( listItems[i], false ), |
| 52 | + 'set', |
| 53 | + 'styles', |
| 54 | + styles |
| 55 | + ); |
| 56 | + surface.model.transact( tx ); |
| 57 | + } |
| 58 | + } |
| 59 | + surface.emitCursor(); |
| 60 | +}; |
| 61 | + |
| 62 | +es.IndentationButtonTool.prototype.outdent = function( listItems ) { |
| 63 | + var surface = this.toolbar.surfaceView, |
| 64 | + styles, |
| 65 | + i; |
| 66 | + |
| 67 | + for ( i = 0; i < listItems.length; i++ ) { |
| 68 | + styles = listItems[i].getElementAttribute( 'styles' ); |
| 69 | + console.log(styles); |
| 70 | + if ( styles.length > 1 ) { |
| 71 | + styles.splice( styles.length - 1, 1); |
| 72 | + tx = surface.model.getDocument().prepareElementAttributeChange( |
| 73 | + surface.documentView.model.getOffsetFromNode( listItems[i], false ), |
| 74 | + 'set', |
| 75 | + 'styles', |
| 76 | + styles |
| 77 | + ); |
| 78 | + surface.model.transact( tx ); |
| 79 | + } |
| 80 | + } |
| 81 | + surface.emitCursor(); |
| 82 | +}; |
| 83 | + |
24 | 84 | es.IndentationButtonTool.prototype.updateState = function( annotations, nodes ) { |
25 | 85 | function areListItems( nodes ) { |
26 | 86 | for( var i = 0; i < nodes.length; i++ ) { |
— | — | @@ -30,7 +90,8 @@ |
31 | 91 | return true; |
32 | 92 | } |
33 | 93 | |
34 | | - if ( areListItems( nodes ) ) { |
| 94 | + this.nodes = nodes; |
| 95 | + if ( areListItems( this.nodes ) ) { |
35 | 96 | this.$.removeClass( 'es-toolbarButtonTool-disabled' ); |
36 | 97 | } else { |
37 | 98 | this.$.addClass( 'es-toolbarButtonTool-disabled' ); |