r105615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105614‎ | r105615 | r105616 >
Date:23:45, 8 December 2011
Author:inez
Status:deferred
Tags:
Comment:
Implemented indent and outdent functionality.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/tools/es.IndentationButtonTool.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/tools/es.IndentationButtonTool.js
@@ -16,10 +16,70 @@
1717
1818 es.IndentationButtonTool.prototype.onClick = function() {
1919 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+ }
2138 }
2239 };
2340
 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+
2484 es.IndentationButtonTool.prototype.updateState = function( annotations, nodes ) {
2585 function areListItems( nodes ) {
2686 for( var i = 0; i < nodes.length; i++ ) {
@@ -30,7 +90,8 @@
3191 return true;
3292 }
3393
34 - if ( areListItems( nodes ) ) {
 94+ this.nodes = nodes;
 95+ if ( areListItems( this.nodes ) ) {
3596 this.$.removeClass( 'es-toolbarButtonTool-disabled' );
3697 } else {
3798 this.$.addClass( 'es-toolbarButtonTool-disabled' );

Status & tagging log