r104918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104917‎ | r104918 | r104919 >
Date:23:24, 1 December 2011
Author:inez
Status:resolved (Comments)
Tags:
Comment:
Added FormatDropdownTool, so now you can switch leaf nodes from paragraphs to pres for instance
Modified paths:
  • /trunk/extensions/VisualEditor/VisualEditor.php (modified) (history)
  • /trunk/extensions/VisualEditor/demo/index.html (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.DropdownTool.js (added) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js (added) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/VisualEditor.php
@@ -104,7 +104,10 @@
105105 'es/tools/es.ButtonTool.js',
106106 'es/tools/es.AnnotationButtonTool.js',
107107 'es/tools/es.ClearButtonTool.js',
108 - 'es/tools/es.HistoryButtonTool.js'
 108+ 'es/tools/es.HistoryButtonTool.js',
 109+ 'es/tools/es.DropdownTool.js',
 110+ 'es/tools/es.FormatDropdownTool.js'
 111+
109112 ),
110113 'styles' => array(
111114 'es/styles/es.SurfaceView.css',
Index: trunk/extensions/VisualEditor/demo/index.html
@@ -137,6 +137,8 @@
138138 <script src="../modules/es/tools/es.AnnotationButtonTool.js"></script>
139139 <script src="../modules/es/tools/es.ClearButtonTool.js"></script>
140140 <script src="../modules/es/tools/es.HistoryButtonTool.js"></script>
 141+ <script src="../modules/es/tools/es.DropdownTool.js"></script>
 142+ <script src="../modules/es/tools/es.FormatDropdownTool.js"></script>
141143
142144 <!-- Demo -->
143145 <script src="../modules/sandbox/sandbox.js"></script>
Index: trunk/extensions/VisualEditor/modules/es/tools/es.FormatDropdownTool.js
@@ -0,0 +1,45 @@
 2+es.FormatDropdownTool = function( toolbar, name ) {
 3+ es.DropdownTool.call( this, toolbar, name );
 4+
 5+ this.formats = [
 6+ { 'name': 'Paragraph', 'type' : 'paragraph' },
 7+ { 'name': 'Heading Level 1', 'type' : 'heading', 'attributes': { 'level': 1 } },
 8+ { 'name': 'Heading Level 2', 'type' : 'heading', 'attributes': { 'level': 2 } },
 9+ { 'name': 'Heading Level 3', 'type' : 'heading', 'attributes': { 'level': 3 } },
 10+ { 'name': 'Heading Level 4', 'type' : 'heading', 'attributes': { 'level': 4 } },
 11+ { 'name': 'Heading Level 5', 'type' : 'heading', 'attributes': { 'level': 5 } },
 12+ { 'name': 'Heading Level 6', 'type' : 'heading', 'attributes': { 'level': 6 } },
 13+ { 'name': 'Preformatted', 'type' : 'pre' }
 14+ ];
 15+
 16+ this.$select.append( '<option>' );
 17+
 18+ for ( var i = 0; i < this.formats.length; i++ ) {
 19+ $( '<option>' ).val( i ).html( this.formats[i].name ).appendTo( this.$select );
 20+ }
 21+};
 22+
 23+es.FormatDropdownTool.prototype.onChange = function() {
 24+ var index = this.$select.val();
 25+ if ( index in this.formats ) {
 26+ var txs = this.toolbar.surfaceView.model.getDocument().prepareLeafConversion(
 27+ this.toolbar.surfaceView.currentSelection,
 28+ this.formats[index].type,
 29+ this.formats[index].attributes
 30+ )
 31+ for ( var i = 0; i < txs.length; i++ ) {
 32+ this.toolbar.surfaceView.model.transact( txs[i] );
 33+ }
 34+ }
 35+};
 36+
 37+es.FormatDropdownTool.prototype.updateState = function( annotations ) {
 38+ // ...
 39+};
 40+
 41+es.Tool.tools.format = {
 42+ constructor: es.FormatDropdownTool,
 43+ name: 'format'
 44+};
 45+
 46+es.extendClass( es.FormatDropdownTool, es.DropdownTool );
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/es/tools/es.DropdownTool.js
@@ -0,0 +1,28 @@
 2+es.DropdownTool = function( toolbar, name ) {
 3+ es.Tool.call( this, toolbar, name );
 4+
 5+ // for es.extendClass
 6+ if ( !name ) {
 7+ return;
 8+ }
 9+
 10+ this.$.addClass( 'es-toolbarDropdownTool' ).addClass( 'es-toolbarDropdownTool-' + name );
 11+
 12+ this.$select = $( '<select>' );
 13+ this.$.append( this.$select );
 14+
 15+ var _this = this;
 16+
 17+ this.$.bind( {
 18+ 'change': function( e ) {
 19+ _this.onChange( e );
 20+ }
 21+ } );
 22+
 23+};
 24+
 25+es.DropdownTool.prototype.onChange = function() {
 26+ throw 'DropdownTool.onChange not implemented in this subclass:' + this.constructor;
 27+};
 28+
 29+es.extendClass( es.DropdownTool, es.Tool );
\ No newline at end of file
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js
@@ -1194,8 +1194,6 @@
11951195 }
11961196 }, fromNode );
11971197
1198 - attributes = attributes || {}; // or maybe should be null instead of empty collection
1199 -
12001198 // TODO: skip nodes which have the same type and attributes as the target
12011199
12021200 for ( var i = 0; i < nodes.length; i++ ) {
Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js
@@ -48,7 +48,7 @@
4949 } );
5050
5151 this.config = config || [
52 - { 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'link', 'clear' ] },
 52+ { 'name': 'textStyle', 'items' : [ 'bold', 'italic', 'link', 'clear', 'format' ] },
5353 { 'name': 'history', 'items' : [ 'undo', 'redo' ] }
5454 ];
5555 this.setup();

Comments

#Comment by Johnduhart (talk | contribs)   02:58, 4 December 2011

Status & tagging log