r104811 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104810‎ | r104811 | r104812 >
Date:00:37, 1 December 2011
Author:inez
Status:deferred
Tags:
Comment:
Seperate ClearButtonTool from AnnotationButtonTool
Modified paths:
  • /trunk/extensions/VisualEditor/VisualEditor.php (modified) (history)
  • /trunk/extensions/VisualEditor/demo/index.html (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.ClearButtonTool.js (added) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/VisualEditor.php
@@ -102,7 +102,8 @@
103103 'es/views/es.ToolbarView.js',
104104 'es/tools/es.Tool.js',
105105 'es/tools/es.ButtonTool.js',
106 - 'es/tools/es.AnnotationButtonTool.js'
 106+ 'es/tools/es.AnnotationButtonTool.js',
 107+ 'es/tools/es.ClearButtonTool.js'
107108 ),
108109 'styles' => array(
109110 'es/styles/es.SurfaceView.css',
Index: trunk/extensions/VisualEditor/demo/index.html
@@ -135,6 +135,7 @@
136136 <script src="../modules/es/tools/es.Tool.js"></script>
137137 <script src="../modules/es/tools/es.ButtonTool.js"></script>
138138 <script src="../modules/es/tools/es.AnnotationButtonTool.js"></script>
 139+ <script src="../modules/es/tools/es.ClearButtonTool.js"></script>
139140
140141 <!-- Demo -->
141142 <script src="../modules/sandbox/sandbox.js"></script>
Index: trunk/extensions/VisualEditor/modules/es/tools/es.ClearButtonTool.js
@@ -0,0 +1,29 @@
 2+es.ClearButtonTool = function( toolbar, name ) {
 3+ es.ButtonTool.call( this, toolbar, name );
 4+ this.$.addClass( 'es-toolbarButtonTool-disabled' );
 5+};
 6+
 7+es.ClearButtonTool.prototype.onClick = function() {
 8+ var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
 9+ this.toolbar.surfaceView.currentSelection,
 10+ 'clear',
 11+ /.*/
 12+ );
 13+ this.toolbar.surfaceView.model.transact( tx );
 14+ this.toolbar.surfaceView.clearInsertionAnnotations();
 15+};
 16+
 17+es.ClearButtonTool.prototype.updateState = function( annotations ) {
 18+ if ( annotations.length === 0 ) {
 19+ this.$.addClass( 'es-toolbarButtonTool-disabled' );
 20+ } else {
 21+ this.$.removeClass( 'es-toolbarButtonTool-disabled' );
 22+ }
 23+};
 24+
 25+es.Tool.tools.clear = {
 26+ constructor: es.ClearButtonTool,
 27+ name: 'clear'
 28+};
 29+
 30+es.extendClass( es.ClearButtonTool, es.ButtonTool );
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js
@@ -4,12 +4,7 @@
55 };
66
77 es.AnnotationButtonTool.prototype.onClick = function() {
8 - var method;
9 - if ( this.name === 'clear') {
10 - method = 'clear';
11 - } else {
12 - method = this.$.hasClass( 'es-toolbarButtonTool-down' ) ? 'clear' : 'set';
13 - }
 8+ var method = this.$.hasClass( 'es-toolbarButtonTool-down' ) ? 'clear' : 'set';
149
1510 var tx = this.toolbar.surfaceView.model.getDocument().prepareContentAnnotation(
1611 this.toolbar.surfaceView.currentSelection,
@@ -17,8 +12,19 @@
1813 this.data
1914 );
2015 this.toolbar.surfaceView.model.transact( tx );
 16+ return false;
2117 };
2218
 19+es.AnnotationButtonTool.prototype.updateState = function( annotations ) {
 20+ for ( var i = 0; i < annotations.length; i++ ) {
 21+ if ( annotations[i].type === this.data.type ) {
 22+ this.$.addClass( 'es-toolbarButtonTool-down' );
 23+ return;
 24+ }
 25+ }
 26+ this.$.removeClass( 'es-toolbarButtonTool-down' );
 27+};
 28+
2329 es.Tool.tools.bold = {
2430 constructor: es.AnnotationButtonTool,
2531 name: 'bold',
@@ -31,10 +37,5 @@
3238 data: { 'type': 'textStyle/italic' }
3339 };
3440
35 -es.Tool.tools.clear = {
36 - constructor: es.AnnotationButtonTool,
37 - name: 'clear',
38 - data: /.*/
39 -};
4041
4142 es.extendClass( es.AnnotationButtonTool, es.ButtonTool );
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -142,6 +142,7 @@
143143
144144 es.SurfaceView.prototype.addInsertionAnnotation = function( annotation ) {
145145 this.insertionAnnotations.push( annotation );
 146+ this.emitUpdate();
146147 };
147148
148149 es.SurfaceView.prototype.loadInsertionAnnotations = function( annotation ) {
@@ -161,10 +162,12 @@
162163 if ( index !== -1 ) {
163164 this.insertionAnnotations.splice( index, 1 );
164165 }
 166+ this.emitUpdate();
165167 };
166168
167169 es.SurfaceView.prototype.clearInsertionAnnotations = function() {
168170 this.insertionAnnotations = [];
 171+ this.emitUpdate();
169172 };
170173
171174 es.SurfaceView.prototype.getModel = function() {
Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js
@@ -58,10 +58,14 @@
5959 annotations;
6060
6161 if( selection.from === selection.to ) {
62 - annotations = this.surfaceView.documentView.model.getAnnotationsFromOffset( selection.to );
 62+ annotations = this.surfaceView.getInsertionAnnotations();
6363 } else {
6464 annotations = this.surfaceView.documentView.model.getAnnotationsFromRange( selection );
6565 }
 66+
 67+ for( var i = 0; i < this.tools.length; i++ ) {
 68+ this.tools[i].updateState( annotations );
 69+ }
6670 };
6771
6872 es.ToolbarView.prototype.setup = function() {

Status & tagging log